【发布时间】:2013-08-22 04:22:05
【问题描述】:
我正在尝试使用 Windows API 中的 RegOpenKeyEx 函数打开注册表项,并使用以下代码:
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int wmain(int argc, wchar_t*argv [])
{
HKEY hKey = HKEY_CURRENT_USER;
LPCTSTR lpSubKey = L"Demo";
DWORD ulOptions = 0;
REGSAM samDesired = KEY_ALL_ACCESS;
HKEY phkResult;
long R = RegOpenKeyEx(hKey, lpSubKey, ulOptions, samDesired, &phkResult);
if (R == ERROR_SUCCESS)
{
cout << "The registry key has been opened." << endl;
}
else //How can I retrieve the standard error message using GetLastError() here?
{
}
}
如何使用GetLastError() 函数在else 中显示一般错误消息而不是有效的任何错误消息ID?
编辑:我知道有一个 FormatMessage 函数但有同样的问题,我不知道如何在我的代码中使用它。
【问题讨论】:
-
是的,但是如何在我的示例代码中使用 FormatMessage?
-
在您编辑问题之前,我的评论是有意义的。下次请尝试更具体。
标签: winapi