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.  http://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:

pinvoke

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

kick it on DotNetKicks.com

Published 28 March 08 10:40 by Tom

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# DotNetKicks.com said on March 28, 2008 10:41 AM:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# rkpatrick said on March 28, 2008 12:14 PM:

There's also an MS tool for generating signatures:

http://blogs.msdn.com/jaredpar/archive/2008/03/14/making-pinvoke-easy.aspx

# Tom said on March 28, 2008 1:00 PM:

That is a great tool.  If anyone has others that can help, feel free to post them as well.

# Granville Barnett said on March 28, 2008 1:52 PM:

In those scenarios C++/CLI is your friend :-)

Nice tool by rkpatrick :-)

# gOODiDEA.NET said on March 29, 2008 9:43 AM:

Web: markItUp! - Lightweight Text Editor CSS Message Box collection Absolute Positioning inside of a

# gOODiDEA said on March 29, 2008 9:44 AM:

Web:markItUp!-LightweightTextEditorCSSMessageBoxcollectionAbsolutePositioninginside...

# Josh Coswell said on March 29, 2008 7:43 PM:

Thanks for great pointers.

Josh Coswell

http://riverasp.net

Leave a Comment

(required) 
(optional)
(required) 

Search

Go

This Blog

Syndication

Page view tracker