How to determine using WINAPI registry means whether the registry key exists???
Printable View
How to determine using WINAPI registry means whether the registry key exists???
Do you want to create the key if it does not exist?
If so, then you could use RegCreateKeyEx. It will create the key if it does not exist, and it will open the key if it does exist. Then you could check the value of lpdwDisposition to see whether it created the key or opened it.
Here is an example of doing it using RegCreateKeyEx.
One way of doing it...Code:HKEY phkResult;
DWORD lpdwDisposition;
RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\My Programs\\My Program"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &phkResult, &lpdwDisposition);
if (lpdwDisposition == REG_CREATED_NEW_KEY) // key did not exist
{
// set default registry values for your program
}
// Read in your values
No, I want to query it's value, but the returned result is ERROR_FILE_NOT_FOUND.
Does this returned result mean that the key doesn't exist in this context???
Yes, you would receive that error as returned by RegOpenKeyEx if the key did not exist.
Is that what you were looking for, or are you having problems opening a key that you know exits (if so, posting the related code would help)?
Yes, thanx. I just wanted to be sure in the meaning of the return code.
But the function that I am using is RegQueryValueEx, but I think it doesn't matter in this case.