I'm not sure if I'm right in assuming you just want to retrieve a value, but if you just want to get the value of an existing registry key, which you know the name of then:
Code:
HKEY hKey;
char * szRegKey = "Software\\note";
char szValue[100];
DWORD dwType, dwSize = sizeof(szValue);
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_QUERY_VALUE, &hKey);
if (lResult == ERROR_SUCCESS) {
lResult = RegQueryValueEx(hKey, lpCmdLine, 0, &dwType, (LPBYTE) szValue, &dwDataSize );
if (lResult == ERROR_SUCCESS && dwType == REG_SZ) {
szValue[99] = '\0';
// Use the value
}
RegCloseKey(hKey);
}
This will put the value of HKLM\Software\Note\lpCmdLine in szValue.
It should be noted that the value is not guaranteed to be null terminated. Personally, I would use four REG_DWORD values, left, right, etc.
I posted some code recently on this board that did everything(allocated memory, retrieved value, null terminated and error checking) with the simple functions:
Code:
HRESULT RegGetString(HKEY hKey, LPCTSTR szValueName, LPTSTR * lpszResult)
HRESULT RegGetDWord(HKEY hKey, LPCTSTR szValueName, DWORD * lpdwResult)
Do a search.
If you want to write values then here is some old code:
Code:
RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\note",0,NULL,
REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,NULL);
RegSetValueEx(hKey,"Value Name",0,REG_DWORD,(LPBYTE) &dwValue, sizeof(DWORD) );
EDIT: It should be noted that while you may develop with administrator priviliges, most people will not run your program with administrative priviliges. Therefore, they will not be able to write values under HKLM or even open HKLM with KEY_ALL_ACCESS. Unless the value is only written at installation or the program is a service, you should use HKLU.