Skip to main content
gamedev.net
🔒 Locked

RegQueryValueEx problem

Started by decebal 0 replies 250+ views
Original Post
decebal
decebal
I''ve got this class that has these two functions:
  
OpenKey(HKEY Pred_Key,char *SubKey_Name,REGSAM Sam,HKEY &Key)
QueryValueEx(HKEY hKey,char *SubKey_Name,DWORD &Type,DWORD &dwBufferLen,char *buffer)
  
the first one should open a key and the other one should read a value from this key. The code for these functions:
  
LONG cRegistry::OpenKey(HKEY Pred_Key,char *SubKey_Name,REGSAM Sam,HKEY &Key)
{
m_Error=RegOpenKeyEx(Pred_Key,SubKey_Name,NULL,Sam,&Key);

return m_Error;
}
LONG cRegistry::QueryValueEx(HKEY hKey,char *SubKey_Name,DWORD &Type,DWORD &dwBufferLen,char *buffer)
{
    m_Error=RegQueryValueEx(hKey,SubKey_Name,NULL,&Type,(BYTE*)&buffer,&dwBufferLen);
	return m_Error;
}
  
and this is the way i call these functions:
  
HKEY Key;
char *buffer3;
DWORD Type=REG_SZ;
DWORD dwBufferLen;
cRegistry Registry;

Registry.OpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",KEY_ALL_ACCESS,Key);
Registry.QueryValueEx(Key,"kernel.dll",Type,dwBufferLen,buffer3);
  
This code compiles and I can run the program but queryvalueex returns 87 and doesn''t return the value of the key. The first function returns 0. Mankind must put an end to war before war puts an end to mankind. John F. Kennedy
Mankind must put an end to war before war puts an end to mankind. John F. Kennedy
Anthracks
Anthracks
You need to actually allocate a buffer, and give a value for how long it is (at least in your sample code, you don''t). In your example, you''re just giving it a pointer to some random spot in memory. Do something more like this:


  

HKEY Key;
char buffer3[256];
DWORD Type=REG_SZ;
DWORD dwBufferLen = 256;
cRegistry Registry;

Registry.OpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",KEY_ALL_ACCESS,Key);
Registry.QueryValueEx(Key,"kernel.dll",Type,dwBufferLen,buffer3);


Also, you realize that the value you get from the registry goes into the buffer, right? It''s not the return value of the function.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.