Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate HRESULT to a readable message

Tags:

c#

excel

com

vsto

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.

like image 612
code4life Avatar asked May 26 '10 15:05

code4life


2 Answers

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".

like image 168
Hans Passant Avatar answered Oct 18 '22 04:10

Hans Passant


Have you tried FormatMessage function? You can use it from C# using PInvoke mechanism.

like image 40
nkrkv Avatar answered Oct 18 '22 03:10

nkrkv