‘Introducing’ PINVOKE.NET and its Visual Studio Add-In!


I guess I’m not cut out to be a journalist.




Two weeks ago when I decided to spend my weekend creating the PINVOKE.NET wiki, I had a great opportunity to awaken my blog from its deep slumber by announcing it to the world.  But Ben, Brad, Brian, Charlie, Chris, Corrado, Darth, Duncan, Ivan, James, Jesse, Jim, Joe, Josh, Julia, Ken, Peter, Phil, Sam, Sean, Shawn, Ted, Yorai, and numerous other people beat me to it!




This past weekend I put the finishing touches on a Visual Studio add-in that communicates with PINVOKE.NET via a Web service and uploaded it to gotdotnet.com.  As I waited for it to appear, I knew that this was my second chance to have an exclusive scoop on my blog.  Lo and behold, Kevin, Kent, Josh, Girish, and Paul let the cat out of the bag before I did!




Don’t get me wrong… I’m flattered that so many people find this stuff blog-worthy!  Ever since preparing for PDC 2003 last September, I wanted to create such a site in order to help people with the PInvoke problem.  That’s when I reserved the pinvoke.net domain name.  But it wasn’t until an e-mail discussion on Thursday 4/15 about the difficulty of PInvoke that I put my foot down and was determined to get the site up and running by that Monday morning (4/19)!  That’s also when it dawned on me that the wiki approach was the way to make this happen fast.  I’m grateful that I stumbled across the great work the FlexWiki folks have done.




So thank you for all of your great comments on the site, in e-mail, and in your blogs.  It gives me hope that the site is starting to achieve its objective.  And thank you especially for your contributions to the wiki!  As a community we’ve expanded the site from 6 to 25 DLLs, with approximately 1,700 signatures & types, including hundreds of pages with sample code, alternative managed APIs, VB signatures, and other helpful information.  All this in just two and a half weeks!  I want to highlight Craig Ellis in particular, who contributed 54 functions and 8 structures all in one sitting!




Therefore, I’m not going to introduce the site.  If you’re somehow reading my blog but aren’t familiar with it, please visit http://www.pinvoke.net for more information.  And don’t worry, support for more browsers is still on my TODO list.  (Working on the site is reserved for my sparest of spare time!)




I do want to give a quick overview of what the Visual Studio add-in does, however.  After installing it from here, you’ll get two new menu items when right-clicking in source code:



The Insert PInvoke Signatures… option opens a dialog, shown here with the results for the MessageBeep API:



Once you type in a function name and press Enter, you can get a description, PInvoke signature(s), and an alternative managed API from the PINVOKE.NET web service.  If you want more information (such as sample code or structure definitions), you can click on the link at the bottom.




But ’tis better to give than to receive, right?  If you want an easy way to contribute to the PINVOKE.NET project, highlight some code and select the Contribute PInvoke Signatures and Types… option:



You’ll get the following dialog, which enables you to upload your content:



Let me know if you have any questions/comments, and enjoy!

