您的位置:首页 > 其它

SDK 注册表 读写

2009-09-13 20:52 162 查看
#include <iostream>
#include <string>
#include <cctype>
#include <windows.h>
using namespace std;

void RegWrite();
void RegRead();

int main()
{
RegWrite();
RegRead();
return 0;
}

void RegWrite()
{
HKEY hKEY;
//The RegCreateKey function creates the specified registry key. If the key already exists in the registry, the function opens it.
RegCreateKey(HKEY_LOCAL_MACHINE,"Software//Mike//admin",&hKEY);
//The RegSetValue function sets the data for the default or unnamed value of a specified registry key. The data must be a text string.
//设置默认的KEY的value
RegSetValue(hKEY,NULL,REG_SZ,"Mike",strlen("Mike"));

DWORD dwAge=89;
//The RegSetValueEx function sets the data and type of a specified value under a registry key.
RegSetValueEx(hKEY,"age",0,REG_DWORD,(CONST BYTE*)&dwAge,4);
RegCloseKey(hKEY);

}

void RegRead()
{
//方法一  读取一般的 key 的值
LONG lValue;
//lValue 用于存储值的字节产度
RegQueryValue(HKEY_LOCAL_MACHINE,"Software//Mike//admin",NULL,&lValue);
char* pBuf=new char[lValue];
RegQueryValue(HKEY_LOCAL_MACHINE,"Software//Mike//admin",pBuf,&lValue);
cout<<pBuf<<endl;

//方法二
HKEY hKey;
RegOpenKey(HKEY_LOCAL_MACHINE,"Software//Mike//admin",&hKey);
DWORD dwType;
DWORD dwValue;
DWORD dwAge;
RegQueryValueEx(hKey,"age",0,&dwType,(LPBYTE)&dwAge,&dwValue);
cout<<dwAge<<endl;
}


效果:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: