一个简单的读写注册表实例[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 tongqingchao 的 blog

“查询”按钮代码如下:void cregeditdlg::onquery()
{
        updatedata(true);
hkey hkey;//定义有关的hkey,在查询结束时要关闭

//打开与路径 data_set相关的hkey
lpctstr data_set="software\\microsoft\\windows nt\\currentversion\\";
//访问注册表,hkey则保存此函数所打开的键的句柄
long ret0=(::regopenkeyex(hkey_local_machine,data_set,0,key_read,&hkey));
if(ret0!=error_success)//如果无法打开hkey,则中止程序的执行
{
afxmessagebox("错误:无法打开有关的hkey");
return;
}

//查询有关的数据
lpbyte owner_get=new byte[80];//定义用户姓名 owner_get
dword type_1=reg_sz;//定义数据类型
dword cbdata_1=80;//定义数据长度

long ret1=::regqueryvalueex(hkey,"registeredowner",null,&type_1,owner_get,&cbdata_1);
if(ret1!=error_success)
{
afxmessagebox("错误:无法查询有关的注册表信息");
return;
}

//查询公司名
lpbyte company_get=new byte[80];//定义公司名称 company_get
dword type_2=reg_sz;//定义数据类型
dword cbdata_2=80;//定义数据长度

long ret2=::regqueryvalueex(hkey,"registeredorganization",null,&type_2,company_get,&cb -

我叫小超~有事找我

本文关键:注册表
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top