I\'ve got a library in C which I\'d like to use from C#.
From what I\'ve gleaned off the internet, one idea is to wrap it in a C++ dll, and DllImport that.
The only 'nasty' parameter is the function pointer. But luckily .NET handles them fairly well via delegates.
The only problem is with the calling convention. In C#, it only emits one type (iirc stdcall
), whereas the C code might expect cdecl
. The latter problem can be handled on an IL level though (or using Reflection.Emit
).
Here is some code that does it via Reflection.Emit
(this is to help understand what psuedo-attribute needs to be placed on the delegate's Invoke
method).