問(wèn)題描述
win API 中是否有一個(gè)函數(shù)可以用來(lái)提取 HRESULT 值的字符串表示?
Is there a function in win API which can be used to extract the string representation of HRESULT value?
問(wèn)題是并非所有返回值都記錄在 MSDN 中,例如 ExecuteInDefaultAppDomain() 函數(shù)沒(méi)有記錄為返回0x80070002 - 系統(tǒng)找不到指定的文件.",但是,它確實(shí)如此!所以,我想知道是否有一個(gè)函數(shù)可以在普通情況下使用.
The problem is that not all return values are documented in MSDN, for example ExecuteInDefaultAppDomain() function is not documented to return "0x80070002 - The system cannot find the file specified.", however, it does! Therefore, I was wondering whether there is a function to be used in common case.
推薦答案
您可以使用 _com_error:
_com_error err(hr);
LPCTSTR errMsg = err.ErrorMessage();
如果您出于任何原因不想使用 _com_error
,您仍然可以查看其源代碼,看看它是如何完成的.
If you don't want to use _com_error
for whatever reason, you can still take a look at its source, and see how it's done.
不要忘記包含標(biāo)題 comdef.h
這篇關(guān)于有沒(méi)有辦法使用 win API 獲取 HRESULT 值的字符串表示?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!