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