-
April 21st, 2010, 05:15 AM
#1
[RESOLVED] RegQueryValueEx problem
hi!
I experience a problem with RegQueryValueEx in Release version (in Debug version there is no problem).
What I am trying to do is to get the path of APPDATA folder of Windows (USER->Volatile Environment->APPDATA).
the code I wrote is this:
Code:
DWORD dwType;
DWORD dwSize;
WCHAR wstr[MAX_PATH];
nResult = RegQueryValueEx(hKey, L"APPDATA", 0, &dwType, (byte*)wstr, &dwSize);
if (nResult == ERROR_MORE_DATA)
{
wsprintf(wstr, L"dwSize:%d maxpath:%d", dwSize, MAX_PATH);
MessageBox(0, wstr, L"more data", 0);
}
if (ERROR_SUCCESS != nResult)
{
DisplayError(nResult);
return;
}
As you may guess, the problem is that it goes in ERROR_MORE_DATA section.
The messagebox displays "dwSize:64 maxpath:260" - so what's the problem?
and... I receive no string in wstr
can anybody give me an advice, please?
-
April 21st, 2010, 12:13 PM
#2
Re: RegQueryValueEx problem
can anybody give me an advice, please?
The one is: read documentation, always start with this.
lpcbData [in, out, optional]
A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpData.
Best regards,
Igor
-
April 21st, 2010, 12:23 PM
#3
Re: RegQueryValueEx problem
wow, that's awesome!
I have read from there for many times but I still could have not gotten the idea
Now I understand what the documentation said, thanks.
-
April 27th, 2010, 11:14 PM
#4
Re: [RESOLVED] RegQueryValueEx problem
Feoggou , u may try with BYTE array ,after that ,u can check ,because u cannot convert WCHAR to BYTE* ,there may size differ...
-
April 28th, 2010, 08:27 AM
#5
Re: [RESOLVED] RegQueryValueEx problem
Originally Posted by rajakumarrs
Feoggou , u may try with BYTE array ,after that ,u can check ,because u cannot convert WCHAR to BYTE* ,there may size differ...
I experienced no problem with that.
I used
Code:
DWORD dwSize = MAX_PATH * 2;
WCHAR wstr[MAX_PATH];
nResult = RegQueryValueEx(hKey, L"APPDATA", 0, &dwType, (byte*)wstr, &dwSize);
and it works.
a WCHAR has 2 bytes, so it should be ok to convert from WCHAR* to byte* (and it seems that it is).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|