1 HKEY regOldHKey;
2
3 //Open Register Key
4 if(::RegOpenKeyEx(HKEY_CURRENT_USER,"Software//OKI//CCons33//UNITTYPE",0,KEY_ALL_ACCESS,®OldHKey)==ERROR_SUCCESS)
5 {
6 long lResult;
7 DWORD dwIndex=0;
8 CHAR* tcKeyName = new CHAR[MAX_PATH];
9 DWORD dwKeyNameLen = MAX_PATH;
10 LPBYTE newByte = new BYTE[MAX_PATH];
11 DWORD nType;
12 DWORD lpSize=MAX_PATH;
13 LPBYTE pbbinKeyData=NULL;
14 while(TRUE)
15 {
16 //circulate the Register
17 lResult=RegEnumValue(regOldHKey,dwIndex,tcKeyName,&dwKeyNameLen,NULL,NULL,NULL,NULL);
18 if(lResult!=ERROR_SUCCESS)
19 break; //if the End then break;
20
21 //Use the key Get the value
22 long retValue;
23 if((retValue=::RegQueryValueEx(regOldHKey,(LPCTSTR)tcKeyName,NULL,&nType,newByte,&lpSize))==ERROR_MORE_DATA)
24 {
25 newByte=(LPBYTE)"NULL";
26 }
27
28 //Print the key and the value
29 cout<<"Key:"<<(LPCTSTR)tcKeyName;
30 cout<<"/t";
31 cout<<"Value:"<<(LPCTSTR)newByte<<endl;
32 dwIndex++;
33 dwKeyNameLen=MAX_PATH;
34 lpSize=MAX_PATH;
35 }
36 }
第二个问题:Link时出错问题
在VC中想把注册表删除,查MSDN查到了SHDeleteKey 这个函数,函数使用很简单:
![](http://writeblog.csdn.net/Images/OutliningIndicators/None.gif)
![](http://writeblog.csdn.net/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://writeblog.csdn.net/Images/OutliningIndicators/InBlock.gif)
![](http://writeblog.csdn.net/Images/OutliningIndicators/ExpandedBlockEnd.gif)
MSDN上面注明要加入shlwapi.h这个头文件,但我另进去之后,link出现错误. 说是LNK2001无法解析的外部符号“symbol”.
不加,找不到函数定义.
其实解决这个问题很简单.在VC菜单中Project->Setting->Link 下面project options的文本框中,输入shlwapi.lib问题就可以解决了.害得我花了几个小时时间.
(或者,在Code前面加上#pragma comment(lib,"shlwapi.lib"))也可以解决问题。