我正在尝试打开Windows默认用户的注册表配置单元。我收到错误“参数无效”。我的代码如下:
PHKEY loadDefaultHiveAppKey(){
PHKEY temporaryHKEY = 0;
wchar_t * errorText = 0;
//wchar_t * defaultProfileHiveFile = getDefaultUserProfileHive();
/* For debugging purpouses use a hardcoded path */
wchar_t * defaultProfileHiveFile = L"C:\\Users\\Default\\NTUSER.dat";
long returnCode = 0;
returnCode = RegLoadAppKey(
defaultProfileHiveFile,
temporaryHKEY,
KEY_ALL_ACCESS,
REG_PROCESS_APPKEY,
0
);
//free(defaultProfileHiveFile);
if(returnCode != ERROR_SUCCESS){
// http://stackoverflow.com/questions/455434/how-should-i-use-formatmessage-properly-in-c
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
returnCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&errorText,
0,
NULL
);
printf("Failed to open registry hive!\n");
if(errorText != 0){
/* This prints "The Parameter is Incorrect" */
printf("%ls\n", errorText);
LocalFree(errorText);
errorText = NULL;
} else {
printf("Unknown reason!\n");
}
return 0;
}
return temporaryHKEY;
}
我的主要基本上只是调用前面的方法。这是RegLoadAppKey
的msdn文章。
答案 0 :(得分:1)
您的phkResult
错了。如果你把它读作指向HKEY的指针就更清楚了。你需要的是:
HKEY temporaryHKEY;
returnCode = RegLoadAppKey(
defaultProfileHiveFile,
&temporaryHKEY,
KEY_ALL_ACCESS,
REG_PROCESS_APPKEY,
0
);