Cregkey operation Registry

Source: Internet
Author: User

// 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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.