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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| /*
http://www.developpez.net/forums/d1598197/general-developpement/programmation-systeme/windows/bas-fonds-windows/#post8714011
*/
#include <windows.h>
#include <shlobj.h>
#include <propsys.h>
#include <stdio.h>
#include <tchar.h>
#include <StrSafe.h>
HRESULT GetUIObjectOfFile(HWND hwnd, LPCWSTR pszPath, REFIID riid, void **ppv)
{
*ppv = NULL;
HRESULT hr;
PIDLIST_ABSOLUTE pidl;
SFGAOF sfgao;
if (SUCCEEDED(hr = SHParseDisplayName(pszPath, NULL, &pidl, 0, &sfgao))) {
IShellFolder *psf;
PCUITEMID_CHILD pidlChild;
if (SUCCEEDED(hr = SHBindToParent(pidl, IID_IShellFolder, (void**)&psf, &pidlChild))) {
hr = psf->GetUIObjectOf(hwnd, 1, &pidlChild, riid, NULL, ppv);
psf->Release();
}
CoTaskMemFree(pidl);
}
return hr;
}
EXTERN_C void TestMP3Properties()
{
HRESULT hr = CoInitialize(NULL);
if(SUCCEEDED(hr))
{
LPCWSTR filePath = L"C:\\Ton\\Chemin\\Ici\\Musique.mp3";
IPropertyStore *pProps = NULL;
hr = GetUIObjectOfFile(NULL, filePath, __uuidof(IPropertyStore), (void**)&pProps);
if(SUCCEEDED(hr))
{
puts("Property store obtained!");
DWORD count = 0;
hr = pProps->GetCount(&count);
if(SUCCEEDED(hr))
{
for(DWORD i=0 ; i<count ; i++)
{
PROPERTYKEY key = {0};
PROPVARIANT value = {0};
PropVariantInit(&value);
hr = pProps->GetAt(i, &key);
if(SUCCEEDED(hr))
{
OLECHAR buf[40] = L"";
StringFromGUID2(key.fmtid, buf, ARRAYSIZE(buf));
wprintf(L"%s - %u:\n", buf, key.pid);
hr = pProps->GetValue(key, &value);
if(SUCCEEDED(hr))
{
WCHAR valuebuf[20] = L"";
LPCWSTR ws = valuebuf;
switch(value.vt)
{
case VT_BSTR:
ws = value.bstrVal;
break;
case VT_LPWSTR:
ws = value.pwszVal;
break;
case VT_I2:
StringCbPrintfW(valuebuf, sizeof valuebuf, L"%d", value.iVal);
break;
case VT_UI2:
StringCbPrintfW(valuebuf, sizeof valuebuf, L"%u", value.uiVal);
break;
case VT_I4:
StringCbPrintfW(valuebuf, sizeof valuebuf, L"%d", value.intVal);
break;
case VT_UI4:
StringCbPrintfW(valuebuf, sizeof valuebuf, L"%u", value.uintVal);
break;
case VT_I8:
StringCbPrintfW(valuebuf, sizeof valuebuf, L"%lld", value.intVal);
break;
case VT_UI8:
StringCbPrintfW(valuebuf, sizeof valuebuf, L"%llu", value.uintVal);
break;
}
if(value.vt == VT_BSTR)
ws = value.bstrVal;
wprintf(L"\tType %u : %s\n", value.vt, ws);
}
}
PropVariantClear(&value);
}
}
pProps->Release(), pProps=NULL;
}
else
printf("GetUIObjectOfFile() failed with HRESULT = %08lX\n", hr);
CoUninitialize();
}
else
printf("CoInitialize() failed with HRESULT = %08lX\n", hr);
} |
Partager