Problem with RegQueryValueEx
Posted on 1997-06-08
I'm having a problem with the RegQueryValueEx function - it's returning error code 87 (Invalid Parameter), and it's due to the 5th parameter. I know this, because it returns ERROR_SUCCESS if I make this parameter NULL.
if (::RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\a\\b",
0, KEY_ALL_ACCESS, &phk) != ERROR_SUCCESS)
long lRet = ::RegQueryValueEx(phk, (LPTSTR) "Password", NULL, NULL,
(LPBYTE) sPwdReg, &dwcbData);
msg.Format("lRet = %ld", lRet);
The "Password" registry value is a string, by the way. Does anybody know what I'm doing wrong here? I've looked through all the examples in the Visual C++ documentation, and found no clues. I've seen this argument typecast to LPCTSTR or LPTSTR, but this won't compile. I've also tried using a char* argument, and allocating memory to it with malloc, but this shouldn't make a difference, and it didn't.
A possibly related problem is that in my Project Settings/C/C++ Tab/Preprocessor Category, I have undefined WIN32_EXTRA_LEAN in order for the compiler to include "winreg.h", which is needed for the registry API. However, if I uncomment the #ifdef WIN32_EXTRA_LEAN directive, I find that WIN32_EXTRA_LEAN *is* defined. I cannot figure this out - I'm working around it by just explicitly including "winreg.h".