I have blogged about it already earlier, but now, when I needed it, I could not find it easily, so I decided to do a bit of “rehashing”…
MSDN Magazine Marshaling between Managed and Unmanaged Code article goes into deep details about marshalling and not only. The cool part: the article has a reference to the P/Invoke Interop Assistant GUI Tool that is handy for doing simple conversions. The tool is now available here, at the CodePlex.
The tool has three tabs: SigExp, SigImp Search, and SigImp Translate Snippet:
- SigExp converts managed signature to an unmanaged signature. It reflects over managed assemblies to find all P/Invoke declarations and COM imported types, and produces the corresponding native C signatures.
- SigImp Search and SigImp Translate Snippet convert unmanaged signatures to managed signatures. SigImp Search allows users to select a native type, procedure, or constant to perform the converstion from – it will display a list of supported types, methods, and constants collected from Windows SDK header files. SigImp Translate Snippet allows users to write their own native code snippet in the tool and then it will generate the managed code equivalent.
The snippet translators work well for small snippets of code, but if you need to translate a larger code base, you should use the command line version of the tool – sigimp.exe (included). It is designed to process several header files and produce a mass output.