How can I get the description for a HRESULT?

W

wundertier

Hi,

I'm accessing COM objects from C#.net.
In case of error a COMException is thrown which includes the HRESULT.
But how do I get the description for the HRESULT?
The Message property of the COMException does not contain any useful
information.
Example (I've got a german OS only, so I don't know the exact english
version of these texts):
HRESULT is: 800706ba
Message is: "Die COM-Klassenfactory für die Komponente mit CLSID
{E36D3A64-1FCE-11D3-B2EF-00104B066E1A} konnte aufgrund des folgenden
Fehlers nicht abgerufen werden: 800706ba."
(The COM-factory for the component with CLSID {E36D3A64-1FCE-11D3-
B2EF-00104B066E1A} could not be called because of the following error:
800706ba.)

What I would like to get is what tools like ERRLOOK return:
"Der RPC-Server ist nicht verfügbar."
(RPC server is not available.)

Is there a way to access these error texts from C#?

Thanks for help!

Steffi
 
K

KWienhold

Hi,

I'm accessing COM objects from C#.net.
In case of error a COMException is thrown which includes the HRESULT.
But how do I get the description for the HRESULT?
The Message property of the COMException does not contain any useful
information.
Example (I've got a german OS only, so I don't know the exact english
version of these texts):
HRESULT is: 800706ba
Message is: "Die COM-Klassenfactory für die Komponente mit CLSID
{E36D3A64-1FCE-11D3-B2EF-00104B066E1A} konnte aufgrund des folgenden
Fehlers nicht abgerufen werden: 800706ba."
(The COM-factory for the component with CLSID {E36D3A64-1FCE-11D3-
B2EF-00104B066E1A} could not be called because of the following error:
800706ba.)

What I would like to get is what tools like ERRLOOK return:
"Der RPC-Server ist nicht verfügbar."
(RPC server is not available.)

Is there a way to access these error texts from C#?

Thanks for help!

Steffi

Maybe you should take a look at
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR, this
should convert HRESULTs into .Net Exceptions with the appropriate text
and throw them. If you only need to know the message of the exception
you could just catch the exception right away again, though there may
be a more elegant solution that I am not aware of.

hth,
Kevin Wienhold
 
K

Kevin Spencer

Sometimes, calling the Windows API GetLastError and FormatMessage functions
will yield some additional data about the error, depending on the software
which throws the error. See:

http://msdn2.microsoft.com/en-us/library/ms679360(VS.85).aspx

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

Hi,

I'm accessing COM objects from C#.net.
In case of error a COMException is thrown which includes the HRESULT.
But how do I get the description for the HRESULT?
The Message property of the COMException does not contain any useful
information.
Example (I've got a german OS only, so I don't know the exact english
version of these texts):
HRESULT is: 800706ba
Message is: "Die COM-Klassenfactory für die Komponente mit CLSID
{E36D3A64-1FCE-11D3-B2EF-00104B066E1A} konnte aufgrund des folgenden
Fehlers nicht abgerufen werden: 800706ba."
(The COM-factory for the component with CLSID {E36D3A64-1FCE-11D3-
B2EF-00104B066E1A} could not be called because of the following error:
800706ba.)

What I would like to get is what tools like ERRLOOK return:
"Der RPC-Server ist nicht verfügbar."
(RPC server is not available.)

Is there a way to access these error texts from C#?

Thanks for help!

Steffi
 
W

Willy Denoyette [MVP]

Hi,

I'm accessing COM objects from C#.net.
In case of error a COMException is thrown which includes the HRESULT.
But how do I get the description for the HRESULT?
The Message property of the COMException does not contain any useful
information.
Example (I've got a german OS only, so I don't know the exact english
version of these texts):
HRESULT is: 800706ba
Message is: "Die COM-Klassenfactory für die Komponente mit CLSID
{E36D3A64-1FCE-11D3-B2EF-00104B066E1A} konnte aufgrund des folgenden
Fehlers nicht abgerufen werden: 800706ba."
(The COM-factory for the component with CLSID {E36D3A64-1FCE-11D3-
B2EF-00104B066E1A} could not be called because of the following error:
800706ba.)

What I would like to get is what tools like ERRLOOK return:
"Der RPC-Server ist nicht verfügbar."
(RPC server is not available.)

Is there a way to access these error texts from C#?

Thanks for help!

Steffi



I don't think that "The RPC server is unavailable." is more usefull than
"The COM-factory for the component with CLSID
{E36D3A64-1FCE-11D3-B2EF-00104B066E1A} could not be called because of the
following error:800706ba.)
The first is the Win32 error message for error code "06ba", that is the
lowest 16 bits of HRESULT, the latter is the COM error message for
0x800706ba.
So, IMO the latter is more descriptive, it tell's you that a Class with
CLSID .... could not be constructed because it's class factory could not be
called due to: 800706ba.
THat means that your out-proc server could not be activated/launched,
probably because of a security issue (the 7 in 8007).

If you really need the HRESULT message you'll have to call
Marshal.GetExceptionForHR(), like so:

...
int hr unchecked ((int) 0x800706ba);
Marshal.GetExceptionForHR(hr).Message

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top