Registry functions, not there?
This is a discussion on Registry functions, not there? within the C++ Programming forums, part of the General Programming Boards category; I got the "new" dev-cpp 4.9.9.1 and when I got to compile this function...
Code:
RegGetValue(
HKEY_LOCAL_MACHINE,
"HARDWARE\DESCRIPTION\System\CentralProcessor
",
"ProcessorNameString",
NULL,
...
-
Registry functions, not there?
I got the "new" dev-cpp 4.9.9.1 and when I got to compile this function...
Code:
RegGetValue(
HKEY_LOCAL_MACHINE,
"HARDWARE\DESCRIPTION\System\CentralProcessor\0",
"ProcessorNameString",
NULL,
NULL,
var,
sizeof(var)
);
It says that thsi function doesn't exist.
here are my header files...
Code:
#include <iostream.h>
#include <Windows.h>
#include <Winreg.h>
Winreg, I know shouldn't be there, but I had to try it, and it still didn't work.
I don't ge this!
-
C Programmer
Hello,
I'm not familiar with RegGetValue(). Though, I am familiar with RegOpenKeyEx, RegQueryValueEx, RegCloseKey, and so forth.
I did a Google search on RegGetValue, and this is what turned up: MSDN. At the bottom it says: Requires Windows Server 2003 SP1. This may answer your question.
- Stack Overflow
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
-
ok so now... I got anouther problem....
Code:
#include <iostream.h>
#include <Windows.h>
int main()
{
BYTE* var;
RegQueryValueEx(
HKEY_LOCAL_MACHINE,
"HARDWARE\DESCRIPTION\System\CentralProcessor\0\ProcessorNameString",
NULL,
NULL,
var,
sizeof(var)
);
cout<<var;
} it says invalad converstion from unsigned in to DWORD.
I must have forgoten alot about c++, but what is wrong?
-
C Programmer
Hello,
Simply, parameter 5 is the address to the data of your buffer and parameter 6 is the address of data buffer size.
I don't make a habit of posting code, though I think it may be beneficial. I apologize for using printf() and other C-style functions in the C++ board. So, here is an example I wrote on how to query a registry key. It may help gear you in the right direction: Code:
#include <windows.h>
#include <stdio.h>
int checkKey(HKEY tree, const char *folder, char *key) {
long lRet;
HKEY hKey;
char temp[150];
DWORD dwBufLen;
// Open location
lRet = RegOpenKeyEx( tree, folder, 0, KEY_QUERY_VALUE, &hKey );
if (lRet != ERROR_SUCCESS)
return 0;
// Get key
dwBufLen = sizeof(temp);
lRet = RegQueryValueEx( hKey, key, NULL, NULL, (BYTE*)&temp, &dwBufLen );
if (lRet != ERROR_SUCCESS)
return 0;
printf("Key value: %s\n", temp);
// Close key
lRet = RegCloseKey( hKey );
if (lRet != ERROR_SUCCESS)
return 0;
// Got this far, then key exists
return 1;
}
int main() {
printf("Checking for key: HKEY_CURRENT_USER -> Control Panel -> Desktop -> Wallpaper\n");
if (checkKey(HKEY_CURRENT_USER, "Control Panel\\Desktop", "Wallpaper"))
printf("Key Exists.\n");
else
printf("Key Does Not Exist.\n");
return 0;
} RegQueryValueEx()
The RegQueryValueEx function retrieves the type and data for a specified value name associated with an open registry key. Code:
LONG RegQueryValueEx(
HKEY hKey, // handle of key to query
LPTSTR lpValueName, // address of name of value to query
LPDWORD lpReserved, // reserved
LPDWORD lpType, // address of buffer for value type
LPBYTE lpData, // address of data buffer
LPDWORD lpcbData // address of data buffer size
); Or learn more about it here.
There are other functions, though simply doing an MSDN/Google search may pull up further documentation on such functions within the windows header file.
If you have any further questions please feel free to ask.
- Stack Overflow
Last edited by Stack Overflow; 12-29-2004 at 12:30 PM.
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
-
Yes, my avatar is stolen
As a shortcut, you can use SHGetValue. Whether you use SHGetValue or RegQueryValueEx, you must make sure that a retrieved string is nul terminated before trying to use it. You should be aware that, unless documented, keys in the registry may change from one platform to another (or even when a hotfix is released).
Code:
#include <windows.h>
#include <shlwapi.h>
#include <stdio.h>
#pragma comment(lib, "shlwapi.lib")
int main(void)
{
TCHAR szName[500];
DWORD dwType;
DWORD cbSize = sizeof(szName) - sizeof(TCHAR); /* Leave room for nul terminator. */
if (SHGetValue(HKEY_LOCAL_MACHINE,
TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"),
TEXT("ProcessorNameString"),
&dwType,
szName,
&cbSize) == ERROR_SUCCESS)
{
/* IMPORTANT: Make sure string is nul terminated. */
szName[cbSize / sizeof(TCHAR)] = TEXT('\0');
printf("Name is %s.\n", szName);
}
else
{
printf("Failed to retrieve value.\n");
}
getchar();
return 0;
}
Last edited by anonytmouse; 12-29-2004 at 12:49 PM.
-
Guest
>> BYTE* var;
that doesn't point to anything.
>> sizeof(var)
the parameter should be a pointer to the size of the buffer - on return it will contain the number of bytes copied.
>> I must have forgoten alot about c++, but what is wrong?
ever heard of documentation? it's a nice thing to have when you can't remember function parameters.
here's borland's WinAPI help file: download.
Code:
int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
<1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
(l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
)putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
Popular pages Recent additions
Similar Threads
-
By edd1986 in forum C Programming
Replies: 3
Last Post: 03-29-2005, 02:35 AM
-
By GuardianDevil in forum Windows Programming
Replies: 1
Last Post: 05-01-2004, 01:41 PM
-
By geek@02 in forum Windows Programming
Replies: 6
Last Post: 04-19-2004, 05:39 AM
-
By hpy_gilmore8 in forum C++ Programming
Replies: 3
Last Post: 01-14-2004, 05:46 PM
-
By linkies in forum C Programming
Replies: 1
Last Post: 08-21-2002, 07:53 AM