Using Managed and Unmanaged C++ DLLs in Your .NET Programs

Dynamic library linkage and use is simple using managed extensions for C++ under .NET. C++ DLLs compiled to IL, like their native .NET language counterparts, are tagged with metadata that provides the calling program information about the classes and methods stored in the DLL. This means that you can use them just like ordinary .NET objects written in C# or VB.

Other DLLs that you might use, such as the system DLLs or those you create, require a little more work but are still straightforward thanks to the Interop services provided by the Common Language Runtime.

Listing 1.4.11 shows a managed C++ component that will be compiled as a DLL.

Listing 1.4.11. cppdll.cpp: A Simple Managed C++ ...

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.