SOL9 Sample: KnownFolderManager

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * KnownFolderManager.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



#include <sol/shell/KnownFolderManager.h>
#include <sol/shell/KnownFolder.h>
#include <sol/shell/ShellItem.h>

#include <sol/Locale.h>
#include <sol/Guid.h>
#include <sol/ole/OleInitializer.h>


void _tmain(int argc, const TCHAR** argv)
{
  OleInitializer intializer;

  try {
    Locale locale;

    //1 Create a manager object of class KnownFolerManager     
    SOL::KnownFolderManager manager;

    //2 Get a desktopFolder from the manager with FOLDERID_Desktop.
    SOL::KnownFolder desktopFolder = manager.getFolder(FOLDERID_Desktop);
    _tprintf(_T("Desktop "));   
    try {
      SOL::ShellItem item = desktopFolder.getShellItem();
      _bstr_t name = item.getDisplayName();
      _tprintf(_T("Name=%s "), (const TCHAR*)name);
    } catch (...) {
    }

    try {
      _bstr_t path = desktopFolder.getPath();
      _tprintf(_T("Path=%s "), (const TCHAR*)path);
    } catch (...) {
    }
    _tprintf(_T("\n"));


    //3 Ge all knownFolderId and the count of the folders 
    KNOWNFOLDERID* pKFId = NULL;
    UINT         count = 0;
    manager.getFolderIds(&pKFId, &count);

    //4 Display a displayName and a path of each known folder.
    for(UINT i = 0; i<count; i++) {
      Guid guid;
      _bstr_t fid = guid.toString(pKFId[i]);
      try {
        SOL::KnownFolder folder = manager.getFolder(pKFId[i]);
        _tprintf(_T("Folder(%d) "), i);
  
        try {
          SOL::ShellItem item = folder.getShellItem();
          _bstr_t name = item.getDisplayName();
          _tprintf(_T("Name=%s "), (const TCHAR*)name);
        } catch (...) {
        }

        try {
          _bstr_t path = folder.getPath();
          _tprintf(_T("Path=%s"), (const TCHAR*)path);
        } catch (...) {
        }
        _tprintf(_T("\n"));

      } catch (HRESULT hr) {
        _tprintf(_T("Exception: Folder(%d) %s : HRESULT=%x\n"),
          i, (const TCHAR*)fid, hr);
      }
    }
    CoTaskMemFree(pKFId);

  } catch (HRESULT hr) {
    printf("Exception HRESULT=%0x", hr); 
  } catch (Exception& ex) {
    ex.printf();
  } catch (...) {
    printf("Unknown IException\n");
  }
}





Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.