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