Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming Language for Creating DLL: C++ or C#

Tags:

c++

c#

dll

This is NOT a Programming doubt!

I am going to write a DLL for some application. I have two options to choose from: C++ or C# In which language I should write DLL?

Does that affects functionality?

I am a completely newbie and Unaware of both C++ and C# (but Some Small programs in C#).

What are Pros and Cons about Writting DLL in C++ or C#?

Thank You very much for your time!

Regards, Swanand!

like image 386
Swanand Avatar asked Oct 13 '10 07:10

Swanand


1 Answers

A DLL is best written in C :)

Let me explain:

DLL's were conceived before C++ came into mainstream use. They were created for the C language. You can write DLL's with C++ but you'll be able to easily use them only from applications that were written with the same version of the same compiler as the DLL. A C DLL can be used from .NET, unlike C++ (yeah, I know, technically it can, but it is a pain in the buttocks).

If you create DLL with C#(or any other .NET language), it's a completely other thing - it's not a windows DLL, it's just a .Net assembly without an entry point(Main), so it can be used from other .NET assemblies by referencing the DLL.

To summarize:

  1. If you need to use your DLL from .NET languages - write it in C#, it won't be a windows dll, just an assembly. Very easy to use.

  2. If you need to use your DLL from ONLY C++ and ONLY from applications written by the same compiler, write in C++. Not portable, easy to use.

  3. If you want to create a general-purpose library that can be used from .NET, C, C++ and regardless of the compiler, use C, or C++ freestanding functions marked as extern "C" and having C-like parameters, like pointers and POD's.

HTH

like image 89
Armen Tsirunyan Avatar answered Sep 29 '22 19:09

Armen Tsirunyan