Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# .NET
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 27-Sep-12 3:20am
Comments
FlyingBird_ at 27-Sep-12 8:24am
   
u have no need to create dll..this dll automatically created by .net application in bin folder after built
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 Smile | :) .
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
H.Brydon at 12-Jul-13 15:32pm
   
Great answer. +5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

  Permalink  

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

  Print Answers RSS
0 CHill60 380
1 Sergey Alexandrovich Kryukov 245
2 Richard MacCutchan 152
3 CPallini 150
4 Peter Leow 150
0 Sergey Alexandrovich Kryukov 9,193
1 OriginalGriff 6,786
2 Peter Leow 4,332
3 Zoltán Zörgő 3,809
4 Richard MacCutchan 2,672


Advertise | Privacy | Mobile
Web02 | 2.8.150128.1 | Last Updated 21 Jan 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100