有没有办法使用 win API 获取 HRESULT 值的字符串表示?

Is there a way to get the string representation of HRESULT value using win API?(有没有办法使用 win API 获取 HRESULT 值的字符串表示?)
本文介绍了有没有办法使用 win API 获取 HRESULT 值的字符串表示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

win API 中是否有一个函数可以用来提取 HRESULT 值的字符串表示?

Is there a function in win API which can be used to extract the string representation of HRESULT value?

问题是并非所有返回值都记录在 MSDN 中,例如 ExecuteInDefaultAppDomain() 函数没有记录为返回0x80070002 - 系统找不到指定的文件.",但是,它确实如此!所以,我想知道是否有一个函数可以在普通情况下使用.

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.

不要忘记包含标题 comdef.h

这篇关于有没有办法使用 win API 获取 HRESULT 值的字符串表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
STL BigInt class implementation(STL BigInt 类实现)
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)