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 / November 2005

Tip: Looking for answers? Try searching our database.

Catch unmanaged C++ exception in managed code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kappa007@hotmail.com - 10 Nov 2005 14:02 GMT
Hi all,

I got following scenario here:

Unmanaged static lib (c++) which throws exceptions (e.g. throw new
MyExceptionClass(...))
Managed C++ dll which uses that lib
Managed application (C#) which loads that dll

Now I want to catch those exceptions from the unmanaged lib in my
application, but preserve the description/info set in my unmanaged
code.
Problem is all I get is a managed SEHException.

I've got no clue about COM and stuff but I found setting the exception
type would work by returning a specific HRESULT.
But how do I set that "rich" (custom) error information?
I read something about implementing IErrorInfo and ISupportErrorInfo
but no idea how I would implement that in my scenario.

Some hints/samples would be appreciated.

Regards,
Dirk
Mattias Sjögren - 10 Nov 2005 18:52 GMT
>Now I want to catch those exceptions from the unmanaged lib in my
>application, but preserve the description/info set in my unmanaged
>code.

C# knows nothing about native C++ exception classes (such as
MyExceptionClass). To get anything useful from it you'd have to catch
it in your C++ code and throw a managed exception instead.

>I read something about implementing IErrorInfo and ISupportErrorInfo
>but no idea how I would implement that in my scenario.

Those interfaces are part of the COM error support. But since you're
not calling the C++ code through COM interop it's not really relevant
here.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


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.