Click here to Skip to main content
14,981,856 members
Articles / Desktop Programming / Win32
Posted 13 Sep 2010


21 bookmarked

Windows API Code Pack v1.1 Released!

Rate me:
Please Sign up or sign in to vote.
4.94/5 (10 votes)
15 Sep 2010Ms-PL3 min read
Windows API Code Pack v1.1

Last Tuesday (31.08.2010), Microsoft released a new version for the excellent managed library, Windows API Code Pack.

For those who don't know, this library serves as a managed wrapper for many Windows APIs which are not included in the .NET framework, especially new features from Windows Vista and Windows 7.

I've been working with this library for quite some time now and I must say it is “.NET missing piece”. Most of the Windows features which don't exist in .NET are at your fingertips, without handling all the Interop stuff yourself.

With the coming of .NET Framework v4.0 which supports side by side execution, we can finally write managed shell extensions without having to worry about race conditions between the installed CLRs. And what could be a better starting point for such a shell extension than Windows API Code Pack?

What’s New?

So, what’s new in this release?

Well, the official site says that other than bug fixes, the main new features are:

  • Shell Object Watcher
  • Preview Handler APIs
  • Thumbnail Handler APIs

Let’s try to understand what it means..

Shell Object Watcher

ShellObjectWatcher is a new class in Windows API Code Pack that provides notifications on all elements in the shell, including: files, folders, virtual folders (libraries, search results, network items), etc.

Using this class, you can get notifications on: Create, Delete, Rename, Share, Drive Added, etc.
The magic is done using the Win32 API SHChangeNotifyRegister.

The managed API is rather simple and there is a WPF sample application that shows how to get all events of a user selected path:


In the image, we see Shell Object Watcher sample application behavior when inserting a USB drive, creating and renaming a folder on C:\ and creating a new text file in the folder.

Shell Extensions

Shell extensions are custom extensions to the Windows operating system, or to be more specific, the shell. Different types of shell extensions extend different parts of the Windows shell.
Many parts of the shell can be extended, for example, Windows API Code Pack provides support for the following shell extensions:

  • Preview Handlers – lets you customize the way the preview window in Windows Explorer will behave on specific file extensions.
  • Thumbnail Handlers – lets you customize the thumbnail of files with a specific file extension.

One thing worth noting is that all shell extensions are usually COM-based components. But using COM Interop, we can implement them using the .NET Framework.

The way it usually works is as follows:

  • First, you need to write code that adheres to a specific, predefined interface. The interfaces depend on the part of the shell you want to extend.
  • Second, you register your object in a specific part of the registry. Different types of shell extensions are registered in different locations of the registry.
  • Finally, you use your shell extension by simply going to the part of the shell you have extended and see it in action.

Preview Handler APIs

Preview handler is one type of shell extension. It allows you to customize the preview window in Windows Explorer for a specific file extension.

In the image below, we can see on the right a custom preview handler for the file extension xyz2.

In this example, the preview handler reads the information from the xyz2 file and displays it. Here is the content of the file SampleFile.xyz2:

<?xml version="1.0" encoding="utf-8" ?>
    <Name>Handler Sample File</Name>
    <Author>Jon Harkness</Author>
    <Region>Seattle, Wa</Region>
  <EncodedImage>Qk22MQQAAAAAAEYAAAA4AAAAOUAAAAB... </EncodedImage>
  <Content>Windows? API Code Pack for Microsoft... </Content>

Of course, you can make preview handlers for any file extension, regardless of the file format.

Thumbnail Handler APIs

Thumbnail handler is another type of shell extension. It allows you to customize the thumbnail of a file extension in Windows Explorer.

For example, in the image below, we can see that the thumbnail of the file SampleFile.xyz2 shows the image that is encoded inside the file.


That’s it for now,
Arik Poznanski

Image 3Image 4


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Arik Poznanski
Software Developer (Senior) Verint
Israel Israel
Arik Poznanski is a senior software developer at Verint. He completed two B.Sc. degrees in Mathematics & Computer Science, summa cum laude, from the Technion in Israel.

Arik has extensive knowledge and experience in many Microsoft technologies, including .NET with C#, WPF, Silverlight, WinForms, Interop, COM/ATL programming, C++ Win32 programming and reverse engineering (assembly, IL).

Comments and Discussions

Praisethankful Pin
Member 138549231-Jun-18 10:42
MemberMember 138549231-Jun-18 10:42 
GeneralMy vote of 5 Pin
Simon Dufour17-Sep-10 8:46
MemberSimon Dufour17-Sep-10 8:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.