What's the "right" way to get Win32 p/Invoke declarations?
I typically use the site http://www.pinvoke.net/ to grab a 开发者_Go百科DllImport
declaration whenever I need to call a Win32 API, and I've noticed it's the de facto standard response on Stack Overflow to API interop questions.
Is this what "everyone" does? Is there a better way? Does Microsoft offer an alternative? e.g. a tool that reads .h files and outputs an assembly.
Why aren't there some standard assemblies that just expose all the Win32 APIs? What would be the barrier to creating them and using them, as an alternative to a site like pinvoke.net?
I use pinvoke.net as a first resort for Win32 APIs that don't have managed wrappers already. There is an interop assistant project on codeplex that will generate the DllImport for you - for Win32 API or your own code. I blogged about it when it came out, back in 2008. Your other question about "standard assemblies" probably means what I call wrappers. There are specific ones for specific parts of the huge body that is the windows API. For example, many of the Windows 7 and Vista goodies are in the Code Pack.
精彩评论