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
2009-04-03 20:48:57
I don't have a dll, just a lib, and a few headers
Malfist
2009-04-03 20:51:24
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
2009-04-03 20:52:14
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
2009-04-03 20:52:48
I don't know, I didn't compile it. I suppose I could, and see what happens.
Malfist
2009-04-03 20:54:08
You may have to wrap it up in a dll.
ojblass
2009-04-03 21:15:19
+2
A:
What Mehrdad said.
Additionally, welcome to the wonderful world of marshalling. P/Invoke.Net is your new best friend.
Joel Coehoorn
2009-04-03 20:51:34