April 29th, 2013

Getting the display name for a shell property

Today’s Little Program takes the symbolic name for a shell property and returns a string suitable for display to the end-user, translated into the user’s specified display language.

#include <windows.h>
#include <ole2.h>
#include <propsys.h>
#include <propkey.h>
#include <atlbase.h>
#include <atlalloc.h>

int __cdecl wmain(int argc, PWSTR argv[]) { CCoInitialize init; if (SUCCEEDED(init) && argc == 2) { CComPtr<IPropertyDescription> spdesc; if (SUCCEEDED(PSGetPropertyDescriptionByName( argv[1], IID_PPV_ARGS(&spdesc)))) { CComHeapPtr<wchar_t> spszName; if (SUCCEEDED(spdesc->GetDisplayName(&spszName))) { wprintf(L”%ls\n”, static_cast<PWSTR>(spszName)); } } } return 0; }

Run this program with the string System.Music.Album­Artist on the command line, and the result is the message Album artist on English-language systems.

The actual workings of the program is pretty straightward. We ask the property system for an interface that describes the property name, and ask that interface to give us the display name, which we print out.

Nothing fancy here. The trick is just knowing that the function exists in the first place.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.