error-handling - 如何获得DXGI_ERROR描述?

标签 error-handling directx directx-12

在D3D12程序中,我遇到了DGXI_ERROR(CreateSharedHandle返回int <0),但是我找不到将其转换为“错误描述”或“错误名称”(或两者)的方法。

我对Microsoft的描述是:https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-error

有这样的功能吗?

最佳答案

出于开发目的,Visual Studio中的“错误查找工具”可以告诉您值的转换和代码。

您还可以启用“DXGI调试”,这将在调试输出的调试输出窗口中提供有关错误情况的更多信息。参见this blog post

通过编程,您可以在Windows 10上使用FormatMessage进行操作:

LPWSTR errorText = nullptr;
DWORD result = FormatMessageW(
    FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ALLOCATE_BUFFER, nullptr, hr,
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    reinterpret_cast<LPWSTR>(&errorText), 0, nullptr );
if (result > 0)
{
    // errorText contains the description of the error code hr

    LocalFree( errorText );
}
else
{
    // Error not known by the OS
}

参见this blog post

关于error-handling - 如何获得DXGI_ERROR描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58248914/

相关文章:

python - python - 如何在python的另一个模块中排除ValueError?

r - 如何将警告()输出到字符串

javascript - C++ 或 v8 游戏引擎

c++ - 如何在 C++/Directx 中绘制圆的一部分?

c++ - DirectX:如何更改按钮对象的字体大小?

c++ - Win32 窗口不显示

c++ - C++ Direct X 12 示例代码中看似无用的行

php - 无法访问与您在CI3中的字段名称相对应的错误消息

php - php中错误处理的正确方法

windows - DXGI 翻转模型锁定垂直同步