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

后端 未结 6 1628
失恋的感觉
失恋的感觉 2020-12-13 00:17

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

相关标签:
6条回答
  • 2020-12-13 00:44

    This project is active and looks promising for the task: https://github.com/mono/CppSharp

    0 讨论(0)
  • 2020-12-13 00:49

    You can create C# wrapper for any native DLL including both C-style DLL exporting functions and C++ DLL exporting classes by using xInterop C++ .NET Bridge with .NET to Native C++ Bridge. It is available for free evaluation with some limitations.

    Disclaimer: I am the author of xInterop C++ .NET Bridge.

    0 讨论(0)
  • 2020-12-13 00:53

    Use Dumpbin.exe that comes with the VS SDK, Dumpbin, you'll still need to write the pinvoke signatures manually from the dumped data

    0 讨论(0)
  • 2020-12-13 01:00

    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

    0 讨论(0)
  • 2020-12-13 01:04

    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).

    0 讨论(0)
  • 2020-12-13 01:04

    Another alternative is the SharpGenTools. It is used by SharpDX to "automatically" create bindings of the directx api. There's also CppSharp, it's used by QtSharp to generate bindings to native C++/C libs. Until now CppSharp is only compatible with .Net Framework 6+.

    0 讨论(0)
提交回复
热议问题