alexo
asked on
RegQueryValue() weirdness
Take a look at the following code:
char buffer[MAX_PATH];
LONG size = MAX_PATH;
RegQueryValue(HKEY_CLASSES _ROOT,
"QuickView\\shell\\open\\c ommand",
buffer, &size);
The call to RegQueryValue() returns an error value of 13.
However, GetLastError() indicates there was no error, and the variables buffer and size get set to the correct values.
Where does this error 13 come from???
(I use RegQueryValue() and not RegQueryValueEx() because I want the default value associated with the key, and it is also simpler.)
char buffer[MAX_PATH];
LONG size = MAX_PATH;
RegQueryValue(HKEY_CLASSES
"QuickView\\shell\\open\\c
buffer, &size);
The call to RegQueryValue() returns an error value of 13.
However, GetLastError() indicates there was no error, and the variables buffer and size get set to the correct values.
Where does this error 13 come from???
(I use RegQueryValue() and not RegQueryValueEx() because I want the default value associated with the key, and it is also simpler.)
What type of data is it that you are trying to read (REG_SZ, REG_DWORD and so on) ?
ASKER
Why should I?
The documentation says: RegQueryValue(key, subkey, ...)
The key I use is HKEY_CLASSES_ROOT, which is open by definition.
The documentation says: RegQueryValue(key, subkey, ...)
The key I use is HKEY_CLASSES_ROOT, which is open by definition.
ASKER
I try to read the default value.
Regedit says it is a string.
Regedit says it is a string.
Thui is correct, you MUST open the key first. The document also fooled me when I tried registry at the first time, I think it actually means that if you want to open a key which is the immediate child of HKEY_***, you can do it directly.
Just add this call and you will see the difference.
Just add this call and you will see the difference.
ASKER
So how comes I still get the correct answer?
And GetLastError() returns zero - meaning no error.
And GetLastError() returns zero - meaning no error.
ASKER
Time to reopen the question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is RegQueryValue() a 16-bit API? Where does it says so.
Why GetLastError() does not apply to 16-bit APIs?
Why GetLastError() does not apply to 16-bit APIs?
RegQueryValue() is indeed a 16-bit API. In face, MSDN strongly suggest that 32-bit application to use the equivalent 32-bit RegQueryValueEx() API. Even MSVC's help book has that also. The same document also mentioned that GetLastError() is only maintained on a per-thread basis. And as you may know, 16-bit has its own one-and-only thread in the system.
ASKER
OK. That seems to wrap it up.
HKEY hDestKey;
RegOpenKey(HKEY_CLASS_ROOT
RegQueryValue(.....same as what you did.....);