I am adding a "plug-in" mechanism to an existing C# application. The
plug-ins are to be customer-written COM objects, dynamically loaded by my C#
host code. I am able to load and talk to a few different sample plugins
knowing only the ProgID. I made a sample C# plugin and a sample VB6 plugin
and a sample C++/ATL (C7) plug in so far and they all work fine except for
one glitch. It would be nice for the methods in the plug-in to be able to
throw exceptions (including nice descriptive text) back to the C# caller when
warranted. I can throw exceptions from the C# and VB6 plugins just fine, and
the exception message text is accessible in my C# catch block. However, when
I throw a char* exception from the C++/ATL plugin, I can't seem to access the
exception text. As an experiment I enabled managed extensions in the the
C++/ATL COM project and threw a System::Exception. I can catch that in the
C# code and see the exception message text OK. I am not sure if I can get
away with telling my customers that they must use managed C++ if they want to
use C++ to make a plugin for our program. It would be nice if I could get
exception message text to work from unmanaged C++ back to C#. Should that be
possible? When caught, it looks like a SEHException when I use unmanaged
C++. When I change to managed C++, it looks like a System.Exception wrapped
in a TargetInvocationException.
The C# catch block:
catch(Exception x)
{
string z = "Error calling CapExpSendDocumentBuffer";
z += "\r\n\r\n";
z = z + x.InnerException.Message;
z += "\r\n\r\n";
z += x.InnerException.StackTrace;
this.label1.Text = z;
err = true;
}
The unmanaged C++ exception throw:
throw "this is a test of the emergency broadcast system";
Robert Jordan - 16 Oct 2004 13:11 GMT
Hi,
> [... ] It would be nice if I could get
> exception message text to work from unmanaged C++ back to C#. Should that be
> possible? When caught, it looks like a SEHException when I use unmanaged
> C++. When I change to managed C++, it looks like a System.Exception wrapped
> in a TargetInvocationException.
You COM objects must implement ISupportErrorInfo.
bye
Rob
RussC - 18 Oct 2004 22:33 GMT
Thanks, Rob! That is exactly what I needed.
Russ
> You COM objects must implement ISupportErrorInfo.
>
> bye
> Rob