PathGetPathDisplayName

Go to Home Page

Returns the display name for a file path

Syntax

HRESULT WINAPI PathGetPathDisplayName (
    LPCWSTR pwszPath,
    LPWSTR pwszDisplayName,
    DWORD displayNameLen
)

Parameters

pwszPath
The path to get the display name of
pwszDisplayName
A pointer to a buffer that receives the display name.
displayNameLen
The length of the pwszDisplayName buffer in WCHARs.

Return Value

S_OK on success, standard COM error code on error

Remarks

A display name is formatted as 'Name.ext (C:\Path\to\File)' (without quotes). Note that pwszPath must use backslashes to separate path components. Forward slashes will result in a copy of pwszPath in pwszDisplayName.

This function is also known as _PathGetPathDisplayName@12.

Examples

#include <windows.h>
#include <stdio.h>

typedef HRESULT (WINAPI*pfnGetDispName)(LPCWSTR, LPWSTR, DWORD);

int main()
{
  HMODULE hMod = LoadLibraryW(L"shell32.dll");
  pfnGetDispName pathGetDisplayName = (pfnGetDispName)GetProcAddress(hMod, (LPCSTR)840);
  WCHAR displayName[MAX_PATH] = {0};
  LPCWSTR fileName = L"C:\\Windows\\system32\\shell32.dll";
  pathGetDisplayName(fileName, displayName, ARRAYSIZE(displayName));
  wprintf(L"%s = %s\n", fileName, displayName);
  fileName = L"C:/Windows/system32/shell32.dll";
  pathGetDisplayName(fileName, displayName, ARRAYSIZE(displayName));
  wprintf(L"%s = %s\n", fileName, displayName);
  fileName = L".\\dir\\shell32.dll";
  pathGetDisplayName(fileName, displayName, ARRAYSIZE(displayName));
  wprintf(L"%s = %s\n", fileName, displayName);
  fileName = L"./dir/shell32.dll";
  pathGetDisplayName(fileName, displayName, ARRAYSIZE(displayName));
  wprintf(L"%s = %s\n", fileName, displayName);
  fileName = L"\\shell32.dll";
  pathGetDisplayName(fileName, displayName, ARRAYSIZE(displayName));
  wprintf(L"%s = %s\n", fileName, displayName);
  fileName = L".\\shell32.dll";
  pathGetDisplayName(fileName, displayName, ARRAYSIZE(displayName));
  wprintf(L"%s = %s\n", fileName, displayName);
  fflush(stdout);
}
OUTPUT
------
C:\Windows\system32\shell32.dll = shell32.dll (C:\Windows\system32)
C:/Windows/system32/shell32.dll = C:/Windows/system32/shell32.dll
.\dir\shell32.dll = shell32.dll (.\dir)
./dir/shell32.dll = ./dir/shell32.dll
\shell32.dll = \shell32.dll
.\shell32.dll = shell32.dll (.)