How to read value from the registry C++?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi All,
This is the code Im writing to read from my Windows 7 registry using VS2008.
Im able to read the value, but only the 1st character.But not the whole string.I think there is a problem with "char buf[255] = {0};" but not sure.
Can any one please help??
Note : the value in registry is "AT/AT COMPATIBLE"; Im only able to read "A".
Thanks in advance.
#include "stdafx.h"<br/>
#include <windows.h><br/>
#include <iostream><br/>
using namespace std;
//#define TOTALBYTES 8192
int _tmain(int argc, _TCHAR* argv[])<br/>
{<br/>
HKEY hKey;<br/>
char buf[255] = {0};<br/>
DWORD dwType = 0;<br/>
//DWORD BufferSize = TOTALBYTES;<br/>
// PPERF_DATA_BLOCK PerfData = (PPERF_DATA_BLOCK) malloc( BufferSize );<br/>
DWORD dwBufSize = sizeof(buf);<br/>
try<br/>
{ <br/>
//if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,SubKey,0,KEY_READ,&hKey) == ERROR_SUCCESS)<br/>
if(RegOpenKey(HKEY_LOCAL_MACHINE,_T("HARDWARE\DESCRIPTION\System"),&hKey) == ERROR_SUCCESS)<br/>
{<br/>
dwType = REG_SZ;<br/>
try<br/>
{<br/>
if(RegQueryValueEx(hKey,TEXT("Identifier"),NULL,NULL,(LPBYTE)buf,&dwBufSize)== ERROR_SUCCESS) <br/>
{<br/>
cout << "key value is " << buf << "n";<br/>
}<br/>
else<br/>
cout << "Query failed " << "n";<br/>
RegCloseKey(hKey);<br/>
}<br/>
catch(...)<br/>
{<br/>
printf("Exception occurred in inner loop");<br/>
}<br/>
}<br/>
else<br/>
cout << "Open failed " << "n";<br/>
}<br/>
catch(...)<br/>
{<br/>
printf("Exception occurred in outer loop");<br/>
}<br/>
return 0;<br/>
} <hr class="sig Jyotiranjan

View the full article
 
Back
Top