C 及WinAPI讀寫登錄檔

2021-09-10 16:11:01 字數 1240 閱讀 3724

需要使用標頭檔案

"windows.h"

1.regoperator.h

/***呼叫winapi讀寫登錄檔

**/#ifndef regoperator_h

#define regoperator_h

#include"windows.h"

#include"tchar.h"

class regoperator

;#endif // regoperator_h

2.regoperator.cpp

#include "regoperator.h"

#includeregoperator::regoperator()

//寫登錄檔

void regoperator::regwrite(hkey keyhandle ,lpcwstr subkey,lpcstr valuename,

dword valuetype,const char *valuestring)

}regclosekey(hkey);

//關閉才能寫入

}//讀登錄檔

unsigned char *regoperator::regread(hkey keyhandle,lpcwstr subkey, lpcstr valuename,lpdword valuetype)

//先查詢鍵值的長度

unsigned long size=0;

//當查詢reg_sz、reg_multi_sz或reg_expand_sz型別資料時,需要用regqueryvalueexa,

//否則用regqueryvalueex(注意兩者的引數型別不同)

if(regqueryvalueexa(hkey,valuename,0,valuetype,null,&size)!=error_success)

unsigned char *result=new unsigned char[size];

memset(result,0,size);//將陣列的每個元素設為'/0'

if(regqueryvalueexa(hkey,valuename,0,valuetype, result,&size)!=error_success)

regclosekey(hkey);

return result;

}

C 讀寫登錄檔

static void main string args registry可以獲取登錄檔的根節點。registrykey.createsubkey可以在節點下建立子節點。通過 分隔,可以建立多級節點。setvalue方法用來在指定的節點下建立乙個鍵值對。deletesubkeytree可以遞迴刪除乙...

C 讀寫登錄檔

c 程式設計打造自己的ie瀏覽器選擇自 yudehui 的 blog 關鍵字c 程式設計打造自己的ie瀏覽器 出處ie 是現在windows 平台下用的最多的瀏覽器,那麼如何用程式來修改 ie,打造有自己的特色的 ie呢?我在這裡向介紹怎麼 c 用通過登錄檔來修改ie。首先我們來熟悉一下 c 中修改...

C 讀寫登錄檔

ie 是現在windows 平台下用的最多的瀏覽器,那麼如何用程式來修改 ie,打造有自己的特色的 ie呢?我在這裡向介紹怎麼 c 用通過登錄檔來修改ie。首先我們來熟悉一下 c 中修改登錄檔的方法與函式。在 vc 中提供了 registry 類 registrykey 類來實現對登錄檔的操作。其中...