Many years ago, as a .NET developer, I would often find myself frustrated whenever I wanted to target a particular aspect of Windows, only to discover that no corresponding API in managed code existed. (Yes, I leaned somewhat towards being one of the “.NET purists” that Scott Hanselman warned you about.) In cases like these, and after exhausting all possibilities to find a library in the .NET Framework that met my requirements, I would bite the bullet and resort to Platform Invocation Services (P/Invoke) or COM Interop. Now, to be clear: Both of these technologies work very well. However, I struggled writing P/Invoke wrappers or failed to understand all the subtle nuances of COM. In short, I found P/Invoke and COM Interop a challenge to get exactly right, resulting in my application crashing in a blaze of glory at runtime.
Over the years, things got a little better as developers in the .NET community began to publish interop libraries. Then, in 2004, Adam Nathan announced the PINVOKE.NET wiki and life – as we knew it – got a whole lot better. Now, despite the goodness that this site brought to the .NET community, it would still take time for signatures to be updated or published. In some cases, the listing would be incomplete. In essence, for developers writing managed code, wanting to target specific aspects of Windows, a certain level of heavy-lifting was sometimes required.
Enter the Windows API Code Pack.
The Windows API Code Pack is designed to help managed code developers target key features of Windows without forced you to resort to P/Invoke or COM Interop. Moreover, it abstracts all of the heavy-lifting away from you, leaving you with a clean API for you to target. From the project’s description:
The Windows API Code Pack provides a source code library that can be used to access some features of Windows 7 and Windows Vista from managed code. These Windows features are not available to developers today in the .NET Framework.
Yochay describes it as-follows (with emphasis added by me):
You may think of the Windows API Code Pack as the closest thing to an “official” managed API for Windows on top of the .NET Framework. The Windows API Code Pack is a free, managed source code library provided by Microsoft as-is. You should consider this library as if you wrote that code. It is a great starting point and provides a really solid solution for managed code developers who create Windows application and looking to light up their applications. It covers a lot of the new Windows 7 features as well as some more fundamental core features from the Windows Vista timeframe.
I’d rank the Windows API Code Pack as a must have library for developers targeting Windows Vista or Windows 7 with managed code. In fact, it’s so awesome that it makes you feel like you’ve discovered the Konami Code for unlocking key features of Windows. (My apologies to younger readers who never had the pleasure of playing the supremely-challenging game, Contra on the NES.) The thing I love most about the Windows API Code Pack is the abstraction layer it provides. It hides the gnarly, low-level plumbing (e.g. P/Invoke or COM Interop integration with Windows) and instead, allows you to focus on integrating features that you care about (e.g. sensors in Windows 7) and in a manner that feels more intuitive to managed code developers (e.g. classes/methods/properties).
So, what exactly does the Windows API Code Pack support in terms of Windows features? In a word: Lots.
- Windows 7 Taskbar
- Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars
- Windows Shell
- Windows 7 Libraries
- Windows Shell Search API support
- Explorer Browser Control
- A hierarchy of Shell Namespace entities
- Windows Shell property system
- Drag and Drop for Shell Objects
- Windows Vista and Windows 7 Common File Dialogs, including custom controls
- Known Folders and non-file system containers
- Shell Object Watcher
- Shell Extensions API support
- Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs
- Windows Vista and Windows 7 Task Dialogs
- Sensor Platform APIs
- Extended Linguistic Services APIs
- Power Management APIs
- Application Restart and Recovery APIs
- Network List Manager APIs
- Command Link control and System defined Shell icons
That’s a lot!
Recently, the team recently released the next version of the Windows API Code Pack. So, what are the major changes in v1.1? From the release notes:
- Code clean-up
- Addressed many FxCop violations and PREfast warnings
- Various spot-fixes for improved stability
- Added String localization preparation
- Bug Fixes within the Code Pack and Samples
- New Features
- PropVariant (Re-designed)
- Thumbnail Handlers
- Preview Handlers
- New Demos and Sample Applications
- Visual Studio 2010 Compliance
- xUnit test coverage
- Signed assemblies
Interested in seeing the Windows API Code Pack in-person? Register for TechDays! We have a session dedicated to the Windows API Code Pack occurring in the Developing for Three Screens and the Cloud track:
DEV336 – The Windows API Code Pack: Add Features of Windows 7 to Your Application
Day 1 – 3:40pm – 4:45pm
Accessing new features of Windows 7 is a challenge from managed (.NET) code. The level of interoperability required is out of reach for many developers. The Windows API Code Pack for the Microsoft .NET Framework is a sample library you can use in your own projects today that provides access to new user interface features (taskbar jumplists, libraries, sensor platform, and more) as well as "behind the scenes" features that make your applications more aware and responsive (restart and recovery, power management, and more.) Discover a shortcut to development of Windows 7-based applications for programmers of Microsoft Visual Basic and Visual C# and get started today.
This session was prepared by the ultra-fantastic Kate Gregory and will be presented in all eight cities hosting TechDays!
If you’re building applications in managed code and you’re looking to target particular features of Windows then download the Windows API Code Pack and building your Next Big Thing today! Also, please send us your feedback or file a bug using the Discussions or Issue Tracker for the Windows API Code Pack!