Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are different kinds of language interop supported by the .NET framework. First is the kind that Abel talks about, a .NET compiler must generate assemblies who's format is described in the CLI Specification. Standardized as <a href="http://www.ecma-international.org/publications/standards/Ecma-335.htm" rel="nofollow">Ecma-335</a> with strict descriptions of the metadata (type descriptions) and code (IL or Intermediate Language). Which makes interop easy to achieve, one language compiler can read the types of another and the .NET runtime makes them work together.</p> <p>But you are talking about C++, that's not a managed language. That requires interop with native code. That's not technically very difficult, after all the jitter generates native code as well. You just need a way to <em>describe</em> the native code so there's a reasonable chance of success. There are three different ways:</p> <ul> <li><p>You can declare <em>functions</em> written in native code with the [DllImport] attribute. That works for language runtimes that expose a C style calling interface. The Windows API is like that. This does <em>not</em> include C++, at least not when you take advantage of its support for classes.</p></li> <li><p>The CLR has good support for COM, the grand father of .NET and an early language interop standard implemented by Microsoft. Particularly the COM Automation subset works well, you can simply add a reference to the type library of a COM component and .NET tooling automatically generates the glue to expose the COM object model implemented by the component as managed types. Office interop works like that, as well as everything you find in the COM tab of the Add Reference dialog. That <em>may</em> work on code written in C++ although COM certainly doesn't require a COM component to be written in C++. VB6 and Delphi are notable languages that support COM well. And the other way around, you can easily expose .NET code as COM to other runtimes. The WinRT api, the one that lets you write Metro apps that run on Windows 8 is COM based at its core, although it is well hidden in the language projections.</p></li> <li><p>The ultimate interop tool and the one you need to use to make C++ code usable is the C++/CLI language. It is an extension built into the Microsoft C++ compiler that allows native C++ code to be compiled into IL and stored in an assembly. With the option to declare managed classes in a C++ style syntax, classes that are directly usable by managed code and that can create native C++ class objects and call their methods. Several parts of the .NET framework were built that way, notably mscorlib, System.Data and PresentationManager, chunks of code that have a strong dependency on native code to get their job done. Think of C++/CLI as the ultimate glue language.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload