Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a tool that generates P/Invoke signatures for arbitrary unmanaged DLL?

I stumbled upon a tool that generates P/Invoke signatures for Microsoft's own unmanaged DLLs: PInvoke Interop Assistant

Is there a similar tool that will generate P/Invoke signatures for third-party unmanaged DLLs?

Alternately, any way to feed a third-party DLL to PInvoke Interop Assistant

EDIT: Actual issue I am trying to resolve

like image 243
GregC Avatar asked Jun 12 '11 01:06

GregC


2 Answers

Google quickly found http://www.pinvoker.com/ (Compatiblity listed as VS2005, 2008, and 2010; it doesn't seem to have been updated to work with newer versions)

Microsoft's C++/CLI compiler can also do this, if you use /clr:safe and #include the header file, it will generate p/invoke code which you can extract with e.g. ILSpy (free) or Red Gate Reflector (used to be free).

like image 108
Ben Voigt Avatar answered Sep 18 '22 23:09

Ben Voigt


I use PInvoke Interop Assistant for unmanaged DLLs by using the third tab in the UI, marked "SigImp Translate Snippet". Simply copy-and-paste your header into the "Native Code Snippet" window and press Generate (or turn on Auto Generate). As an illustration here's some code from a question of mine. Note that for some reason errors don't appear in the Error panel but as comments at the top of the generated code.

As several people have already said, the generated code should be used as a guide - you may well have to make changes to get exactly what you want.

enter image description here

like image 26
parsley72 Avatar answered Sep 18 '22 23:09

parsley72