tags:

views:

190

answers:

5

Hi, 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!

+5  A: 

It will depend upon your target application. If you are writing Win32 app, then C++ may be wise choice. If you are developing a reusable library in .NET chose C#.

stackunderflow
A: 

When you say C++ are you referring to the Standard C++ or the "Managed" version?

If you are referring to the latter then you are no worse off than writing in C# as Managed C++ is an alternative .NET language, and actually I think you have more functionality available, although it is not as simple a language to write in as C#.

CashCow
A: 

Pros and cons dont change for a library if you mean managed c++. But for the coding, ease of use and available libraries matters. I would suggest c# since you say you are newbie. Its much more easy and you have LOTS of sources online. But if you plan to use some native code and need CLR support then c++ is the only choice.

Good luck

Ali YILDIRIM
Thank you very much for Suggestions Ali!
Swanand Purankar
+7  A: 

A DLL is best written in C :)

Let me explain:

The concept of DLL's was created when ther was no today's C++. It was created for C. 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

Armen Tsirunyan
You can also write COM objects in C++ (with or without ATL) and stay portable. But this is a total pain in the ***... Good advice btw.
Alexandre C.
@Alexandre: Good point, only I guessed that since the OP is new to Dll'l it's possible he has no idea what COM is :)
Armen Tsirunyan
A: 

its depend on ur application, but C# is better in general, because u can make it com visible DLL when u want and then u can use it in other applications(with other languages), but if u want do same thing with VC++ u should create ATL object and it is more difficult, also working with C++ is more harder than c#.

SaeedAlg