我目前正在学习如何使用 c++ 处理注册表。我制作了一个应用程序,应该查看某个键中的某个值是否存在。但是,应用程序一到达 RegEnumValue() 就会崩溃。有什么想法可能是什么问题?
代码:
#include <iostream>
#include <windows.h>
#include <Psapi.h>
using namespace std;
bool registerKeyExists(char* key, char* subkey);
int main()
{
while(true){
if(registerKeyExists("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "SynTPEnh")){
return 0;
}
}
return 0;
}
bool registerKeyExists(char* key, char* subkey){
HKEY keyEnum;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &keyEnum) == ERROR_SUCCESS){
char* valueName;
DWORD valueSize = 100;
DWORD cbName;
FILETIME lastFiletime;
DWORD i = 0;
DWORD returnCode = ERROR_SUCCESS;
while(returnCode == ERROR_SUCCESS){
cout << "This show!" << endl;
returnCode = RegEnumValue(keyEnum, i, valueName, &valueSize, NULL, NULL, NULL, NULL);
cout << "This doesn't show!" << endl;
if(valueName == subkey)
return true;
i++;
}
}
return false;
}