VirtualBox

Changeset 36879 in vbox


Ignore:
Timestamp:
Apr 29, 2011 9:15:52 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
71457
Message:

IPRT/path-win: Fixed NT4 breakage when using SHGetFolderPathW.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/path-win.cpp

    r36675 r36879  
    3737#include <iprt/string.h>
    3838#include <iprt/time.h>
     39#include <iprt/ldr.h>
    3940#include <iprt/mem.h>
    4041#include <iprt/param.h>
     
    4445#include "internal/fs.h"
    4546
     47/* Needed for lazy loading SHGetFolderPathW in RTPathUserDocuments(). */
     48typedef HRESULT FNSHGETFOLDERPATHW(HWND, int, HANDLE, DWORD, LPWSTR);
     49typedef FNSHGETFOLDERPATHW *PFNSHGETFOLDERPATHW;
    4650
    4751/**
     
    191195    AssertReturn(cchPath, VERR_INVALID_PARAMETER);
    192196
    193     RTUTF16 wszPath[RTPATH_MAX];
    194     HRESULT rc = SHGetFolderPathW(0, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, wszPath);
    195     if (   rc == S_OK     /* Found */
    196         || rc == S_FALSE) /* Found, but doesn't exists */
    197         /*
    198          * Convert and return.
    199          */
    200         return RTUtf16ToUtf8Ex(&wszPath[0], RTSTR_MAX, &pszPath, cchPath, NULL);
    201 
     197    RTLDRMOD hShell32;
     198    int rc = RTLdrLoad("Shell32.dll", &hShell32);
     199    if (RT_SUCCESS(rc))
     200    {
     201        PFNSHGETFOLDERPATHW pfnSHGetFolderPathW;
     202        rc = RTLdrGetSymbol(hShell32, "SHGetFolderPathW", (void**)&pfnSHGetFolderPathW);
     203        if (RT_SUCCESS(rc))
     204        {
     205            RTUTF16 wszPath[RTPATH_MAX];
     206            HRESULT hrc = pfnSHGetFolderPathW(0, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, wszPath);
     207            if (   hrc == S_OK     /* Found */
     208                || hrc == S_FALSE) /* Found, but doesn't exist */
     209            {
     210                /*
     211                 * Convert and return.
     212                 */
     213                RTLdrClose(hShell32);
     214                return RTUtf16ToUtf8Ex(&wszPath[0], RTSTR_MAX, &pszPath, cchPath, NULL);
     215            }
     216        }
     217        RTLdrClose(hShell32);
     218    }
    202219    return VERR_PATH_NOT_FOUND;
    203220}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette