|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Interoperability Overview (C# Programming Guide)
Tools and techniques for interoperating between C# managed code and unmanaged code include Platform Invoke services and .NET Framework and COM interoperability tools.
Platform invoke locates and calls unmanaged code as an exported function.It also marshals the call's arguments, such as input and output parameters, integers, strings, arrays, and structures, as needed. For more information, seeand .
Tools for Interoperability between the.NET Framework and COM
For calling COM APIs from managed code, usewhich takes a type library as input and outputs a .NET Framework assembly and associated managed metadata. You can then add this generated, .NET Framework assembly to your Visual Studio project as a Project Reference. For example, use
TlbImp comlibrary.dll /out: comlnetibrary.dlland add a reference to
comlnetibrary.dllin your project For more information, see and Calling COM Components from .NET Clients.
For calling managed code from COM, use, which takes a managed assembly as input, and generates a type library containing COM definitions of all the public types defined in that assembly.
For calling managed components from COM clients, use, which reads the metadata within a .NET Framework assembly, and adds the registry entries so that COM clients can create managed classes.
For calling ActiveX controls, use, which takes an ActiveX control’s type library as input and generates a wrapper control that allows the control to be hosted in Windows Forms. For example,
Aximp activex.ocxcreates two files,
Axactivex.dll, and you can use as a project reference the auto-generated
To use the tools above such as registering a managed assembly for COM interop, you must have administrator or a power user security permissions. For more information, see .NET Framework Security.
Interoperability Examples and Techniques
For more information, see. For more information on techniques for interoperability, please see: