Eugeny89
Eugeny89

Reputation: 3731

problems with RegQueryValueEx

take a lok at the following code

HKEY hKey = 0;
int code = RegOpenKey(HKEY_CURRENT_USER, subkey, &hKey); //code is ERROR_SUCCESS

char aBuf[255] = {0};
char bBuf[255] = {0};
DWORD dwType = REG_SZ;
DWORD dwBufSize = sizeof(bBuf);

int aCode = RegQueryValueEx(hKey, L"a", 0, &dwType, (BYTE*)aBuf, &dwBufSize);
int bCode = RegQueryValueEx(hKey, L"b", 0, &dwType, (BYTE*)bBuf, &dwBufSize);
//(*) here I have a breakpoint

At the breakpoint aBuf (as well as bBuf) is something like 'a' '\0' 'v' '\0' 'a' '\0' 'l' '\0' 'u' '\0' 'e' '\0'. What am I doing wrong?

Thank you in advance!

Upvotes: 0

Views: 291

Answers (2)

Raymond Chen
Raymond Chen

Reputation: 45172

Your code is compiled UNICODE (as evidenced by your use of L"a"), so the result will be a wchar_t array, not a char array.

Upvotes: 5

Reinderien
Reinderien

Reputation: 15263

It sounds like you have a UTF16 encoding problem. Decode the string as UTF16 and you should be OK.

Upvotes: 1

Related Questions