Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use a DLL created using C# in an unmanaged VC++ application?

Tags:

c++

c#

dll

I have a DLL that I wrote in C# and I want to use it both with C# applications and applications written in unmanaged VC++. Is this possible?

like image 577
Matthew Bowen Avatar asked May 20 '10 12:05

Matthew Bowen


People also ask

Can a DLL be used in any language?

No. DLL is PL specific. In visual studio you have COM objects which can be used in other VS based PLs. You can use sockets with client and server topology to talk from one program to another program.

What language is a DLL file written in?

DLL files use languages like C or C++, although you'll see C++ more often. You can write your own DLLs to run some code you need if you're willing to learn how to do it. It could be valuable to your project and of course it could make you look good in return.

What is .DLL file in C?

In Windows, a dynamic-link library (DLL) is a kind of executable file that acts as a shared library of functions and resources. Dynamic linking is an operating system capability. It enables an executable to call functions or use resources stored in a separate file.


2 Answers

To supplement other answers here, here's the MS support article which describes your scenario.

http://support.microsoft.com/kb/828736

like image 61
Jason Evans Avatar answered Oct 12 '22 06:10

Jason Evans


Well, seems I have to bring up my unmanaged exports again. ;-)

Just answered a similar question 2 days ago. This totally works in C#, and it even creates a .lib & .exp file for your C# assembly to be consumed by C++:

internal class Sample
{
  [DllExport("_export_test", CallingConvention.Cdecl)]
  static int Test(int a)
  {
     return a + 1;
  }
}
like image 31
Robert Giesecke Avatar answered Oct 12 '22 06:10

Robert Giesecke