如何获取 DXGI_ERROR 描述?

How to get DXGI_ERROR description?

在D3D12程序中,我遇到了一个DGXI_ERRORCreateSharedHandle returns一个int <0),但是我找不到办法将其翻译成 "error description" 或 "error name"(或两者)。

我有微软的描述:https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-error

有没有这样的功能?

出于开发目的,Visual Studio 中的 "Error Lookup Tool" 可以从一个值告诉您翻译和代码。

您还可以启用 "DXGI Debugging",这将在您的调试版本的调试输出 window 中提供有关错误案例的更多信息。参见 this blog post

以编程方式,您可以在 Windows 上使用 FormatMessage 10:

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