RegQueryValueEx() 函数有问题
当我使用它时,它会用 0 填充 *lpData
LONG WINAPI RegQueryValueEx(
_In_ HKEY hKey,
_In_opt_ LPCTSTR lpValueName,
_Reserved_ LPDWORD lpReserved,
_Out_opt_ LPDWORD lpType,
_Out_opt_ LPBYTE lpData,
_Inout_opt_ LPDWORD lpcbData
);
这是不起作用的代码
#include <windows.h>
#include <stdio.h>
int main()
{
HKEY hKey = NULL;
DWORD data = 42;
DWORD type = REG_DWORD;
DWORD size = sizeof(DWORD);
LONG result;
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey);
if(result == ERROR_SUCCESS)
{
result = RegQueryValueEx(hKey, "InstallDate", NULL, &type, (LPBYTE)&data, &size);
RegCloseKey(hKey);
if (result == ERROR_SUCCESS)
printf("The value is : %d\n", data);
}
return (0);
}
输出:
值为:0
我使用 Visual Studio 2012 并且正在运行 Win7
编辑:更正的行
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
感谢@David Heffernan