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

Asked

Viewed 640 times

6

After some time searching, I did not find any results for this issue, the topics already existing in MSDN also returned nothing in relation to support of the 2 in Windows.

In summary, the question is, what is the difference after compiled from a DLL produced using C++ and one produced with C#? As far as I got results, the C++ seems to run smoothly on Windows without the need for additional installations, while the C# always needs the . Net installed. This statement is correct?

In addition, you can use DLL’s C# in C++ and vice versa?

1 answer

6


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

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

The opposite is also valid. You can use a DLL . NET in a C++ program. For this just follow this tutorial provided by Microsoft: How to call a Managed 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 DLL C++ and a DLL C# is the format. A DLL . NET is distributed in some sections:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.