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 2005

Tip: Looking for answers? Try searching our database.

MFC calling .NET component. Get Error Message

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Anthony Yott - 20 Oct 2005 16:58 GMT
Folks,

Quick question. I've created a .NET library component that will be used by
some of my MFC C++ customers by making the .NET component COMVisible (ie I
will create the .NET Component in C++ as a COM object). I'm creating a simple
MFC Dialong application to test the component. Everything works great except
for one thing.
In the static constructor of the .NET component I throw a
System.ApplicationException if a certain condition is not met e.g.,

//--- DOTNET CODE
static MyCustomComponent()
{
   if (!condition)
       throw new System.ApplicationException("Condition Not Met");
}

Here is the C++ code that instantiates the component

//--- C++
CoInitialize(NULL);
MyCustomComponent::ICompnentPtr m_pComponent;
HRESULT hr = m_pComponent.CreateInstance("MyCustomComponent.Component");

If the the condition above is not met in the static constructor then the hr
variable in the C++ code comes
back as 0x80040154 Class not registered. This seems normal but my question
is this. Is there any way to
extract the error message from my exception? I would like to display the
error message "Condition Not Met"
as opposed to having to create this in the C++ application.

Can anyone help me with this?

Thanks in advance,
Anthony Yott
Robert Jordan - 20 Oct 2005 17:26 GMT
Anthony,

> Quick question. I've created a .NET library component that will be used by
> some of my MFC C++ customers by making the .NET component COMVisible (ie I
[quoted text clipped - 27 lines]
>
> Can anyone help me with this?

Since you're preventing the instantiation of the COM object,
there is no way to deliver another exception then
"Class not registered".

If you still want custom exceptions, you have to approve the
instantiation and throw the exception whenever a menber of the
COM object is invoked.

Rob
Anthony Yott - 20 Oct 2005 17:36 GMT
Thank you Robert that is what I was afraid of.
Signature

Anthony Yott

> Anthony,
>
[quoted text clipped - 39 lines]
>
> 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.