470,630 Members | 1,637 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,630 developers. It's quick & easy.

Catching a C# COMException in VC++ 6

In case someone knows off the top....

I am accessing a COM-interface-exposing C# dll in VC++ 6. The C# disp
method can throw a COMException.

Do I catch a _com_error ? It's not obvious from the docs.

TIA,
Mike
Sep 3 '08 #1
1 2068
Hi Mike,
In case someone knows off the top....

I am accessing a COM-interface-exposing C# dll in VC++ 6. The C# disp
method can throw a COMException.

Do I catch a _com_error ? It's not obvious from the docs.
That depends on how your VC++ 6 code looks like.

COM itself when it comes down to calling methods on interfaces uses
HRESULTs (32 bit numbers) to return error information. There are
"extensions" like IErrorInfo or EXCEPINFO which you can lookup
if you want.

The language you use COM in might add/integrate its error handling
concepts.

In VC++ you can use #import "typelib/progid/clsid" to auto generate
tli/tlh pairs where HRESULT can be translated to C++ exceptions
based on _com_error. You should catch(_com_error& ex) in this case.
Please recognize the & to avoid the creation of temporary copies of
the thrown object instance.

If you use the MFC class wizard to create COM client wrapper classes,
it uses another concept of giving you error information. I didn't use it
for ages, so I do not know anymore if they gave you the HRESULT or
did also encapsulate the error in some MFC COM error class.

--
SvenC
Sep 3 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Damaji Jambhale | last post: by
2 posts views Thread by Alex Vinokur | last post: by
3 posts views Thread by Jay A. Moritz | last post: by
2 posts views Thread by Eric Lilja | last post: by
5 posts views Thread by cj | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.