Do you know a soft which automatically generates C# code (with [DllImport] attributes in .cs) from a native DLL in order to use this DLL in a C# code?
Asked
Active
Viewed 1.2k times
20
-
2most if not all of the standard mappings have already been done, you can check them out at http://www.pinvoke.net/ - they even have an add-in. – BrokenGlass Sep 22 '10 at 17:53
-
Does this answer your question? [Is there a tool that generates P/Invoke signatures for arbitrary unmanaged DLL?](https://stackoverflow.com/questions/6319650/is-there-a-tool-that-generates-p-invoke-signatures-for-arbitrary-unmanaged-dll) – StayOnTarget Jun 28 '21 at 20:37
1 Answers
16
Checkout the P/Invoke Interop Assistant:
In marshalling, there are a bunch of attributes and rules. Understanding all those attributes and rules seem a bit daunting. In order to make developing work more efficient and easier on those attributes and the rules, P/Invoke Interop Assistant comes out. It is a toolkit that helps developers to efficiently convert from C to managed P/Invoke signatures or verse visa. This is conceptually similar to TlbImp for COM Interop which generates managed proxy entry points based on some formal description of the unmanaged side but it works for P/Invoke. The toolkit was first released on MSDN Magazine website in Jan, 2008.website in Jan, 2008.

ctacke
- 66,480
- 18
- 94
- 155

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
-
-
2If you don't have source or at least .lib file, you have no way to know what parameters the DLL functions expect (if the declarations are stdcall, as they usually are) – Eugene Mayevski 'Callback Sep 22 '10 at 16:56
-
-
@Patrice, I am afraid you are out of luck then. I hope you have at least the documentation which will be helpful when manually generating the signatures. – Darin Dimitrov Sep 22 '10 at 17:05
-
@Patrice Pezillier - are you sure you don't have at least a header file for the DLL interface? – Steve Townsend Sep 22 '10 at 17:22
-
if I have header file .h and dll can I use P/Invoke Interop Assistant ? – Patrice Pezillier Sep 22 '10 at 18:52
-
2Yes it should work with a header file. Checkout [this blog post](http://blogs.microsoft.co.il/blogs/sasha/archive/2008/01/12/p-invoke-signature-generator.aspx). – Darin Dimitrov Sep 22 '10 at 18:56