ファイル プロパティの取得

IShellFolder2::GetDetailsOf()

#include <Shlobj.h>
#include <Shlwapi.h>

int main()
{
    HRESULT result = NULL;

    result = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    if (result != S_OK) return 1;


    IShellFolder *pShellFolder;
    SHGetDesktopFolder(&pShellFolder);

    IShellFolder2 *pShellFolder2;
    result = pShellFolder->QueryInterface(IID_PPV_ARGS(&pShellFolder2));
    if (result != S_OK) return 1;

    for (int i = 0;; i++)
    {
        SHELLDETAILS  details;
        result = pShellFolder2->GetDetailsOf(NULL, i, &details);
        if (result != S_OK) break;

        TCHAR header[256];
        StrRetToBuf(&details.str, NULL, header, sizeof(header) / sizeof(TCHAR));

        wprintf(L"%d:%s\n", i, header);
    }

    pShellFolder2->Release();
    pShellFolder->Release();

    CoUninitialize();
    return 0;
}
HRESULT GetDetailsOf(
  [in]  PCUITEMID_CHILD pidl,
  [in]  UINT            iColumn, // 取得対象の情報フィールドのインデックス
  [out] SHELLDETAILS    *psd
);
IShellFolder2::GetDetailsOf method (Windows) | MSDN

iColumnのインデックス番号は、エクスプローラの詳細表示での表示順に対応します。このうちシステム フォルダは下表の項目に加え、基本的な項目を持ちます。

インデックス 名前
0 Name
1 Size
2 Type
3 Date Modified

一方仮想フォルダは、それぞれ独自の項目を持ちます。

STRRETからLPTSTRへの変換は、StrRetToBuf()で行えます。

HRESULT StrRetToBuf(
  _Inout_ STRRET          *pstr,
  _In_    PCUITEMID_CHILD pidl,
  _Out_   LPTSTR          pszBuf,
  _In_    UINT            cchBuf
);
StrRetToBuf function (Windows) | MSDN

FolderPtr::GetDetailsOf()

#import "shell32.dll" \
rename("ShellExecute", "__ShellExecute")

int main()
{
    HRESULT result = NULL;

    result = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    if (result != S_OK) return 1;


    LPCTSTR path = L"C:\\sample";

    Shell32::IShellDispatchPtr pShell;
    result = pShell.CreateInstance(__uuidof(Shell32::Shell));
    if (result != S_OK) return 1;

    Shell32::FolderPtr pFolder = pShell->NameSpace(path);
    int headersCount = 0;
    for (;; headersCount++)
    {
        BSTR header = pFolder->GetDetailsOf(NULL, headersCount);
        if (*header == NULL) break;

        wprintf(L"%s\n", header);
    }


    Shell32::FolderItemsPtr pItems = pFolder->Items();
    for (int i = 0; i<pItems->Count; i++)
    {
        const _variant_t vIndex((short)i);
        Shell32::FolderItemPtr pItem = pItems->Item(vIndex);

        for (int k = 0; k < headersCount; k++)
        {
            const _variant_t vItem((IDispatch*)pItem);
            BSTR property = pFolder->GetDetailsOf(vItem, k);

            wprintf(L"%d:%s\n", k, property);
        }
        pItem.Release();
    }
    pItems.Release();
    pFolder.Release();
    pShell.Release();

    CoUninitialize();
    return 0;
}
HRESULT CreateInstance(
   const CLSID& rclsid,
   IUnknown* pOuter=NULL,
   DWORD dwClsContext = CLSCTX_ALL
) throw( );
_com_ptr_t::CreateInstance | MSDN
Microsoft Learnから検索