reading registry returns empty

Hello,

Trying to get value of a registry key returns empty. It should be the problem of my code, but I didn't figure it out.

string myFunc(unsigned long pulHKEY_TYPE, int piHKEY_NAME, const string & postr, const string & postrKeyName)
{
DWORD vdwType = pulHKEY_TYPE;
char vch[255];
DWORD vdwDataSize = 255;
memset(vch, 0, 255);

HKEY vHKEY;
long vlRet;

switch(piHKEY_NAME){
case HKEY_L_MACHINE:
vlRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, string2wstring(postr).c_str(), 0, KEY_READ, &vHKEY);
break;
} // end switch

if(ERROR_SUCCESS == vlRet)
{
vlRet = RegQueryValueEx(vHKEY, string2wstring(postrKeyName).c_str(), NULL, &vdwType, (BYTE *)vch, &vdwDataSize);
if(ERROR_SUCCESS == vlRet)
{
cout << " >> Value: " << vch;
}
else
cout << " >> Query registry failed!";
} // end if-else

string ostr = string(vch);
RegCloseKey(vHKEY);
return ostr;
}
----------------

cout<< myFunc(REG_SZ, myObject.HKEY_L_MACHINE, "SOFTWARE\\Micorsoft\\MediaPlayer\\", "IEInstall");
Micorsoft? Looks like you are trying to work with a key that doesn't exist.

PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Including enough code that it will compile would also be a benefit. Headers and a fully formed main function.
string2wstring

Why? Just use wide strings.

The first thing I notice is that you are calling "RegOpenKeyEx()" and "RegQueryValueEx()"... which don't exist. You'll want to explicitly use either "RegOpenKeyExA()" or "RegOpenKeyExW()", I suggest the later variant for both but it's more important to stay consistent then to listen to me. It will make your troubleshooting SO MUCH EASIER, just trust me.

The next thing I notice is the conspicuous absence of our friend GetLastError(). You should be calling this so often that you get sick of seeing it. He holds the answer to your questions, I guarantee it.
Topic archived. No new replies allowed.