Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends,

I have a code of some functions written in c language.
i want to use that functions in my c# .net project,without writing that logic again in c# .net . can i make a dll of that c code and use it in my c# .net project ? if yes tell me the way . that c code are in four files two of .h and two of .c extension.i tried to make the dll by change the extension from .c to .cpp, and make a dll usin c++ in .net but it does't work . please suggest a way to do this .

Thankyou .
Posted
Comments
wings_ 27-Sep-12 8:24am    
u have no need to create dll..this dll automatically created by .net application in bin folder after built

In my opinion, you should compile the C-code to a valid Win32 DLL. This means, that the functions you want call must be prepared for this. ( I'm not an expert in C, but propably something like extern keyword ). This should be only a minor change to the actual code.

After that, you can use this DLL in your .NET projects. See this tutorial: http://msdn.microsoft.com/en-us/magazine/cc164123.aspx[^]

I hope, that my answer at leat a bit helpful :) .
 
Share this answer
 
You do not need to change the extension of the .c files in order to make a DLL. Take a look at this article[^] which explains how to create a simple DLL, and also the link that macika123[^] provided on how to use P/Invoke. Assuming that you have some version of Visual Studio or Visual C++ Express then you will find a template project for DLLs which you can use, just add your code into the relevant places.
 
Share this answer
 
Comments
H.Brydon 12-Jul-13 15:32pm    
Great answer. +5
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900