ASP.NET Tips: Finding the layout of functions and structs for pinvoke
So when you start working with .NET a lot, you will find out quickly that there are some things that you just can't do in .NET and you will need to drop back down to the Win32 API to do something. When you need to do that, you pinvoke the function that you need to call, setting up the various parameters to pass to it. This can get very tricky to setup, while some things are easy to transfer, strings for example, others are much harder.
Fortunately, there is a solution. https://www.pinvoke.net/. This site does a great job of listing virtually any command you may want to call, you can find them by which DLL they are in, or searching for it. It will then give you the signature of what it should look like. For example, if you want to use the OSVERSIONINFO struct:
You will notice that the site gives both C# and VB code examples. It also sometimes gives a code example of how to use the structures or functions. This is a great resource for anyone that needs to call the Win32 API. There is even an add-in for Visual Studio 2003 and 2005 that you can install. Download the PInvoke.net Add-in here
Comments
Anonymous
March 28, 2008
You've been kicked (a good thing) - Trackback from DotNetKicks.comAnonymous
March 28, 2008
There's also an MS tool for generating signatures: http://blogs.msdn.com/jaredpar/archive/2008/03/14/making-pinvoke-easy.aspxAnonymous
March 28, 2008
That is a great tool. If anyone has others that can help, feel free to post them as well.Anonymous
March 28, 2008
In those scenarios C++/CLI is your friend :-) Nice tool by rkpatrick :-)Anonymous
March 29, 2008
The comment has been removedAnonymous
March 29, 2008
Web:markItUp!-LightweightTextEditorCSSMessageBoxcollectionAbsolutePositioninginside...Anonymous
March 29, 2008
Thanks for great pointers. Josh Coswell http://riverasp.net