/* The original version of this program can be found at http://damb.dk */
#include <windows.h>
#include <iostream.h>
int main(void)
{
HKEY hKey;
DWORD Value = 0;
// Try to read
if(RegOpenKey(HKEY_CURRENT_USER, "Software\\MyCompany\\MyApp", &hKey) == ERROR_SUCCESS)
{
DWORD Type = REG_DWORD, Size = sizeof(DWORD);
RegQueryValueEx(hKey, "Value", 0, &Type, (BYTE *)&Value, &Size);
cout << "Got Value: " << Value << endl;
}
else
cout << "Failed to read value" << endl;
RegCloseKey(hKey);
// Try to save the Value
if(RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\MyCompany\\MyApp", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, 0) == ERROR_SUCCESS)
{
Value++;
RegSetValueEx(hKey, "Value", 0, REG_DWORD, (BYTE *)&Value, sizeof(Value));
cout << "Did write value" << endl;
}
else
cout << "Failed to write value" << endl;
RegCloseKey(hKey);
return 0;
}