Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Consuming the Contents of Windows 7 Libraries

23 Apr 2009   #1

Consuming the Contents of Windows 7 Libraries

This is the fifth post about Windows 7 Libraries. By now, you should be familiar with Windows 7 Libraries (Understanding Windows 7 Libraries) and understand the internal structure of Libraries and how they integrate into the Windows Shell (Libraries Under the Hood). In the previous post, we explained the different programming models and ways to work with Windows 7 Libraries. In this post, we focus on the Windows Shell Programming model that you can use to access libraries even without using the latest IShellLibrray APIs.

In the previous post, we talked about the importance of using the right version of the Common File Dialog (CFD) to enable the complete Libraries user experience in Windows 7. In this post we will further explorer the opportunities to let users select and consume Libraries as if they where regular folders. Letís imagine the case of a slideshow application that presents users' pictures. By using the Pictures Library, users are essentially telling the system that their important pictures are stored in the Pictures Library, and therefore, our slideshow application can simply be pointed directly to the Pictures Library and show the users' entire pictures collections. Furthermore, from developersí point of view, using the Libraries system can eliminate the need to maintain a separate configuration file or database, since developers can rely on the Libraries System. But before we dive into the Shell Libraries programming APIs, we need to understand the few concepts regarding the Shell Programming Model.

Shell Programming Model

  • IShellItem, commonly referred to as an item, is the currency of the Shell UI model and its programming model. Items are individual, self-contained content sources. Take for example the above-mentioned Common File Dialogs. Quite few of the interface methods used for controlling the file dialogs use Shell items to refer to folders instead of file system paths. This is important because the CFD can communicate information about both file system folders and other virtual folders that you find in the shell, such as the Control Panel or the Computer folder.
  • IShellFolder interface represents shell folder objects from the shell namespace. Using IShellFolder you can traverse through the contents of a folder, to retrieve the display name of an item in a folder, parse a display name relative to the folder, and obtain an item ID list.
  • IShellLink interface represents a link, usually to a file, folder, or an executable.
  • IPropertyStore interface can be used to manage the property store associated with various shell objects.
  • IShellLibrary interface represents a Windows 7 Library, which we will cover in depth in future posts.
Now that we have defined the different players in the Shell Programming Model, we can see how Libraries fit into this model. Since Libraries are not file system locations, you cannot use file system-specific APIs. Therefore, you have two main options to consume library contents - the Shell Programming Model and the new IShellLibrary API.

Using the Shell Programming Model

You can use the IShellItem and IShellFolder interfaces and a bunch of helper functions to enumerate the contents of Libraries just as if they were regular folders. This means that applications can consume Libraries contents without using the new Libraries API and with very little change to their existing code.

The following code snippet shows how to use the IShellFolder interface to enumerate through the entire contents of the Picture library.

IShellItem *psi;
HRESULT hr = SHGetKnownFolderItem(
IShellFolder *psf;
hr = psi->BindToHandler(NULL, BHID_SFObject, IID_PPV_ARGS(&psf));
IEnumIDList *penumIDList;
psf->EnumObjects(NULL, SHCONTF_FOLDERS, IID_PPV_ARGS(&penumIDList));
//use penumIDList to enumarte the content of the folder

Here you can see that by using the helper function SHGetKnownFolderItem, we can retrieve the correct library location by passing the FOLDERID_PicturesLibrary, which is a GUID representing the known folder, in our case the Picture Library. A successful call will fill the IShellItem *psi with the correct information about the Library represented as a Shell Item. From this point the rest of the code is standard Windows Shell programming, where we use the BindToHandler to bind the previously obtained Shell Item to a Shell folder. Next, we enumerate through the different items in the Shell folder, which in case of a library can be either files or folders. The SHGetKnownFolderItem is a Shell Helper function and is part of a larger group of helper functions that can be found in the shlobj.h header file in the Windows 7 RC SDK.

Using the New IShellLibrary API

You can achieve the same functionality as the code above by using the new Windows 7 IShellLibrary API as shown by the next code snippet.

IShellLibrary *pslLibrary;
HRESULT hr = SHLoadLibraryFromKnownFolder(
IShellItemArray *psiaFolders;
hr = pslLibrary->GetFolders(
IEnumShellItems *penumShellItems;
//work with penumShellItem to enumerate the items in the library

Here you can see that we used another helper function SHLoadLibraryFromKnownFolder to create the IShellLibrary object from which we can call the GetFolders method to return an IShellItemArray that later is used to obtain an enumerator to traverse through the entire library contents.

In the next post we will focus more on the IShellLibrary API.


My System SpecsSystem Spec

24 Apr 2009   #2

Windows 7 x64 / Same

Can I access them like regular folders in .NET? (in the System.IO directive)
My System SpecsSystem Spec

 Consuming the Contents of Windows 7 Libraries

Thread Tools

Similar help and support threads for2: Consuming the Contents of Windows 7 Libraries
Thread Forum
Is there a less time consuming way to do this? General Discussion
Windows 7 OS consuming 100GB space ,how???? Performance & Maintenance
svchost.exe consuming 100% ram Performance & Maintenance
Solved The consuming of RAM Performance & Maintenance
SVCHost Consuming 100% CPU Performance & Maintenance
contents of C\windows switched with contents of c\program files General Discussion
Windows 7 RC - network consuming Network & Sharing

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 02:08 AM.
Twitter Facebook Google+

Windows 7 Forums

Seven Forums Android App Seven Forums IOS App

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33