Ahmet Ekrem SABAN
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?
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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.
check here maybe ther is something useful:
http://stackoverflow.com/questions/728325/can-you-call-a-c-dll-from-a-c-dll
ASKER