Comments (79)

  1. jledgard says:

    I think the perfect next step would be an option to paste in the code snippets into the editor as well if they exist. Optionally I could also see people wanting to include the pinvoke.net or MSDN help URL above the signature/sample code as a comment. This is really cool stuff though.

  2. Kevin Dente says:

    Hey man, I think I had the original scoop on this one. 😉 Sorry, didn’t mean to burst your bubble. Awesome, awesome stuff, and badly needed.

  3. Adam Nathan says:

    Ah, I missed that, so I’ve added your name above. 🙂 Sorry about spoiling your contest idea!

  4. Kevin Dente says:

    You probably did me a favor. I didn’t have the web service to work with that your add-in has, so it was getting ugly anyway. I’m sure I can come up with another idea or two for add-ins. 😉

  5. David Levine says:

    Great tool, I wish I had it years ago. I’ve a couple of observations and questions …

    I browsed around looking at some of the APIs I have used and already spotted a few differences. Many are of the type where I used an int instead of a uint – small but perhaps significant – so it has already proved useful.

    Also, I noticed that the signatures I looked at did not decorate the methods with attributes, such as SetLastError = true etc. Do any of them? Should these be there?

    Is there a means of reporting differences, or starting a discussion about what the most appropriate signature should be? Should I just upload the signature I use and let someone (you?) sort it out?

    It would be nice if there was a downloadable database so offline developement could use this tool.

  6. Adam Nathan says:

    Thanks, David. Yes, there can be many ways to define a PInvoke signature, and they can be equally correct. For example:

    – Maybe you want to set PreserveSig=false in order to get exceptions instead of raw failure HRESULTs

    – Maybe you want to use SuppressUnmanagedCodeSecurity because you’ve ruled out the possibility of a luring attack

    – Maybe you can define the parameters differently because you’re using the API in a limited scenario

    The idea is that people should feel free to add additional versions of a signature, with a note explaining why. For an example, see http://pinvoke.net/jump.aspx/kernel32.GetVersionEx. Or if you know that an existing signature is just wrong, feel free to correct it. Or if you aren’t sure, feel free to start a discussion on that function’s page, and hopefully someone will come along with an answer.

    In the case of SetLastError=true, I’d say it should be marked for all APIs that use that mechanism, although it turns out that the CLR exhibits SetLastError=true behavior for many Win32 DLLs anyway, regardless of how the signatures are marked. It’s also interesting to note that the VB compiler always emits SetLastError=true when you use a Declare statement. So I’m now thinking that I should change the template to stick SetLastError=true in C# signatures by default.

  7. Miguel de Icaza says:

    Do you have a web service running, that we could say, hook

    up from a client to retrieve this information?

    Miguel

  8. stripe says:

    Is there a proxy server friendly version of the client? I get the annoying 407 error, is the source code available so i can quickly add the few lines of code to make it use the proxy?

    Ta

  9. "Introducing" PINVOKE.NET and its Visual Studio Add-In! .NET????????WindowsAPI?????DllImport??????????????????????????????????????????????? ??????VS.NET????????????????????PINVOKE.NET??Web???????????????????????????????? ?????????????????????···…

  10. Joe Cheng says:

    So so so SO great. Ever since the first day I started doing P/Invoke I wondered why there wasn’t a repository for signatures… but the VS.NET add-in is a very welcome surprise.

    Thanks, Adam, for your efforts (your book is a constant fixture on the desks of myself and my coworkers) and to everyone who has contributed signatures!

  11. stripe says:

    I have done a version that works behind proxy servers.

    Download source code OR binary from

    http://www.stripe.dsl.pipex.com/PInvokeAddin

  12. I applaud Adam’s creation, PINVOKE.NET, and its community driven repository of PINVOKE declarations for .NET. When I’m doing managed development and need to make some call into unmanaged territory, I’ll be certain to look there first for assistance.

  13. Ryan Farley says:

    Truly awesome stuff, Adam. All I can say is that it is about time someone did something like this. Your efforts are really appreciated. Thanks!

  14. Mick Doherty says:

    Very Nice…

    I program in VB.Net but I prefer to use the <DllImport(….)> style of declare to the old VB Classic style.

    How about adding that option?

  15. Mick Doherty says:

    Ok . I see that we must just add that variation. However, we cannot use Line Continuation.

    <DllImport("UxTheme.dll", _

    CallingConvention:=CallingConvention.Cdecl)> _

    Function DrawThemeBackground( _

    ByVal hTheme As IntPtr, _

    ByVal hdc As IntPtr, _

    ByVal iPartId As Integer, _

    ByVal iStateId As Integer, _

    ByRef pRect As RECT, _

    ByRef pClipRect As RECT) As Integer

    End Function

    is much easier to read than

    <DllImport("UxTheme.dll", CallingConvention:=CallingConvention.Cdecl)>Function DrawThemeBackground(ByVal hTheme As IntPtr, ByVal hdc As IntPtr, ByVal iPartId As Integer, ByVal iStateId As Integer, ByRef pRect As RECT, ByRef pClipRect As RECT) As Integer

    End Function

    but then I suppose IntelliSense takes away the need to read it.

  16. Adam Nathan says:

    Thanks, Mick, although I don’t understand your comment about line continuation. I encourage you to use it in the signatures you contribute!

    And thanks, stripe, for the feedback about proxy servers. At some point I’ll release another version that addresses this (in addition to adding new features, such as search).

  17. Would it be possible if the webservice also had a method to get a list of the modules currently available?

  18. Mick Doherty says:

    Adam,

    I submitted a signature using Line Continuation as follows:

    <DllImport("UxTheme.dll", _

    CallingConvention:=CallingConvention.Cdecl)> _

    Function DrawThemeBackground( _

    ByVal hTheme As IntPtr, _

    ByVal hdc As IntPtr, _

    ByVal iPartId As Integer, _

    ByVal iStateId As Integer, _

    ByRef pRect As RECT, _

    ByRef pClipRect As RECT) As Integer

    End Function

    when I tried to use that all I got back was:

    <DllImport("UxTheme.dll", _

    CallingConvention:=CallingConvention.Cdecl)> _

    Function DrawThemeBackground( _

    So I had to modify the submission so that the arguments were all on one line.

  19. Justin Cummings says:

    Great work, Adam!

    This tool will prove invaluable. I do have a couple of suggestions, and considerations:

    1. On the pinvoke.net site, the browser navigation menu could use some massaging to work with Moz/Firebird/Gecko-based browsers — both the javascript and the method of font-size selection are the most noticible issues.

    2. As part of the snippet submission process, it would benificial to provide an [optional] author supplied annotation of the module (dll, exe, cpl, etc) version and possibly platform being used, as you know the legacy APIs for some modules varied greatly.

    3. A further enhancement of the second suggestion would be [a little] more involved, and it was the approach I intended to explore until I saw your work — wrap the native debugger and attempt to locate the suggested within a [local/remote] symbol file. If found, annotate the submission with a confirmation status (or improve it’s weight/rating/relavence) and the version of the PDB used. Since the native debugger isnt really designed to work as an in-process component, perhaps make this semi-automated confirmation process a nighly/hourly batch process.

    Again, kudos and much thanks to you sir.

  20. I’ve written a small application using Delphi 7 (Win32) that gets header declarations from PInvoke.NET and even converts them to Delphi for .NET. You can download it at <a href="http://www.agnisoft.com/downloads/pbroker.zip">http://www.agnisoft.com/downloads/pbroker.zip</a&gt; or visit my blog page on it at <a href="http://shenoyatwork.blogspot.com/2004/06/pinvoke-and-delphi.html">http://shenoyatwork.blogspot.com/2004/06/pinvoke-and-delphi.html</a&gt;.

    Great work, Adam, this is a really cool service!

  21. hmm … every time I tried it the user32.dll terminated with an error . what is wrong

  22. andry says:

    -"1,700 signatures & types" it real cool 🙂

  23. Alex says:

    This is great Add-in.

    However I noticed that it does not work with Visual Studio 2005 Express Edition 🙁

    Thank you

  24. In a recent meeting, I got the opportunity to meet Ward Cunningham, David Orenstein, and Korby Parnell.&amp;nbsp;…

  25. VsAddin says:

    Hi,

    after installing it with my visual studio version 2005 (no beta) – the addin doesn’t appear. What should I do? The setup finished without errors.

  26. If someone asked me, what is the nastiest types of issues you get? I would say managed heap corruption,…

  27. The following links to .NET resources have been collated over time with the assistance of colleagues.&amp;nbsp;…

  28. online directory main

  29. Thanks!!! http://www.insurance-top.com/company/”>http://www.insurance-top.com/company/ auto site insurance. [URL=http://www.insurance-top.com]home insurance[/URL]: compare car insurance, auto insurance, insurance car. Also [url=http://www.insurance-top.com]cars insurance[/url] from website .

  30. Hi! http://www.insurance-top.com/company/ auto site insurance. compare car insurance, auto insurance, insurance car. from website .

  31. Hoodia gordonii diet pills.

    http://beam.to/cellulitesolution/

    http://beam.to/hoodiapills/

    http://beam.to/hoodiagordonii/

    http://beam.to/h57hoodia/

    <a href=http://beam.to/hoodiapills/>hoodia diet pills</a>

    <a href=http://beam.to/hoodiagordonii/>hoodia gordonii</a>

    <a href=http://beam.to/h57hoodia/>h57hoodia</a>

    cheap pharmacy hoodia cactus extract kill appetite pills.

  32. Hoodia gordonii diet pills.

    http://beam.to/cellulitesolution/

    http://beam.to/hoodiapills/

    http://beam.to/hoodiagordonii/

    http://beam.to/h57hoodia/

    <a href=http://beam.to/hoodiapills/>hoodia diet pills</a>

    <a href=http://beam.to/hoodiagordonii/>hoodia gordonii</a>

    <a href=http://beam.to/h57hoodia/>h57hoodia</a>

    cheap pharmacy hoodia cactus extract kill appetite pills.

  33. Persone los pioneros non rabata. Great…

  34. lesbian rape says:

    Best of all people w can talk…

  35. Text: cbc3fac2dc74c4adab698148eeeed9020
    <a href="cbc3fac2dc74c4adab698148eeeed90200">cbc3fac2dc74c4adab698148eeeed90200</a>
    [a]cbc3fac2dc74c4adab698148eeeed90201[/a]
    [a href=cbc3fac2dc74c4adab698148eeeed90202]cbc3fac2dc74c4adab698148eeeed90202[/a]
    [a href="cbc3fac2dc74c4adab698148eeeed90203"]cbc3fac2dc74c4adab698148eeeed90203[/a]
    [link]cbc3fac2dc74c4adab698148eeeed90204[/link]
    [link=cbc3fac2dc74c4adab698148eeeed90205]cbc3fac2dc74c4adab698148eeeed90205[/link]
    [link="cbc3fac2dc74c4adab698148eeeed90206"]cbc3fac2dc74c4adab698148eeeed90206[/link]
    [url]cbc3fac2dc74c4adab698148eeeed90207[/url]
    [url=cbc3fac2dc74c4adab698148eeeed90208]cbc3fac2dc74c4adab698148eeeed90208[/url]
    [url="cbc3fac2dc74c4adab698148eeeed90209"]cbc3fac2dc74c4adab698148eeeed90209[/url]

  36. If someone asked me, what is the nastiest types of issues you get? I would say managed heap corruption,

  37. No prescription didrex. Didrex. Cheap didrex without prescription.