Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2004

Tip: Looking for answers? Try searching our database.

Unmanaged C++ exception text not accessible in C# ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RussC - 16 Oct 2004 00:53 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.