Calling Custom .NET DLLs from Your Managed C++ Code

Managed C++ uses .NET DLLs whenever it imports runtime elements such as MSCORLIB.DLL with the #using statement. It is also useful to be able to implement a portion of your code in managed C++ and a portion in C# or VB. This means that you will have to import and use your own custom DLLs. The process is simple and is described in this section.

First we'll create a C# DLL that we can import and invoke. Listing 1.4.9 shows a very simple DLL that has one class and one method.

Listing 1.4.9. mydll.cs: A Simple C# DLL
using System;

namespace mydll {

public class myclass
{
    public void MyMethod()
    {
        Console.WriteLine("MyMethod invoked!!!");
    }
}
}

You don't have to be a C# expert to see how this works. ...

Get C# and the .NET Framework: The C++ Perspective now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.