views:

170

answers:

3

I have some c headers, and a c lib that I'd like to import and use in a c# project. How can I do this?

+4  A: 

Use [System.Runtime.InteropServices.DllImport] attribute (P/Invoke):

[DllImport("dllname.dll")]
static extern void MyFunctionName();
Mehrdad Afshari
I don't have a dll, just a lib, and a few headers
Malfist
You'll need to build that lib into a dll then. You can't link the lib directly into your C# program that I'm aware of.
Joel Coehoorn
Can't you create a DLL from the lib in C? It's not possible to call static C libraries directly. You might also take a look at C++/CLI in that case.
Mehrdad Afshari
I don't know, I didn't compile it. I suppose I could, and see what happens.
Malfist
You may have to wrap it up in a dll.
ojblass
+2  A: 

What Mehrdad said.

Additionally, welcome to the wonderful world of marshalling. P/Invoke.Net is your new best friend.

Joel Coehoorn