// Write text
Void writestring (cregkey & Key, cstringw valuename, cstringw value)
{
Key. setstringvalue (valuename, value );
}
// Write bool
Void writeboolean (cregkey & Key, cstringw valuename, bool value)
{
Writestring (Key, valuename, value? _ T ("true"): _ T ("false "));
}
// Write DWORD
Void writedword (cregkey & Key, cstringw valuename, DWORD Value)
{
Key. setdwordvalue (valuename, value );
}
// Write to the Registry
Void writeprops ()
{
Cregkey key;
Key. Create (HKEY_LOCAL_MACHINE, _ T ("software // chain // CPP "));
Writestring (Key, _ T ("game"), _ T ("Kage "));
Writedword (Key, _ T ("year"), 1990 );
Writeboolean (Key, _ T ("ispass"), true );
}
// Read text
Bool readstring (cregkey & Key, cstringw valuename, cstringw & value)
{
Tchar s [_ max_path];
DWORD Len = _ max_path;
If (key. querystringvalue (valuename, S, & Len) = error_success)
{
Value = s;
Return true;
}
Return false;
}
// Read bool
Bool readboolean (cregkey & Key, cstringw valuename, bool & value)
{
Cstringw S;
// Read the text value first
If (readstring (Key, valuename, S ))
{
// Judge whether it is true
Value = (cstringw ("true"). comparenocase (S) = 0 );
Return true;
}
Return false;
}
// Read DWORD
Bool readdword (cregkey & Key, cstringw valuename, DWORD & value)
{
DWORD dw;
If (key. querydwordvalue (valuename, DW) = error_success)
{
Value = dw;
Return true;
}
Return false;
}
// Read the Registry
Void readprops ()
{
Cregkey key;
Key. Open (HKEY_LOCAL_MACHINE, _ T ("software // chain // CPP "));
Cstringw game;
DWORD year;
Bool ispass;
Readstring (Key, _ T ("game"), game );
Readdword (Key, _ T ("year"), year );
Readboolean (Key, _ T ("ispass"), ispass );
_ Tprintf (_ T ("game name: % S/R/n release year: % d/R/n customs clearance: % S/R/N"), game, year, ispass? _ T ("customs clearance"): _ T ("no customs clearance "));
}
Int main ()
{
Setlocale (lc_all, "CHS ");
Writeprops ();
Sleep (100 );
Readprops ();
Return 0;
}