WString GetDisplayPathName( const WChar* const path )
{
    WCHAR pszShortPathNameW[MAX_PATH];
    ::MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, path, -1, pszShortPathNameW, MAX_PATH );

    // Get the Desktop's shell folder interface
    LPSHELLFOLDER psfDesktop = NULL;
    HRESULT hr = ::SHGetDesktopFolder(&psfDesktop);

    // Request an ID list (relative to the desktop) for the short pathname
    ULONG chEaten = 0;
    LPITEMIDLIST pidlShellItem = NULL;
    hr = psfDesktop->ParseDisplayName( NULL, NULL, pszShortPathNameW, &chEaten, &pidlShellItem, NULL );
    psfDesktop->Release();

    // If we couldn't get an ID list for short pathname, it must not exist.
    if( FAILED( hr ) ) 
    {
        //We can do: a) return short pathname; b) return NULL, c) best effort
        WFilePath filepath( path );
        WString drive = filepath.GetDrive();
        WString directory = filepath.GetDirectory();
        WString filename = filepath.GetFileName();
        WString extension = filepath.GetExtension();
        if( ! drive.GetEmpty() && ! directory.GetEmpty() && directory != "\\" )
        {
            if( directory[directory.GetLength() - 1] == '\\' )
                directory = directory.Substring( 0, directory.GetLength() - 1 );
            filepath = GetDisplayPathName( drive + directory ) + "\\";
            drive = filepath.GetDrive();
            directory = filepath.GetDirectory();
        }
        filepath.MakePath( drive, directory, filename, extension );
        return filepath;
    }

    // We did get an ID list, convert it to a long pathname
    CHAR szLongPath[MAX_PATH];
    ::SHGetPathFromIDList( pidlShellItem, szLongPath );

    // Free the ID list allocated by ParseDisplayName
    LPMALLOC pMalloc = NULL;
    hr = ::SHGetMalloc( &pMalloc );
    if( ! FAILED( hr ) ) 
    {
        pMalloc->Free( pidlShellItem );
        pMalloc->Release();
    }

    return szLongPath;
}

