将HRESULT转换为可读消息 [英] Translate HRESULT to a readable message

查看:172
本文介绍了将HRESULT转换为可读消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以提供一些有关如何以编程方式翻译HRESULT的信息( http://en.wikipedia.org) / wiki / HRESULT )值到人类可读的消息?

Can anyone provide some information on how to programmatically translate HRESULT (http://en.wikipedia.org/wiki/HRESULT) values to a human-readable message?

我知道实用程序ERR.EXE会这样做,但我的应用程序需要向我的用户显示一些有意义的消息,而不是一个神秘的0x800A03EC。

I know that the utility ERR.EXE does this, but my app needs to display some meaningful message to my users rather than a cryptic 0x800A03EC.

推荐答案

没有内置支持从具有该值的HRESULT生成消息。 COM组件需要使用IErrorInfo接口来实现它。

There's no built-in support for generating messages from an HRESULT with that value. The COM component needs to implement that itself, using the IErrorInfo interface.

.NET中内置的CLR互操作支持已经自动实现了,你永远不需要帮助。它会在看到COM接口方法返回失败代码时自动抛出一个适当的异常。 Message属性从IErrorInfo初始化。如果你没有一个正确的消息,那么COM服务器只是不提供它。

The CLR interop support built into .NET already does that automatically, you should never need to help. It automatically throws an appropriate exception when it sees a COM interface method return a failure code. The Message property is initialized from IErrorInfo. If you get nothing decent as a message then the COM server just doesn't supply it.

这可能是0x800a03ec,它是一个抓包低级Excel错误有许多错误原因。您可以通过googlingexcel error 1004找到大量的匹配。

Which is likely for 0x800a03ec, it is a grab-bag low-level Excel error with many error causes. You can find plenty of hits for it by googling "excel error 1004".

这篇关于将HRESULT转换为可读消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