What is the difference between a DLL produced with C ++ and a C #

6

After some time searching, I did not find any results for this issue, the existing MSDN topics also did not return anything regarding the support of the 2 in Windows.

In short, the question is, what's the difference after compiling a DLL produced using C ++ and one produced with C #? As far as I get results, C ++ seems to run quietly on Windows without additional installations, since C # always needs .Net installed. Is this statement correct?

In addition, is it possible to use C # DLLs in C ++ and vice versa?

    
asked by anonymous 17.11.2015 / 12:20

1 answer

6

Your statement is partially correct. In fact, common DLLs (win32 / Com) need to be registered with the regsvr32 tool while in fact, you only need to add a C # DLL in the bin folder so that it can be used (and it can only be used used by .NET applications as you said). You can read more about this here: Difference between normal DLL and .Net DLL

You can use a C ++ DLL in .NET languages. For this Visual Studio creates an "interop" file for you. Basically a INTEROP file is an interface that allows you to access the resources of the DLL, that is, a wrapper to the DLL in which you will use the resources of the DLL without worrying about any conversion. This "interop" file is created because .NET languages need type description (only to be "understood" by the language). You can read more about it here: What is the interop dll?

The opposite is also valid. You can use a .NET DLL in a C ++ program. To do so, simply follow the tutorial provided by Microsoft : How to call a DLL from native Visual C ++ code in Visual Studio .NET or in Visual Studio 2005

Now answering the fundamental question. The difference, after compiled, between a C ++ DLL and a C # DLL is the format. The .NET DLL is partitioned into some sections:

  • PE header
  • CLR header
  • CLR metadata
  • CLR IL code
  • Native data

Each section is interpreted by the .NET language while the C ++ DLL does not have these sections. For this reason, it needs a wrapper as I mentioned earlier. These sections are described here: Inside .NET assemblies (part 1)

    
17.11.2015 / 12:52