SOL9 Sample: KnownFolderShellItem
|
1 Screenshot
2 Source code
/*
* KnownFolderShellItem.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
#define UNICODE
#include <sol/shell/KnownFolderManager.h>
#include <sol/shell/KnownFolder.h>
#include <sol/ole/OleInitializer.h>
#include <sol/Locale.h>
#include <sol/Guid.h>
#include <sol/shell/ShellItem.h>
#include <sol/FileWriter.h>
//#include <sol/shell/NameSpaceTreeControl.h>
void _tmain(int argc, const TCHAR** argv)
{
OleInitializer initializer;
try {
Locale locale;
FileWriter writer(L".\\KnownFolderShellItem.xml");
writer.write(L"<?xml version='1.0'?>\n");
//1 Create a manager object of class KnownFolerManager
SOL::KnownFolderManager manager;
writer.write(L"<ShellApplication>\n");
//2 Ge all knownFolderId and the count of the folders
KNOWNFOLDERID* pKFId = NULL;
UINT count = 0;
manager.getFolderIds(&pKFId, &count);
//3 Display the name of each folder of the known folders.
writer.write(L"<KnownFolders count='%d'>\n", count);
for(UINT i = 0; i<count; i++) {
Guid guid;
_bstr_t fid = guid.toString(pKFId[i]);
try {
SOL::KnownFolder folder = manager.getFolder(pKFId[i]);
writer.write(L"<KnownFolder>\n");
try {
_bstr_t path = folder.getPath();
_bstr_t encPath;
HTMLEncoder encoder;
encoder.encode((const wchar_t*)path, encPath);
writer.write(L"<Path>%s</Path>\n", (const wchar_t*)encPath);
} catch (...) {
}
try {
SOL::ShellItem shellItem = folder.getShellItem();
shellItem.write(writer);
} catch (...) {
}
writer.write(L"</KnownFolder>\n");
} catch (HRESULT hr) {
_tprintf(_T("Exception: Folder(%d) %s : HRESULT=%x\n"),
i, (const TCHAR*)fid, hr);
}
}
CoTaskMemFree(pKFId);
writer.write(L"</KnownFolders>\n");
writer.write(L"</ShellApplication>\n");
writer.close();
} 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.