Getting the display name for a shell property

Date:April 29, 2013 / year-entry #116
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20130429-00/?p=4523
Comments:    2
Summary: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 #include #include #include #include #include int __cdecl wmain(int argc, PWSTR argv[]) { CCoInitialize init; if (SUCCEEDED(init) && argc == 2)...

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.


Comments (2)
  1. John Doe says:

    Is there a function to list all registered properties, or all properties of an object?

    [You can answer this question yourself. When you implement IShellFolder, how can somebody enumerate all the properties of your objects? -Raymond]
  2. Medinoc says:

    The weird part is that it doesn't return a BSTR. Is there a reason for this?

    [Automation interfaces use BSTR. This is not an automation interface. -Raymond]

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index