My guess is that you are calling RegCloseKey() between those two function calls. Here's a non-template version that works
#include <Windows.h>
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::string;
BOOL ShowError(long dwError)
{
char buf[255]= {0};
if( dwError != 0)
{
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0, (DWORD)dwError,0,buf,sizeof(buf),0);
cout << buf << '\n';
return TRUE;
}
return FALSE;
}
unsigned long GetValue (HKEY Key,std::string Name,unsigned long& Value) {
unsigned long DataSize;
DataSize = sizeof(long);
ShowError(RegQueryValueEx (Key,Name.c_str(),0,NULL,(unsigned char*)&Value,
&DataSize));
return Value;
}
char* GetValue (HKEY Key,std::string Name, char Value[1024]) {
//memset (Value,0,sizeof(Value)/sizeof(char));
Value[0] = 0;
unsigned long DataSize = 1024;
ShowError(RegQueryValueEx (Key,Name.c_str(),0,NULL,(unsigned char*)Value,
&DataSize));
return Value;
}
int main()
{
HKEY hKey = 0;
char strValue[255] = {0};
unsigned long dwValue = 0;
if( ShowError(RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Active Setup",&hKey)) )
{
return 1;
}
GetValue(hKey,"JITSetupPage",strValue);
GetValue(hKey,"DisableRepair",dwValue);
RegCloseKey(hKey);
cout << strValue << '\n';
cout << dwValue << '\n';
}