Groups | Blog | Home
all groups > dotnet interop > april 2006 >

dotnet interop : Invoking C# object from C++ DLL



Daniel F. Devine
4/13/2006 5:50:30 PM
I wish to provide a C++ DLL interface for non-framework clients to access a
C# DLL - is this possible? I have had some limited success by using a pimpl
idiom to cross from unmanaged to managed - but anything more than a simple
message output yields an exception. I cannot debug past the C++/C#
boundary.

I have put this question to Microsoft support and while they tell me that I
SHOULD be able to do this and I SHOULD be able to debug across the boundary
they cannot tell me how to do it although they have had my sample code for
two days now. Can anyone shed some light on this?

Thanks for any help.

Daniel F. Devine
4/14/2006 9:48:22 AM

[quoted text, click to view]

Thanks for the reply. Actually I can do this with COM but was looking for a
solution that avoided COM for deployment reasons. I am not sure if this can
be done BUT Microsoft Tech support ensures me that it can be done although
to date they have not shown me why my sample stub blows up with an
EEFileLoadException. There seems to be virtually no documentation on this
error that I can find. If it can't be done that would be most helpful to
know as I would stiop wasting my time and look for another solution.


Daniel F. Devine
4/14/2006 11:25:39 AM

[quoted text, click to view]

Sure - but first I'll psedocode it because even as a small testbed it is
somewhat complex

C++ DLL interface exposes invokeCrystal

invokeCrystal is in a C++ compilation unit - pure C++

ManagedReport *mr = new ManagedReport();

mr->ViewReport();

delete mr;

ManagedReport object is defined in a separate compilation unit compiled with
/clr

ViewReport()
{
ManagedCrystalObject ^mo = gcnew
ManagedCrystalObject
}

In the C# class ManagedCrystalObject a Winform hosting the Crystal Viewer is
to be displayed.


In the invocation of ViewReport I get the exception : EEFileLoadException
Also to note is that I cannot step into the managed code unit from the
unmanged code unit.

If you still need the code I will upload it.

Thanks for your responses

Dmytro Lapshyn [MVP]
4/14/2006 3:56:42 PM
Hi Daniel,

Consider making your C# class library COM-visible. I think all mainstream
programming languages are able to consume COM nowadays, and it's fairly easy
to do since COM visibility is supported by .NET Framework and SDK tools.

[quoted text, click to view]
Dmytro Lapshyn [MVP]
4/14/2006 5:59:48 PM
Can you please post your code that gives you the EEFileLoadException here?


[quoted text, click to view]
Dmytro Lapshyn [MVP]
4/17/2006 1:08:38 PM
Now I see you are using the IJW technology, and I don't have any experience
with this one :-(
What I can tell is: The EEFileLoadException error means that the CLR could
locate the assembly with the managed class, but couldn't load it for some
reason.

This link might help:

http://doc.trolltech.com/3.3/activeqt-dotnet.html

Also, do a Google search on IJW.

[quoted text, click to view]
Daniel F. Devine
4/17/2006 3:07:20 PM

[quoted text, click to view]

Thanks-

I am discovering that EEFileLoadException ALSO occurs when ANY error occurs
in the Managed class - a managed client debug session will yield the proper
exception in the Managed class - but when called from the Unmanaged class -
blindly, I cannot debug into it -any exception will trigger the
EEFileLoadException in the C++ class.


AddThis Social Bookmark Button