Compiler: MSVC++ | OS: Windows XP Pro.
How would I read-in a key or entry from the registry(what function, and please show an example)?
TIA, knave.
Compiler: MSVC++ | OS: Windows XP Pro.
How would I read-in a key or entry from the registry(what function, and please show an example)?
TIA, knave.
Tried working with this, but failed to get it to work. any help is appreciated.
Code:#include "stdio.h" #include "stdlib.h" #include "windows.h" #include "iostream.h" int main() { HKEY hKey; char *lpValName = " anything", *lpKey = "Software\\etc\\etc\\etc\\etc\\etc\\"; DWORD dwData,dwSize,dwType; if(RegOpenKeyEx(HKEY_CURRENT_USER,lpKey, NULL,KEY_READ,&hKey) == ERROR_SUCCESS) { dwSize = sizeof(DWORD); dwType = REG_SZ; // REG_SZ ONLY!!! if(RegQueryValueEx(hKey,lpValName,NULL,&dwType, (LPBYTE)&dwData ,&dwSize) == ERROR_SUCCESS) { printf(" Data from key: %s",dwData); } else printf("\n Could not read the registry key"); } else printf("\n Failed to locate the registry key"); RegCloseKey(hKey); return 0; }
Try RegCreateKeyEx instead of 'RegOpenKeyEx' as RegCreateKeyEx will create the key if it doesn't already exist or open the key if it does. Note that RegCreateKeyEx has different parameters.
There are a couple of simple syntax errors in your posted code but I assume these are just typos.
Hope that helps some. Good luck.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.