Share via


Listing your properties...

I'm still working on a managed property system wrapper but after some excellent comments from Ben Karas, we decided to hold off and have a meeting. Something I can show today is how to list all your system properties in native C++:

#ifndef _WIN32_WINNT

#define _WIN32_WINNT 0x0600

#endif

#include <iostream>

#include <iomanip>

#include <objbase.h>

#include <ComDef.h>

#include <ShlObj.h>

#define DECLARE_COM_SMARTPTR(x) _COM_SMARTPTR_TYPEDEF(x, __uuidof(x));

DECLARE_COM_SMARTPTR(IPropertySystem)

DECLARE_COM_SMARTPTR(IPropertyDescriptionList)

DECLARE_COM_SMARTPTR(IPropertyDescription)

using namespace std;

int wmain() {

if FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))

return -1;

IPropertySystemPtr propertySystem(__uuidof(PropertySystem));

IPropertyDescriptionListPtr propertyDescriptionList;

propertySystem->EnumeratePropertyDescriptions( PDEF_ALL, IID_PPV_ARGS(& propertyDescriptionList));

UINT count;

propertyDescriptionList->GetCount(& count);

for( UINT i = 0; i < count; i++) {

IPropertyDescriptionPtr propertyDescription;

propertyDescriptionList->GetAt(i, IID_PPV_ARGS(& propertyDescription));

PROPDESC_TYPE_FLAGS mask;

propertyDescription->GetTypeFlags(PDTF_ISINNATE, & mask);

wcout << (mask ? L'R' : L' ') ;

wcout << L"\t\"";

wchar_t * name;

propertyDescription->GetDisplayName(& name);

if (name) {

wcout << name ;

CoTaskMemFree(name);

}

wcout << L"\"\t";

propertyDescription->GetCanonicalName(& name);

if (name) {

wcout << L'(' << name << L")";

CoTaskMemFree(name);

}

wcout << L"\"\t";

VARTYPE vt;

propertyDescription->GetPropertyType(& vt);

wchar_t * type = NULL;

switch (vt & ~VT_VECTOR) {

case VT_NULL: type = L"VT_NULL"; break;

case VT_UI1: type = L"VT_UI1"; break;

case VT_UI2: type = L"VT_UI2"; break;

case VT_UI4: type = L"VT_UI4"; break;

case VT_UI8: type = L"VT_UI8"; break;

case VT_I2: type = L"VT_I2"; break;

case VT_I4: type = L"VT_I4"; break;

case VT_I8: type = L"VT_I8"; break;

case VT_R8: type = L"VT_R8"; break;

case VT_BOOL: type = L"VT_BOOL"; break;

case VT_FILETIME: type = L"VT_FILETIME"; break;

case VT_CLSID: type = L"VT_CLSID"; break;

case VT_LPWSTR: type = L"VT_LPWSTR"; break;

case VT_BLOB: type = L"VT_BLOB"; break;

case VT_STREAM: type = L"VT_STREAM"; break;

case VT_CF: type = L"VT_CF"; break;

}

if (type) {

if (vt & VT_VECTOR) {

wcout << L"VT_VECTOR |";

}

wcout << L' ' << type;

} else {

wcout << vt ;

}

wcout << L"\t";

PROPERTYKEY propertyKey;

propertyDescription->GetPropertyKey(& propertyKey);

wcout << L'{';

GUID & g = propertyKey.fmtid;

wcout << hex

<< showbase

<< L'{' << g.Data1 << L","

<< g.Data2 << L","

<< g.Data3 << L",{"

<< g.Data4[0] << L","

<< g.Data4[1] << L","

<< g.Data4[2] << L","

<< g.Data4[3] << L","

<< g.Data4[4] << L","

<< g.Data4[5] << L","

<< g.Data4[6] << L","

<< g.Data4[7] << L"}}"

<< L","

<< propertyKey.pid << L'}'

<< dec << noshowbase ;

wcout << endl;

}

CoUninitialize();

return 0;

}

 

On my box, I have 845 properties! Enjoy et à demain si on le veut bien…