problem reading string from registry
-
Problem with reading a string from the registry (example windows version). I tryed this and it worked fine: char* text; //unsigned long* buffer; DWORD* buffer; unsigned long PerServer; unsigned long Per1_0Server; CRegKey reg; reg.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); reg.QueryValue(PerServer,"MaxConnectionsPerServer"); but when i try to read a string (the windows version name) with: reg.Open(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion"); reg.QueryValue(text,"ProductName",buffer); i get an assertation error on the line "pdwCount!=null;" (in CRegKey) if i change buffer to anything using "buffer=(unsigned long*)999;" i dont get the error but i get no data. Am i being stupid? I cant see where im going wrong. An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
-
Problem with reading a string from the registry (example windows version). I tryed this and it worked fine: char* text; //unsigned long* buffer; DWORD* buffer; unsigned long PerServer; unsigned long Per1_0Server; CRegKey reg; reg.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); reg.QueryValue(PerServer,"MaxConnectionsPerServer"); but when i try to read a string (the windows version name) with: reg.Open(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion"); reg.QueryValue(text,"ProductName",buffer); i get an assertation error on the line "pdwCount!=null;" (in CRegKey) if i change buffer to anything using "buffer=(unsigned long*)999;" i dont get the error but i get no data. Am i being stupid? I cant see where im going wrong. An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
To use the CRegKey::QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount) overload, you'll have to have an allocated (or static) buffer for szValue and the size of the buffer in a variable pointed to by pdwCount before calling QueryValue()
// here's the maximum length of our text buffer #define TEXTLENGTH 120 // that's the text buffer itself char text[TEXTLENGTH]; // here's a variable used both to tell QueryValue about the // buffer's length and to get QueryValue's length answer DWORD textlength; // the registry key object CRegKey reg; // stuff omitted (... snip ...) // initialize with maximum length of text buffer textlength = TEXTLENGTH; // query the registry key reg.QueryValue(text, "ProductName", &textlength); // now textlength is changed, it contains the actual length // of the text retrieved from the registry.
-
Problem with reading a string from the registry (example windows version). I tryed this and it worked fine: char* text; //unsigned long* buffer; DWORD* buffer; unsigned long PerServer; unsigned long Per1_0Server; CRegKey reg; reg.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); reg.QueryValue(PerServer,"MaxConnectionsPerServer"); but when i try to read a string (the windows version name) with: reg.Open(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion"); reg.QueryValue(text,"ProductName",buffer); i get an assertation error on the line "pdwCount!=null;" (in CRegKey) if i change buffer to anything using "buffer=(unsigned long*)999;" i dont get the error but i get no data. Am i being stupid? I cant see where im going wrong. An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
ALWAYS USE API s.............THEY ARE COOOOOOOOOOOOOL EXAMPLE IS: HKEY hkey; DWORD dwSize; char szInstalledapth[MAX_PATH*2] if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Renjith\\",0,KEY_READ,&hkey)!=ERROR_SUCCESS) { MessageBox(HWND_DESKTOP,"Unable To oen registry","Registry Error",MB_ICONERROR); return FALSE; } //Reading a String dwSize=MAX_PATH; if(RegQueryValueEx(hkey,"InstalledPath",0,NULL,(LPBYTE) szInstalledapth,&dwSize)!=ERROR_SUCCESS) { RegCloseKey(hkey); return FALSE; } //////////READING A DWORD DWORD dwLogLevel; dwSize=sizeof(DWORD); if(RegQueryValueEx(hkey,"LogLevel",0,NULL,(unsigned char*)&dwLogLevel,&dwSize)!=ERROR_SUCCESS) { RegCloseKey(hkey); return FALSE; } //CLOSING THE REGISTRY if(hkey) RegCloseKey(hkey); R_Renjith The True CP ian
-
To use the CRegKey::QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount) overload, you'll have to have an allocated (or static) buffer for szValue and the size of the buffer in a variable pointed to by pdwCount before calling QueryValue()
// here's the maximum length of our text buffer #define TEXTLENGTH 120 // that's the text buffer itself char text[TEXTLENGTH]; // here's a variable used both to tell QueryValue about the // buffer's length and to get QueryValue's length answer DWORD textlength; // the registry key object CRegKey reg; // stuff omitted (... snip ...) // initialize with maximum length of text buffer textlength = TEXTLENGTH; // query the registry key reg.QueryValue(text, "ProductName", &textlength); // now textlength is changed, it contains the actual length // of the text retrieved from the registry.
Thanks, that got it going first time. thank you again - Lucky :) An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
-
Problem with reading a string from the registry (example windows version). I tryed this and it worked fine: char* text; //unsigned long* buffer; DWORD* buffer; unsigned long PerServer; unsigned long Per1_0Server; CRegKey reg; reg.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); reg.QueryValue(PerServer,"MaxConnectionsPerServer"); but when i try to read a string (the windows version name) with: reg.Open(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion"); reg.QueryValue(text,"ProductName",buffer); i get an assertation error on the line "pdwCount!=null;" (in CRegKey) if i change buffer to anything using "buffer=(unsigned long*)999;" i dont get the error but i get no data. Am i being stupid? I cant see where im going wrong. An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
Lucky the code machine wrote: char* text; //unsigned long* buffer; DWORD* buffer; unsigned long PerServer; unsigned long Per1_0Server; CRegKey reg; You don't initialize your variables. do this instead:
TCHAR text[1024]; //May be any length suitable for the value
//unsigned long* buffer;
DWORD buffer = 1024;
unsigned long PerServer;
unsigned long Per1_0Server;
CRegKey reg;reg.Open(HKEY_LOCAL_MACHINE,_T("Software\\Microsoft\\Windows\\CurrentVersion"));
reg.QueryValue(text,_T("ProductName"),&buffer);Often, when a method asks for a pointer to value, it asks for a placeholder to return something to you. but the this pointer must point to valid memory area. Also, note use of TCHAR and _T(""). Michel It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard