Generate C# DLLImport declarations from a native dll

11,191

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.

Share:
11,191
Patrice Pezillier
Author by

Patrice Pezillier

Updated on June 04, 2022

Comments

  • Patrice Pezillier
    Patrice Pezillier about 2 years

    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?

  • Steve Townsend
    Steve Townsend almost 14 years
    As I read it, this will only work if you have the DLL source?
  • Eugene Mayevski 'Callback
    Eugene Mayevski 'Callback almost 14 years
    If 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)
  • Patrice Pezillier
    Patrice Pezillier almost 14 years
    I don't have source. I don't have .lib
  • Darin Dimitrov
    Darin Dimitrov almost 14 years
    @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.
  • Steve Townsend
    Steve Townsend almost 14 years
    @Patrice Pezillier - are you sure you don't have at least a header file for the DLL interface?
  • Patrice Pezillier
    Patrice Pezillier almost 14 years
    if I have header file .h and dll can I use P/Invoke Interop Assistant ?
  • Darin Dimitrov
    Darin Dimitrov almost 14 years
    Yes it should work with a header file. Checkout this blog post.