c++ - 如何检索 DirectX 9 的错误字符串

标签 c++ winapi com error-handling directx

我想检索 DirectX 9 的错误字符串,但我可以在网上找到使用 FormatMessage() 和 _com_error.ErrorMessage() 的方法,这两个方法都让我失望。

hr = g_pd3dDevice->GetRenderTargetData(...
... // the debugger tells me hr = 0x8876086c
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
    FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL, hr, 0, (LPTSTR)&lpBuf, 0, NULL))
// it returns 0 with lpBuf unallocated

FormatMessage() 失败,我再次将它与 GetLastError() 一起使用以查看 FormatMessage() 失败的原因: “系统在 %2 的消息文件中找不到消息编号 0x%1 的消息文本。”

_com_error.ErrorMessage() 告诉我“未知错误 0x8876086c”

最佳答案

要获取 DirectX 错误消息,有两个函数 — DXGetErrorString()DXGetErrorDescription()。话虽如此,FormatMessage() 不会为您提供所需的信息。这是一个小例子:

// You'll need this include file and library linked.
#include <DxErr.h>
#pragma comment(lib, "dxerr.lib")

...

if (FAILED(hr)) {
    fprintf(stderr, "Error: %s error description: %s\n",
        DXGetErrorString(hr), DXGetErrorDescription(hr));
}

关于c++ - 如何检索 DirectX 9 的错误字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13543195/

相关文章:

c++ - IncludeOS hello world 失败

C# 使用 FindWindowEx 按名称和序号获取子句柄

c++ - 如何让 EnumWindows 列出所有窗口?

vba - 使用 powerpoint 对象模型而不运行 powerpoint 应用程序

windows - 跨进程边界的 CRT 类型

c++ - 我可以根据某些计算结果定义类型吗?

c++ - 使程序运行更快的 Visual C++ 9 编译器选项

python - C-contiguous fashion在caffe blob存储中意味着什么?

c++ - MFC,如何从主窗口关闭模态对话框?

c++ - 无法编译 Microsoft COM/ActiveX 示例