I have created my own header file in order to simply reading Regedit.
Here is my header file:
HKEY myHKEY;
long longResult;
long ReadValueRegedit(HKEY hKey, string strSubKey, string strValueName, DWORD dwValueType, int intArchitecture, string strValue)
{
switch(intArchitecture)
{
case 32:
{
longResult = RegOpenKeyEx(hKey, strSubKey.c_str(), 0, KEY_READ | KEY_WOW64_32KEY, &myHKEY);
}
case 64:
{
longResult = RegOpenKeyEx(hKey, strSubKey.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &myHKEY);
}
}
if(longResult == ERROR_SUCCESS)
{
char chValue[MAX_PATH];
DWORD dwSize = MAX_PATH;
longResult = RegQueryValueEx(myHKEY, strValueName.c_str(), 0, &dwValueType, (LPBYTE)chValue, &dwSize);
if(longResult == ERROR_SUCCESS)
{
stringstream ssValue;
ssValue << chValue;
strValue = ssValue.str();
}
}
RegCloseKey(hKey);
return longResult;
}
I use my header file like this:
#include <conio.h>
#include <iostream>
#include <regedit.h> //My header file
using namespace std;
int main()
{
string strDeger;
long longSonuc = ReadValueRegedit(HKEY_CURRENT_USER, "SOFTWARE\\Disc Soft\\DAEMON Tools Lite", "InstallKey", REG_SZ, 32, strDeger);
cout << "Okunan Deger:\t" << strDeger << "\nIslem Sonucu:\t" << longSonuc;
getch();
return 0;
}
The variable which is called strDeger
, should show me content of the value which I want to regedit.
The variable which is called longSonuc
, shows error code and it throws 0 (ERROR_SUCCESS)
.
But the problem is strDeger shows nothing. It should show c6045c6c-97c2-4429-a7d1-00b5bfd4d21e
.
Click this link in order to display the output of my program.
So, what should I do in order to fix my issue?