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


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.

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?
Ahmet Ekrem SABANSenior IT consultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


This tells how to create DLL from C# classes:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Worked immediately and with a nice tutorial. Thank you so much!
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.