The Registry

if i write this to the registry with:

HKEY hKey;
char fullpath[]="c:\windows\";
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\\myproggie",
0,
KEY_ALL_ACCESS,
&hKey);
RegSetValueEx(hKey, name, 0, REG_SZ, (const BYTE*)fullpath, sizeof(fullpath) + 1);
RegCloseKey(hKey);

how do i read it back?
scooter1Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
bbousquetConnect With a Mentor Commented:
DWORD dwType;
char somepath[20]; //or some other size
DWORD dwSize;
RegQueryValueEx(hKey, name, 0, &dwType, somepath, &dwSize);

On success RegQueryValueEx will return ERROR_SUCCESS

I hope this helps.
0
 
scooter1Author Commented:
Why can't you give an example that will get what i wrote in my question, for a beginner i can't get what you wrote to work, i get :
error C2664: 'RegQueryValueA' : cannot convert parameter 4 from 'unsigned long *' to 'long *'
0
 
bbousquetCommented:
Well, considering your key value is a string I'd go with the following (to read the stuff you wrote in your program) - RegQueryValue would do just fine for that - no need for RegQueryValueEx:

(...)

LONG lSize = sizeof(fullpath);
if(RegQueryValue(hKey, name, fullpath, &lSize) != ERROR_SUCCESS) {
  // we have an error here!
}

(...)

[This is all from memory - but it should work fine]
0
All Courses

From novice to tech pro — start learning today.