Click here to Skip to main content
13,146,710 members (65,630 online)
Rate this:
 
Please Sign up or sign in to vote.
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 27-Sep-12 2:20am
Comments
FlyingBird_ 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 :) .
  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 12-Jul-13 15:32pm
   
Great answer. +5
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
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
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 21 Jan 2014
Copyright © CodeProject, 1999-2017
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