-
June 17th, 2010, 12:58 AM
#1
RegQueryValueEx
Okay, for some reason when I call RegQueryValueEx, my buffer pads every other byte with a space. So the output is something like "1 0 0 1 u s w e s t" and so on... I've tried a few different methods but can't seem to nail this one...
On top of that, when I cout the data, it only prints the first byte...
Code:
int main ()
{
HKEY hKey;
DWORD cType;
char lpData[1024] = {0};
DWORD buffersize = sizeof(lpData);
if(RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Blizzard Entertainment\\Warcraft III"),NULL,KEY_READ,&hKey) == ERROR_SUCCESS)
{
cout << "Opened successfully";
}else{
cout << "Failed to open reg key: " << GetLastError() << "\n";
}
RegQueryValueEx(hKey,TEXT("Battle.net Gateways"),NULL,&cType,(LPBYTE) lpData,&buffersize);
cout << "Registry Key Open: mem key location=" << hKey << "\n\n";
cout << "Data: " << lpData;
RegCloseKey (hKey);
system("Pause");
}
-
June 17th, 2010, 01:29 AM
#2
Re: RegQueryValueEx
Originally Posted by Feered
Okay, for some reason when I call RegQueryValueEx, my buffer pads every other byte with a space. So the output is something like "1 0 0 1 u s w e s t" and so on...
Is it a UNICODE string?
Victor Nijegorodov
-
June 17th, 2010, 07:05 AM
#3
Re: RegQueryValueEx
I fixed the space padding by going to the compilers settings and turning UNICODE to Not Set. However, now when I cout the buffer, it's only printing the first word.
--edit
I'm sorry, just realized it's not a space padding. It's a null padding after each word.
Last edited by Feered; June 17th, 2010 at 07:26 AM.
-
June 23rd, 2010, 06:52 AM
#4
Re: RegQueryValueEx
Your code contains few mistakes.
Take a look at next example and guess which are they.
Code:
#include <windows.h>
#include <tchar.h>
#include <iostream>
#ifdef UNICODE
#define t_cout wcout
#else
#define t_cout cout
#endif
int _tmain()
{
HKEY hKey = NULL;
DWORD cType = REG_NONE;
TCHAR lpData[1024] = {0};
DWORD size = sizeof(lpData);
LONG lRet = RegOpenKeyEx(HKEY_CURRENT_USER,
_T("Software\\Blizzard Entertainment\\Warcraft III"),
NULL, KEY_QUERY_VALUE, &hKey);
if(ERROR_SUCCESS != lRet)
{
std::t_cout << _T("RegOpenKeyEx failed. Error: ") << lRet << std::endl;;
return lRet;
}
lRet = RegQueryValueEx(hKey, _T("Battle.net Gateways"), NULL, &cType, (LPBYTE)lpData, &size);
RegCloseKey(hKey);
if(ERROR_SUCCESS != lRet)
{
std::t_cout << _T("RegQueryValueEx failed. Error: ") << lRet << std::endl;;
return lRet;
}
if(REG_SZ != cType)
{
std::t_cout << _T("Value has not expected type REG_SZ") << std::endl;
return E_FAIL;
}
std::t_cout << "Data: " << lpData << std::endl;
system("Pause");
return ERROR_SUCCESS;
}
-
June 26th, 2010, 04:06 PM
#5
Re: RegQueryValueEx
Hello, ovidiucucu
I'd like to get the Type of the data, (REG_SZ,REG_DWORD etc),
Thank you
-
June 27th, 2010, 04:18 AM
#6
Re: RegQueryValueEx
RegQueryValueEx has a parameter:
lpType
[out] Pointer to a variable that receives a code indicating the type of data stored in the specified value. For a list of the possible type codes, see Registry Value Types. The lpType parameter can be NULL if the type code is not required.
Victor Nijegorodov
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
|