P/Invoke Interop Assistant [Justin Van Patten]

P/Invoke Interop Assistant [Justin Van Patten]

  • Comments 10

The Interop team recently released a new tool called the P/Invoke Interop Assistant.  This tool automatically generates managed p/invoke declarations (in C# or VB) from native signatures.  It includes a quick look-up for the common Win32 libraries and lets you generate p/invoke declarations for any other native library simply by passing it the native signature.  This makes it a lot easier to do interop correctly, without having to understand all the rules and attributes used when marshalling between unmanaged and managed.

Here's a screenshot of the tool in action.  Simply type in the name of a Win32 API, in this case CreateFile, and the tool will generate the correct p/invoke declaration.

P/Invoke Interop Assistant

The tool was first released as part of an MSDN Magazine article on Marshaling between Managed and Unmanaged Code back in January.  Now it's on CodePlex along with the source code.  I highly recommend checking it out.

  • Is there an effort at MS to examine all the p/Invokes that people are using? To include some of that in the BCL I mean. Mono had a tool like that, it basically analyzes source code looking for "stuff" that's missing in either Mono or Linux/OSX/whatever (P/Invokes).

  • A efficient tool, but the signature is very detailed. For example, the 'InAttribute', it is really inform it? But, 'LPWStrAttribute', is a good idea, inform it explicitly, to avoid problems :-)

  • Ask the Directory Services Team : Custom Certificate Request in Windows Vista Microsoft Security Development

  • The http://pinvoke.net/ wiki is another great place to get interop signatures.

  • Shouldn't Create file return a SafeFileHandle instead of an IntPtr?

  • Staffan,

    Ideally yes. Right now the tool just automatically translates unmanaged code into the managed interop definitions.  There's no way to figure out from the unmanaged API alone what kind of SafeHandle to use or what API to call to close the handle.  It'd be trivial to implement if there was a map of functions, parameter positions, and which function to close with.  The team is considering enabling this with a plugin which could do just that based on an input file.

    Thanks,

    Justin

  • Since today I'm putting my blog reading in day, here's another post announcing what seems to

  • Since today I'm putting my blog reading in day, here's another post announcing what seems to

  • Looks like a fabulous tool. Could I suggest that the team reaches out to http://pinvoke.net to ask them to advertise it on their front page as well? I know they already have a plugin there, but choice is a good thing...

  • It would be nice to have the same for COM Interop.

Page 1 of 1 (10 items)