Link to home
Start Free TrialLog in
Avatar of Ahmet Ekrem SABAN
Ahmet Ekrem SABANFlag for Austria

asked on

How to integrate a C#-Class into a C++-Kode in a CLR project?

Hello!

I have a Windows Frames project written in C#. Now, for demonstration purposes, I have to write a code in C++, all in .NET Framework 4.0 with Microsoft Visual Studio 2010. I have several years of experience in C/S application, partly written in C/C++, but the WinForms project is my first .NET project and with C#.

To go on faster, it would be nice to use some C# classes that I have already written, like Constants, DAOs, etc., in the demo project. I found out that it is possible to have both C++ and C# code in a CLR project, but I do not know how I can access a C# class directly from a C++ class.

Question
How can I access a C# class from C++ code in a CLR project? If a DLL is the solution, how can I create a DLL out of the C# classes?
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ahmet Ekrem SABAN

ASKER

Worked immediately and with a nice tutorial. Thank you so much!
But one problem remains: I cannot import the DLL to the C++ CLR project. Then, I tried it with a Win32-console project, but there is also the problem that I cannot call from C++ the classes and their method from the DLL. This is not explained in your link, as the project calling the DLL is a C# project. Somehow, there is a "missing link" - some header file or something else is required.
Yes, that is unexpected problem. I'll try to look at it and let you know if I find something. Sorry about it.