Search code examples
comcom-interop

Generating .net assemblies for c++ modules


I am a .net developer who has never touched c++. I don't want to either :)

Unfortunately, I have to work with c++ module in .net 4.0 and I am clueless.

Is there a tool that can generate a .net assembly for a given c++ module?

If not, what are my next steps to successfully call these c++ libraries?


Solution

  • There are many ways:

    COM Interop

    The Type Library Importer converts the type definitions found within a COM type library into equivalent definitions in a common language runtime assembly.

    PInvoke/DllImport

    The common language runtime provides Platform Invocation Services, or PInvoke, that enables managed code to call C-style functions in native dynamic-linked libraries (DLLs). The same data marshaling is used as for COM interoperability with the runtime and for the "It Just Works," or IJW, mechanism.

    C++/CLI

    This is more advanced because it will most probably require the C++ module to be updated and re-compiled.

    Mixed assemblies are capable of containing both unmanaged machine instructions and MSIL instructions. This allows them to call and be called by .NET components, while retaining compatibility with components that are entirely unmanaged. Using mixed assemblies, developers can author applications using a mixture of managed and unmanaged functionality. This makes mixed assemblies ideal for migrating existing Visual C++ applications to the .NET Platform.