Windows 7 Libraries Helpers

After two weeks break, we are back to our normal technical posts, covering Windows 7 Libraries. This is the sixth 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). You know the different programming models that are available to choose from (Light Up with Windows 7 Libraries), and you know how to use Windows Shell APIs to consume the contents of a library (Consuming the Contents of Windows 7 Libraries). In this post, we focus on the Windows 7 Libraries helper functions.

The IShellLibrary COM object presents a Windows 7 Library. This interface defines methods for creating and managing Libraries. You can work directly with the COM interface, but it's easier to use a higher abstraction layer of functions. Shobjidl.h provides the following library helper functions:

  • SHAddFolderPathToLibrary - Adds a folder to a library
  • SHCreateLibrary - Creates an IShellLibrary object
  • SHLoadLibraryFromItem - Creates and loads an IShellLibrary object from a specified library definition file
  • SHLoadLibraryFromKnownFolder - Creates and loads an IShellLibrary object for a specified KNOWNFOLDERID
  • SHLoadLibraryFromParsingName - Creates and loads an IShellLibrary object for a specified path
  • SHRemoveFolderPathFromLibrary - Removes a folder from a library
  • SHResolveFolderPathInLibrary - Attempts to resolve the target location of a library folder that has been moved or renamed
  • SHSaveLibraryInFolderPath - Saves an IShellLibrary object to disk

Note: if you are really interested in how these helper functions are implemented, simply go to the Shobjidl.h h file and search for these functions.

Using these help functions, you can perform most of the management operations on a Library without using the lower level APIs. For example, you can add a folder to a Library using SHAddFolderPathToLibrary without calling ISHellLibrary::Commit(). Since the IShellLibrary is a COM-based API, you will need to CoInitialize the COM objects. After doing so, all you need to do is use the helper functions. The following code snippet creates a new Library, adds a folder to it, and saves the Library definition file in the Libraries folder.

IShellLibrary *pLib; 
IShellItem *pSi;
SHCreateLibrary(IID_PPV_ARGS(&pLib));
SHAddFolderPathToLibrary( pLib, L"C:\\temp ");
pLib ->SaveInKnownFolder(
FOLDERID_Libraries,
L"Test 1 Lib",
LSF_MAKEUNIQUENAME,
& pSi);
 
The helper functions don’t provide all the functionality in the IShellLibrary interface. By working directly with the IShellLibrary interface, you can get or set the Library icon using the GetIcon, and SetIcon. But more importantly, you can get the contents of a library by using the IShellLibrary:: GetFolders() as shown in the next code snippet

IShellLibrary *pslLibrary;
SHLoadLibraryFromKnownFolder(
FOLDERID_PicturesLibrary,
STGM_READ,
IID_PPV_ARGS(&pslLibrary));

IShellItemArray *psiaFolders;
pslLibrary->GetFolders(
LFF_FORCEFILESYSTEM,
IID_PPV_ARGS(&psiaFolders));
 
In the next post we will walk through some techniques of staying in sync with the library contents.


Comments

  1. Posted on: May 08, 2009 at 9:49PM  

    IColumnProvider, MS? Un-deprecate it for this release please.

  2. Posted on: October 13, 2009 at 5:18PM  

    of people thought there was a very nice thought and a continuous concrete operating system improvements and I'm sure it will further advance

