gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 16:29:55 25 4
gpt4 key购买 nike

我想检索 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com