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

Posted on 2011-10-04
Last Modified: 2013-12-14

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?
Question by:sae1962at
    LVL 47

    Accepted Solution


    This tells how to create DLL from C# classes:
    LVL 1

    Author Closing Comment

    Worked immediately and with a nice tutorial. Thank you so much!
    LVL 1

    Author Comment

    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.
    LVL 47

    Expert Comment

    Yes, that is unexpected problem. I'll try to look at it and let you know if I find something. Sorry about it.
    LVL 47

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now