custom HRESULT decoding to error message 
Author Message
 custom HRESULT decoding to error message

Hi list!

I use a COM object (from the SOAP SDK 3.0) which returns custom HRESULTs
when errors occur. How can I decode these HRESULTs to their string
equivalent (textual description)? I use Visual C++ 6.0 and #import to
generate smart pointers/wrappers for the COM interfaces. So the methods
throw com_error exceptions when something goes wrong, but the ErrorMessage()
method returns the generic "Unknown error" message.

I read through documentation that com_error implementation uses
FormatMessage to find that string. I noticed it takes a HMODULE handle to
know where to look for the message table, but the com_error implementation
doesn't use it. I believe that I have to manually load the library to obtain
the HMODULE and call FormatMessage myself? This is not a nice solution, as I
don't know at run-time what DLL is loaded for MSSOAP, as the COM subsystem
does that, through the registry (of course I can find out its name, but
still, it's not a nice way to deal with this..)

How could I do find that textual error description?

Thanks in advance,
iuli



Mon, 23 May 2005 22:30:57 GMT  
 custom HRESULT decoding to error message
Unlike WIn32 errors, HRESULTs are not associated with text
messages. You can produce a message DLL, but that's not
standard behavior (most clients won't expect to find it).
Instead, in COM you can use rich exception information
which is passed per method (there's no strong relation
between the HRESULT and the returned text, just casual
relation about both being returned by the same call).
Then you'd use the Description property of the _com_error
object in your client. The ErrorMessage property is only
useful for standard HRESULTs. The object must also
implement ISupportErrorInfo to advertize the fact it
produces rich exception information.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> Hi list!

> I use a COM object (from the SOAP SDK 3.0) which returns custom HRESULTs
> when errors occur. How can I decode these HRESULTs to their string
> equivalent (textual description)? I use Visual C++ 6.0 and #import to
> generate smart pointers/wrappers for the COM interfaces. So the methods
> throw com_error exceptions when something goes wrong, but the ErrorMessage()
> method returns the generic "Unknown error" message.

> I read through documentation that com_error implementation uses
> FormatMessage to find that string. I noticed it takes a HMODULE handle to
> know where to look for the message table, but the com_error implementation
> doesn't use it. I believe that I have to manually load the library to obtain
> the HMODULE and call FormatMessage myself? This is not a nice solution, as I
> don't know at run-time what DLL is loaded for MSSOAP, as the COM subsystem
> does that, through the registry (of course I can find out its name, but
> still, it's not a nice way to deal with this..)

> How could I do find that textual error description?

> Thanks in advance,
> iuli



Tue, 24 May 2005 05:17:24 GMT  
 custom HRESULT decoding to error message
If you checked "Support ISupportErrorInfo" in your object, you can simply
call AtlReportError() and it will take a handle to the HINSTANCE of the dll
(_Module.GetResourceHandle()) and the ID of the string in the string table.
Set up your custom HRESULT errors via a #define E_WHATEVER
MAKE_HRESULT(...).  Now if implemented correctly, whenever VB or some other
client runs your code and a custom HRESULT error is returned, the text in
your string table will show up in the message box.


Unlike WIn32 errors, HRESULTs are not associated with text
messages. You can produce a message DLL, but that's not
standard behavior (most clients won't expect to find it).
Instead, in COM you can use rich exception information
which is passed per method (there's no strong relation
between the HRESULT and the returned text, just casual
relation about both being returned by the same call).
Then you'd use the Description property of the _com_error
object in your client. The ErrorMessage property is only
useful for standard HRESULTs. The object must also
implement ISupportErrorInfo to advertize the fact it
produces rich exception information.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Hi list!

> I use a COM object (from the SOAP SDK 3.0) which returns custom HRESULTs
> when errors occur. How can I decode these HRESULTs to their string
> equivalent (textual description)? I use Visual C++ 6.0 and #import to
> generate smart pointers/wrappers for the COM interfaces. So the methods
> throw com_error exceptions when something goes wrong, but the
ErrorMessage()
> method returns the generic "Unknown error" message.

> I read through documentation that com_error implementation uses
> FormatMessage to find that string. I noticed it takes a HMODULE handle to
> know where to look for the message table, but the com_error implementation
> doesn't use it. I believe that I have to manually load the library to
obtain
> the HMODULE and call FormatMessage myself? This is not a nice solution, as
I
> don't know at run-time what DLL is loaded for MSSOAP, as the COM subsystem
> does that, through the registry (of course I can find out its name, but
> still, it's not a nice way to deal with this..)

> How could I do find that textual error description?

> Thanks in advance,
> iuli



Sat, 28 May 2005 03:45:09 GMT  
 custom HRESULT decoding to error message
Thank you for your answer. But...

Well... ok, I can do that when the time comes and I will write my own SOAP
Toolkit.:-) Until then, I have to use Microsoft's toolkit, and they DON'T
provide IErrorInfo objects, _only_ custom HRESULTs. I know they have a
textual description, probabily as some custom resource (I heard there is a
message compiler also), the question was.. "how can I find it?"

Thanks,
Iuli


Unlike WIn32 errors, HRESULTs are not associated with text
messages. You can produce a message DLL, but that's not
standard behavior (most clients won't expect to find it).
Instead, in COM you can use rich exception information
which is passed per method (there's no strong relation
between the HRESULT and the returned text, just casual
relation about both being returned by the same call).
Then you'd use the Description property of the _com_error
object in your client. The ErrorMessage property is only
useful for standard HRESULTs. The object must also
implement ISupportErrorInfo to advertize the fact it
produces rich exception information.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Hi list!

> I use a COM object (from the SOAP SDK 3.0) which returns custom HRESULTs
> when errors occur. How can I decode these HRESULTs to their string
> equivalent (textual description)? I use Visual C++ 6.0 and #import to
> generate smart pointers/wrappers for the COM interfaces. So the methods
> throw com_error exceptions when something goes wrong, but the
ErrorMessage()
> method returns the generic "Unknown error" message.

> I read through documentation that com_error implementation uses
> FormatMessage to find that string. I noticed it takes a HMODULE handle to
> know where to look for the message table, but the com_error implementation
> doesn't use it. I believe that I have to manually load the library to
obtain
> the HMODULE and call FormatMessage myself? This is not a nice solution, as
I
> don't know at run-time what DLL is loaded for MSSOAP, as the COM subsystem
> does that, through the registry (of course I can find out its name, but
> still, it's not a nice way to deal with this..)

> How could I do find that textual error description?

> Thanks in advance,
> iuli



Sun, 29 May 2005 21:25:40 GMT  
 custom HRESULT decoding to error message
See the article

MC: Message Compiler Sample

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> Thank you for your answer. But...

> Well... ok, I can do that when the time comes and I will write my own SOAP
> Toolkit.:-) Until then, I have to use Microsoft's toolkit, and they DON'T
> provide IErrorInfo objects, _only_ custom HRESULTs. I know they have a
> textual description, probabily as some custom resource (I heard there is a
> message compiler also), the question was.. "how can I find it?"

> Thanks,
> Iuli



> Unlike WIn32 errors, HRESULTs are not associated with text
> messages. You can produce a message DLL, but that's not
> standard behavior (most clients won't expect to find it).
> Instead, in COM you can use rich exception information
> which is passed per method (there's no strong relation
> between the HRESULT and the returned text, just casual
> relation about both being returned by the same call).
> Then you'd use the Description property of the _com_error
> object in your client. The ErrorMessage property is only
> useful for standard HRESULTs. The object must also
> implement ISupportErrorInfo to advertize the fact it
> produces rich exception information.

> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD

> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================



> > Hi list!

> > I use a COM object (from the SOAP SDK 3.0) which returns custom HRESULTs
> > when errors occur. How can I decode these HRESULTs to their string
> > equivalent (textual description)? I use Visual C++ 6.0 and #import to
> > generate smart pointers/wrappers for the COM interfaces. So the methods
> > throw com_error exceptions when something goes wrong, but the
> ErrorMessage()
> > method returns the generic "Unknown error" message.

> > I read through documentation that com_error implementation uses
> > FormatMessage to find that string. I noticed it takes a HMODULE handle to
> > know where to look for the message table, but the com_error implementation
> > doesn't use it. I believe that I have to manually load the library to
> obtain
> > the HMODULE and call FormatMessage myself? This is not a nice solution, as
> I
> > don't know at run-time what DLL is loaded for MSSOAP, as the COM subsystem
> > does that, through the registry (of course I can find out its name, but
> > still, it's not a nice way to deal with this..)

> > How could I do find that textual error description?

> > Thanks in advance,
> > iuli



Mon, 30 May 2005 03:21:18 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. how to get the error message through a HRESULT

2. Quick question on custom error messages w/ Error() macro

3. Unable to add custom C# control to a form - Exception from HRESULT: 0x80131019

4. custom HRESULT in MSSOAP toolkit revisited.

5. Custom HRESULTs question.

6. Custom HRESULTs

7. Custom HRESULTS

8. problem with custom HRESULTS

9. How to get message from HRESULT?

10. A simple program to decode BASE64-encoded messages?

11. questions on getting and decoding message by Serial Communication

12. How to add custom window message handler to MESSAGE MAP

 

 
Powered by phpBB® Forum Software