Determining Win32 API Support in the .NET Framework

From time to time .NET developers will need to use a native Win32 API to get some platform specific work done. One of the first things I ask myself when I start writing out Interop signatures is "Does the .NET framework already support this?". The breadth of classes in the framework can be daunting and it's not always easy to answer that question. Often the conversations and references online revolve around the native API so that isn't always a help. Searching the MSDN docs can also lead to dead ends as the concepts and naming conventions are often modernized in the framework.  

It turns out, if you know the Win32 API finding support for it in the framework isn't all that hard with .NET Reflector. Generally Microsoft creates internal helper classes that define all the Interop signatures for the Win32 APIs used behind the scenes. So you can simply search for that Win32 signature to see if it's being used by the framework. Now, getting access to those types after you've found them isn't always easy. Sometimes the search will lead you to the public classes that you should read up on to achieve the same purpose. Other times you find a private sealed class available only to the framework classes internally. Depending on your deployment requirements you can get around that with reflection or accessors. If reflection isn't your thing, you can just snip the bit of code you need and use it in your classes.

In order to improve the odds of finding the desired classes, be sure to have most of the .NET assemblies loaded into .NET Reflector. It's easy to add the most common assemblies by selecting File | Open List. Then Add a new list and select the target runtime.

Related Articles

Published : Mar 26, 2009
Views : 29827

Subscribe Subscribe | Blog Home

Downloads

Tags

  • development