Share via


Lazy PInvoke Tips

So you need to write code that calls into a native API.  You could spend time writing/testing the code needed to do this but odds are that if you are working with a common API then somebody else has already done this and posted it on the web.

First, there are two resources you should check with:

If those don't work, Google is your friend.  Unfortunately, “PInvoke” isn't a very good search term since people will often not use the term at all and when they do, different people write it in different ways (p-invoke, p/invoke, and platform invoke are all common alternatives).  So instead of using PInvoke in your search, you should use “DllImport”.  People rarely ask “How to I DllImport  XYZ?” but anyone giving an accurate answer is guaranteed use this term in their response since DllImport is the attribute used to call a native function from C# or VB.NET.

For example, here's a simple one... suppose you want to call RegCreateKeyEx.  You could search for “pinvoke regcreatekeyex” and get back a small set of pretty useless results.  Alternatively, you could search for “dllimport regcreatekeyex” which brings back a buch of results that are all right on the money.

[Author: Robert Levy]