Groups | Blog | Home
all groups > dotnet interop > october 2004 >

dotnet interop : Access to C# functions or classes from unmanaged C++


Clement
10/5/2004 8:43:43 PM
I have made a dll in unmanaged C++ code using Visual Studio.Net 2003. I
would like to access C# functions or class methods from this dll. The C#
code would be in an other dll.

Typically, the C++ code does shell interaction, while the C# part is a
GUI and a web services client. The functions or methods will be called
to have a form displayed, or to get an integer value.

I have tried to use References, without success. I suppose this is to be
used with manages C++ code only, and anyway I couldn't have it working.

An other solution is probably to create a COM class in C# and access it
from C++, but once more I couldn't have anything working.

Do you have any ideas or suggestions ? Any code sample would be welcome.

--
Luis Abreu
10/5/2004 10:41:13 PM
Hello. have you thought about pinvoke? or is this not possible? take a
look at this:

http://www.codeguru.com/Cpp/COM-Tech/complus/managed/article.php/c3947/

--
---
Regards,
Luis Abreu
http://weblogs.pontonetpt.com/luisabreu
http://www.pontonetpt.com

[quoted text, click to view]

Clement
10/7/2004 10:11:41 PM
[quoted text, click to view]
Well, my goal is to access C# functions from C++ code, while pInvoke
seems to be made to access c++ code (in dll) from .NET (c#) applications.

But I could achieve my goal using COM finally. I had previously not
tried to use the tlb files (using #import directive), which seem to be
the easiest way to use COM classes from C++.

Thanks for the help anyway.

--
Luis Abreu
10/9/2004 12:32:19 AM
Hello Clement.

Sorry...I didn't understand what you really wnated on the 1st post. However,
in your case, there's another solution which is documented on this article:

http://www.codeproject.com/dotnet/bridge.asp

I think that this approach is more eficient that wrapping the objects in
COM. hope it helps.

--
---
Regards,
Luis Abreu
http://weblogs.pontonetpt.com/luisabreu
http://www.pontonetpt.com


[quoted text, click to view]

Luis Abreu
10/9/2004 11:57:01 AM
oh, another thing? if want to call them from unmanaged code, why don't you
build a mixed (i think that this is the right name) c++ component (one that
has support for .net)?

--
---
Regards,
Luis Abreu
http://weblogs.pontonetpt.com/luisabreu
http://www.pontonetpt.com

[quoted text, click to view]

AddThis Social Bookmark Button