Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a c# developer, want to use the library developed in ASCI C, which is having many folders with c, h and makefile. Can any one help me guide how to use this library from Visual Studio 2008
Posted

Use

[DllImport("your_functions.dll", CharSet = CharSet.Auto)]

You cannot because you can't statically link unmanaged code(c) into managed code(c#). You will have to write a .dll to wrap all your library functions in C++. Once you do, you can use C# interop functionality to call those functions from the dll.
 
Share this answer
 
Comments
Naina Dhande 28-May-14 0:53am    
Do I have to use PInvoke after creating the dll of the library. If so, How to start?
Here's an easier solution.

Create a C++/CLI project that links to your C library. This completely avoids P/Invokes and DllImport. Getting the DllImport declarations to match actual C functions can be a pain.

Define a namespace in the C++ project with public functions. You don't need to write any C++ classes - unless you want to do so.

The C++/CLI syntax is a little strange at first (lots of "^" hats) and intellisense does not work there.

Keep the C++/CLI later as thin as possible so that most of your debugging is in C# or in the C library.

When debugging, be sure to enable Mixed debugging to you can step through .NET and native code.
 
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