将HRESULT翻译成可读消息 [英] Translate HRESULT to a readable message

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

问题描述

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



我知道实用程序ERR.EXE执行此操作,但我的应用程序需要向我的用户显示一些有意义的消息,而不是隐藏的0x800A03EC。

解决方案

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



.NET内置的CLR互操作支持已经自动执行,您不应该需要帮助。它会看到一个COM接口方法返回失败代码时自动抛出一个适当的异常。 Message属性从IErrorInfo初始化。如果您没有收到任何正确的消息,那么COM服务器就不会提供。



哪个可能是0x800a03ec,它是一个抓包低级Excel错误有许多错误原因。你可以通过搜索excel error 1004找到大量的命中。


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

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.

解决方案

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.

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.

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天全站免登陆