VC++读写注册表一。写注册表, 两个函数: RegCreatekeyEx,RegSetValueEx
void WriteReg()
{
//test1:在根结点上创建子键
CString strSubKey= "MySubKey";
HKEY hkey1, hkey2;
long lrt, lRtVal;
DWORD dwdisposition= REG_CREATED_NEW_KEY;
if( ERROR_SUCCESS == RegCreateKeyEx( HKEY_CURRENT_USER, strSubKey, 0, NULL, 0, KEY_CREATE_SUB_KEY | KEY_SET_VALUE, NULL, &hkey1, &dwdisposition ) )
//注:KEY_CREATE_SUB_KEY | KEY_SET_VALUE标志分别用于后面创建子键,后创建键值项, {
//test2:在刚创建的子键(MySubKey)下再创建子键( MySubSubKey)
lrt = RegCreateKeyEx( hkey1, "MySubSubKey", 0, NULL, 0, KEY_CREATE_SUB_KEY | KEY_SET_VALUE, NULL, &hkey2, &dwdisposition );
//test3:在第一步创建的子键MySubKey下增加键值项
CString strValue="value of the MySubKey's valueItem";
lRtVal= RegSetValueEx( hkey1, "valItem1", 0, REG_SZ, (const byte *)(LPCTSTR)strValue , strValue.GetLength() + 1 );
//test4:在MySubSubKey下创建键值项
if( lrt == ERROR_SUCCESS )
{
strValue="value of the MySubSubKey's valueItem";
lRtVal= RegSetValueEx( hkey2, "valItem1", 0, REG_SZ, (const byte *)(LPCTSTR)strValue , strValue.GetLength() + 1 );
}
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载