首先明確一下hkey的概念。從字面上看它是乙個key的控制代碼。讀寫位置的確定就靠它了。開啟登錄檔編輯器("regedit"),裡面的hkey_current_user還有hkey_local_machine這些是不是hkey控制代碼呢?必然是啊,都hkey打頭了......
明確這個之後,一些問題就好解決了。所有的登錄檔操作都需要hkey控制代碼,但形式不太一樣。
比如我想在local_machine下新增乙個鍵值,regcreatekey函式第二個引數是子鍵值,好了,我想寫多少層就寫多少層。
同樣,建立預設鍵也有子鍵值這個引數。但是建立普通鍵就沒有子鍵值,所以要想辦法得到乙個確切的hkey。這就要用到regopenkey了。另外regcreatekey的第三個引數也可以得到。
上**......
void csetregdlg::onsetreg()
void csetregdlg::ongetreg()
char *pbuf = new char[lvalue];
regqueryvalue(hkey_local_machine,"software\\fansyreg\\test",pbuf,&lvalue);
hkey hkey;
long res1 = regopenkey(hkey_local_machine,"software\\fansyreg\\test",&hkey);
dword dwage = 0;
dword dwlength; //不知為何不允許初始化
res = regqueryvalueex(hkey,"age",null,null,(lpbyte)&dwage,&dwlength);//最後乙個引數不允許為空
if (res != error_success)
cstring str;
str.format("default value is %s, age = %d",pbuf,dwage);
messagebox(str);
delete pbuf;
pbuf = null;
}
讀寫登錄檔
ie 是現在windows 平台下用的最多的瀏覽器,那麼如何用程式來修改 ie,打造有自己的特色的 ie呢?我在這裡向介紹怎麼 c 用通過登錄檔來修改ie。首先我們來熟悉一下 c 中修改登錄檔的方法與函式。在 vc 中提供了 registry 類 registrykey 類來實現對登錄檔的操作。其中...
讀寫登錄檔
寫登錄檔 registrykey regwrite 往hkey current user主鍵裡的software子鍵下寫乙個名為 test 的子鍵 如果test子鍵已經存在系統會自動覆蓋它 regwrite registry.currentuser.createsubkey software tes...
C 中對登錄檔的操作 讀寫登錄檔方法
從登錄檔中讀資訊 要讀取的鍵值 讀到的鍵值字串,如果失敗 如登錄檔尚無資訊 則返回 private function readinfo byval p keyname as string dim softwarekey as registrykey registry.localmachine.ope...