mirror of
https://github.com/microsoft/DirectXTex.git
synced 2026-02-07 13:26:13 +01:00
command-line tools updated to provide text description for HRESULTs
This commit is contained in:
@@ -890,6 +890,36 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
const wchar_t* GetErrorDesc(HRESULT hr)
|
||||
{
|
||||
static wchar_t desc[1024] = {};
|
||||
|
||||
LPWSTR errorText = nullptr;
|
||||
|
||||
DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, nullptr,
|
||||
static_cast<DWORD>(hr),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&errorText), 0, nullptr);
|
||||
|
||||
*desc = 0;
|
||||
|
||||
if (result > 0 && errorText)
|
||||
{
|
||||
swprintf_s(desc, L": %ls", errorText);
|
||||
|
||||
size_t len = wcslen(desc);
|
||||
if (len >= 2)
|
||||
{
|
||||
desc[len - 2] = 0;
|
||||
desc[len - 1] = 0;
|
||||
}
|
||||
|
||||
if (errorText)
|
||||
LocalFree(errorText);
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
_Success_(return != false)
|
||||
bool CreateDevice(int adapter, _Outptr_ ID3D11Device** pDevice)
|
||||
{
|
||||
@@ -1221,7 +1251,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L"Failed to initialize COM (%08X)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L"Failed to initialize COM (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1876,7 +1906,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = LoadFromDDSFile(pConv->szSrc, ddsFlags, &info, *image);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -1907,7 +1937,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = LoadFromBMPEx(pConv->szSrc, WIC_FLAGS_NONE | dwFilter, &info, *image);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -1917,7 +1947,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = LoadFromTGAFile(pConv->szSrc, TGA_FLAGS_NONE, &info, *image);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -1927,7 +1957,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = LoadFromHDRFile(pConv->szSrc, &info, *image);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -1937,7 +1967,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = LoadFromPortablePixMap(pConv->szSrc, &info, *image);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -1947,7 +1977,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = LoadFromPortablePixMapHDR(pConv->szSrc, &info, *image);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -1958,7 +1988,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = LoadFromEXRFile(pConv->szSrc, &info, *image);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -1981,7 +2011,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = LoadFromWICFile(pConv->szSrc, wicFlags, &info, *image);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -2012,7 +2042,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = ConvertToSinglePlane(img, nimg, info, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [converttosingleplane] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [converttosingleplane] (%08X%ls)\n",
|
||||
static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -2064,7 +2095,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = timage->Initialize(mdata);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [BC non-multiple-of-4 fixup] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [BC non-multiple-of-4 fixup] (%08X%ls)\n",
|
||||
static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2114,7 +2146,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = Decompress(img, nimg, info, DXGI_FORMAT_UNKNOWN /* picks good default */, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [decompress] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [decompress] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -2172,7 +2204,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = PremultiplyAlpha(img, nimg, info, TEX_PMALPHA_REVERSE | dwSRGB, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [demultiply alpha] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [demultiply alpha] (%08X%ls)\n",
|
||||
static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -2216,7 +2249,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = FlipRotate(image->GetImages(), image->GetImageCount(), image->GetMetadata(), dwFlags, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [fliprotate] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [fliprotate] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2272,7 +2305,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = Resize(image->GetImages(), image->GetImageCount(), image->GetMetadata(), twidth, theight, dwFilter | dwFilterOpts, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [resize] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [resize] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2323,7 +2356,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
}, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [swizzle] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [swizzle] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2360,7 +2393,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
dwFilter | dwFilterOpts | dwSRGB | dwConvert, alphaThreshold, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [convert] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [convert] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2592,7 +2625,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
}
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [rotate color apply] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [rotate color apply] (%08X%ls)\n",
|
||||
static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2643,7 +2677,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
});
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [tonemap maxlum] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [tonemap maxlum] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2672,7 +2706,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
}, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [tonemap apply] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [tonemap apply] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2727,7 +2761,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = ComputeNormalMap(image->GetImages(), image->GetImageCount(), image->GetMetadata(), dwNormalMap, nmapAmplitude, nmfmt, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [normalmap] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [normalmap] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2760,7 +2794,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
dwFilter | dwFilterOpts | dwSRGB | dwConvert, alphaThreshold, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [convert] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [convert] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2819,7 +2853,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
}, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [colorkey] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [colorkey] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2868,7 +2902,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
}, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [inverty] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [inverty] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2929,7 +2963,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
}, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [reconstructz] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [reconstructz] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2989,7 +3023,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = timage->Initialize(mdata);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [copy to single level] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [copy to single level] (%08X%ls)\n",
|
||||
static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3001,7 +3036,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
*timage->GetImage(0, 0, d), TEX_FILTER_DEFAULT, 0, 0);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [copy to single level] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [copy to single level] (%08X%ls)\n",
|
||||
static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -3014,7 +3050,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
*timage->GetImage(0, i, 0), TEX_FILTER_DEFAULT, 0, 0);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [copy to single level] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [copy to single level] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -3031,7 +3067,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = timage->Initialize(mdata);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [copy compressed to single level] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [copy compressed to single level] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3083,7 +3119,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
}
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [mipmaps] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [mipmaps] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3115,7 +3151,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = timage->Initialize(image->GetMetadata());
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [keepcoverage] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [keepcoverage] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3128,7 +3164,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = ScaleMipMapsAlphaForCoverage(img, info.mipLevels, info, item, preserveAlphaCoverageRef, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [keepcoverage] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [keepcoverage] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -3174,7 +3210,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
hr = PremultiplyAlpha(img, nimg, info, TEX_PMALPHA_DEFAULT | dwSRGB, *timage);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [premultiply alpha] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [premultiply alpha] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -3292,7 +3328,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
}
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED [compress] (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED [compress] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -3364,7 +3400,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
wchar_t szPath[MAX_PATH] = {};
|
||||
if (!GetFullPathNameW(szDest, MAX_PATH, szPath, nullptr))
|
||||
{
|
||||
wprintf(L" get full path FAILED (%x)\n", static_cast<unsigned int>(HRESULT_FROM_WIN32(GetLastError())));
|
||||
wprintf(L" get full path FAILED (%08X%ls)\n",
|
||||
static_cast<unsigned int>(HRESULT_FROM_WIN32(GetLastError())), GetErrorDesc(HRESULT_FROM_WIN32(GetLastError())));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -3372,7 +3409,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
auto err = static_cast<DWORD>(SHCreateDirectoryExW(nullptr, szPath, nullptr));
|
||||
if (err != ERROR_SUCCESS && err != ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
wprintf(L" directory creation FAILED (%x)\n", static_cast<unsigned int>(HRESULT_FROM_WIN32(err)));
|
||||
wprintf(L" directory creation FAILED (%08X%ls)\n",
|
||||
static_cast<unsigned int>(HRESULT_FROM_WIN32(err)), GetErrorDesc(HRESULT_FROM_WIN32(err)));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -3534,7 +3572,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user