Trackbacks

  1. Posted by: Windows 7 Libraries ??? IShellFolder - Windows 7 for Developers … | networking-the.info on May 08, 2009 at 5:34PM

    Pingback from  Windows 7 Libraries ??? IShellFolder - Windows 7 for Developers … | networking-the.info

  2. Posted by: Windows 7 Libraries ??? IShellFolder - Windows 7 for Developers … « ?????? THe World on May 08, 2009 at 5:39PM

    Pingback from  Windows 7 Libraries ??? IShellFolder - Windows 7 for Developers … «  ?????? THe World

  3. Posted by: Windows 7 Libraries – IShellFolder - Windows 7 for Developers … | DONG'S BLOG on May 08, 2009 at 5:41PM

    Pingback from  Windows 7 Libraries – IShellFolder - Windows 7 for Developers … | DONG'S BLOG

  4. Posted by: DotNetShoutout on May 08, 2009 at 6:23PM

    Thank you for submitting this cool story - Trackback from DotNetShoutout

  5. Posted by: Windows 7 Libraries ??? IShellFolder - Windows 7 for Developers … | Current Technology Updates daily on May 08, 2009 at 8:16PM

    Pingback from  Windows 7 Libraries ??? IShellFolder - Windows 7 for Developers … | Current Technology Updates daily

  6. Posted by: Tech News, Resources from Blogosphere - 09 May 09(7) | Best Webhosting on May 08, 2009 at 10:37PM

    Pingback from  Tech News, Resources from Blogosphere - 09 May 09(7) | Best Webhosting

  7. Posted by: IShellFolder in Windows 7 Libraries explained on May 09, 2009 at 4:27AM

    Pingback from  IShellFolder in Windows 7 Libraries explained

  8. Posted by: foremost problem Blog » EmacsNewbieWithIcicles on May 09, 2009 at 7:30AM

    Pingback from  foremost problem Blog » EmacsNewbieWithIcicles

  9. Posted by: MS, Intel ???Goofed Up??? Win 7 XP Virtualization < processor support Blog on May 09, 2009 at 8:30AM

    Pingback from  MS, Intel ???Goofed Up??? Win 7 XP Virtualization  <  processor support Blog

  10. Posted by: Windows 7 Libraries ??? IShellFolder|Join Our Story!|AngNetwork Blog on May 09, 2009 at 2:00PM

    Pingback from  Windows 7 Libraries ??? IShellFolder|Join Our Story!|AngNetwork Blog

  11. Posted by: Dew Drop - Weekend Edition - May 9-10, 2009 | Alvin Ashcraft's Morning Dew on May 09, 2009 at 7:58PM

    Pingback from  Dew Drop - Weekend Edition - May 9-10, 2009 | Alvin Ashcraft's Morning Dew

  12. Posted by: Windows 7 for Developers on May 18, 2009 at 11:42PM

    Here is another post in the Windows 7 Libraries post series. So far, we have covered what Windows 7 Libraries

  13. Posted by: Erwyn van der Meer on May 23, 2009 at 9:13AM

    Sometimes it’s attention to detail that excites me the most. I just noticed the beautiful rendering of

  14. Posted by: Блог Windows 7 для разработчиков on May 25, 2009 at 2:02AM

    Синхронизация библиотек Windows 7 И вот новая статья из серии, посвященной библиотеках Windows 7. На

  15. Posted by: ?????????????????????????? ?????????????????? Windows 7 | Coded Style on May 25, 2009 at 3:26AM

    Pingback from  ?????????????????????????? ?????????????????? Windows 7 | Coded Style

  16. Posted by: ?????????????????????????? ?????????????????? Windows 7 | Coded Style on May 25, 2009 at 3:27AM

    Pingback from  ?????????????????????????? ?????????????????? Windows 7 | Coded Style

  17. Posted by: ?????????????????????????? ?????????????????? Windows 7 | Coded Style on May 25, 2009 at 3:27AM

    Pingback from  ?????????????????????????? ?????????????????? Windows 7 | Coded Style

  18. Posted by: ?????????????????????????? ?????????????????? Windows 7 | Coded Style on May 30, 2009 at 9:59AM

    Pingback from  ?????????????????????????? ?????????????????? Windows 7 | Coded Style

  19. Posted by: ?????????????????????????? ?????????????????? Windows 7 | Coded Style on May 30, 2009 at 10:00AM

    Pingback from  ?????????????????????????? ?????????????????? Windows 7 | Coded Style

  20. Posted by: Windows 7 for Developers on June 09, 2009 at 5:01PM

    We are wrapping up our comprehensive drilldown into the Windows 7 Libraries API and architecture with

  21. Posted by: Windows 7 for Developers on June 09, 2009 at 5:07PM

    We are wrapping up our comprehensive drilldown into the Windows 7 Libraries API and architecture with

  22. Posted by: Windows 7 Programming Guide ??? Libraries « Agave Anejo's Blog on June 21, 2009 at 11:01AM

    Pingback from  Windows 7 Programming Guide ??? Libraries « Agave Anejo's Blog