strange characters with RegQueryValueEx

Hello guys.

I'm creating a NPAPI dll file and I need to get some information from the registry, but when I use RegQueryValueEx, I get some strange characters.

For instance, my computer model is "N310", but I get "Nfb1fb1" or "N$(".

I'm pretty sure that it's a charset issue, but I'm new with C++ and I need some help.

I'm using Visual Studio 2010 and my project is using the UNICODE charset.

Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
char lszValue[255];
std::string cadena;
HKEY hKey;
LONG returnStatus;
DWORD dwType=REG_SZ;
DWORD dwSize=255;

returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\BIOS", NULL, KEY_READ, &hKey);
if (returnStatus == ERROR_SUCCESS) {
    returnStatus = RegQueryValueEx(hKey, L"SystemProductName", NULL, &dwType,(LPBYTE)&lszValue, &dwSize);
    lszValue[dwSize] = 0;
    cadena.assign(lszValue, dwSize);

    return cadena;
}


Thank you very much and thanks for advance.
This:
1
2
3
char lszValue[255];
std::string cadena;
DWORD dwSize=255;
should be:
1
2
3
wchar_t lszValue[255];
std::wstring cadena;
DWORD dwSize=sizeof(lszValue);

Also, you should be checking dwType to see what type you're getting back.
Last edited on
Topic archived. No new replies allowed.