shell32: Return Unicode strings from all of the IShellFolder::GetDisplayNameOf functions in not running in Win9x mode.

This commit is contained in:
Rob Shearman 2007-04-10 10:20:48 +01:00 committed by Alexandre Julliard
parent 6fb16fca6b
commit 899e2ecff8
3 changed files with 93 additions and 62 deletions

View file

@ -558,7 +558,7 @@ static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
{ {
IGenericSFImpl *This = (IGenericSFImpl *)iface; IGenericSFImpl *This = (IGenericSFImpl *)iface;
HRESULT hr = S_OK; HRESULT hr = S_OK;
WCHAR wszPath[MAX_PATH]; LPWSTR pszPath;
TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet); TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
pdump (pidl); pdump (pidl);
@ -566,13 +566,17 @@ static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
if (!strRet) if (!strRet)
return E_INVALIDARG; return E_INVALIDARG;
pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
if (!pszPath)
return E_OUTOFMEMORY;
if (_ILIsDesktop (pidl)) if (_ILIsDesktop (pidl))
{ {
if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
(GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)) (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
strcpyW(wszPath, This->sPathTarget); strcpyW(pszPath, This->sPathTarget);
else else
HCR_GetClassNameW(&CLSID_ShellDesktop, wszPath, MAX_PATH); HCR_GetClassNameW(&CLSID_ShellDesktop, pszPath, MAX_PATH);
} }
else if (_ILIsPidlSimple (pidl)) else if (_ILIsPidlSimple (pidl))
{ {
@ -627,21 +631,21 @@ static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
* Only the folder itself can know it * Only the folder itself can know it
*/ */
hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
wszPath, pszPath,
MAX_PATH); MAX_PATH);
} }
else else
{ {
/* parsing name like ::{...} */ /* parsing name like ::{...} */
wszPath[0] = ':'; pszPath[0] = ':';
wszPath[1] = ':'; pszPath[1] = ':';
SHELL32_GUIDToStringW (clsid, &wszPath[2]); SHELL32_GUIDToStringW (clsid, &pszPath[2]);
} }
} }
else else
{ {
/* user friendly name */ /* user friendly name */
HCR_GetClassNameW (clsid, wszPath, MAX_PATH); HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
} }
} }
else else
@ -652,44 +656,43 @@ static HRESULT WINAPI ISF_Desktop_fnGetDisplayNameOf (IShellFolder2 * iface,
if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) && if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
(GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER)) (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
{ {
lstrcpynW(wszPath, This->sPathTarget, MAX_PATH - 1); lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1);
PathAddBackslashW(wszPath); PathAddBackslashW(pszPath);
cLen = lstrlenW(wszPath); cLen = lstrlenW(pszPath);
} }
_ILSimpleGetTextW(pidl, wszPath + cLen, MAX_PATH - cLen); _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen);
if (!_ILIsFolder(pidl)) if (!_ILIsFolder(pidl))
SHELL_FS_ProcessDisplayFilename(wszPath, dwFlags); SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
} }
} }
else else
{ {
/* a complex pidl, let the subfolder do the work */ /* a complex pidl, let the subfolder do the work */
hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags,
wszPath, MAX_PATH); pszPath, MAX_PATH);
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
BOOL defCharUsed; /* Win9x always returns ANSI strings, NT always returns Unicode strings */
strRet->uType = STRRET_CSTR; if (GetVersion() & 0x80000000)
if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, strRet->u.cStr, MAX_PATH,
NULL, &defCharUsed))
strRet->u.cStr[0] = '\0';
if (defCharUsed)
{ {
strRet->u.pOleStr = SHAlloc((lstrlenW(This->sPathTarget)+1) * strRet->uType = STRRET_CSTR;
sizeof(WCHAR)); if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
if (!strRet->u.pOleStr) NULL, NULL))
hr = E_OUTOFMEMORY; strRet->u.cStr[0] = '\0';
else CoTaskMemFree(pszPath);
{ }
strcpyW(strRet->u.pOleStr, This->sPathTarget); else
strRet->uType = STRRET_WSTR; {
} strRet->uType = STRRET_WSTR;
strRet->u.pOleStr = pszPath;
} }
} }
else
CoTaskMemFree(pszPath);
TRACE ("-- (%p)->(%s,0x%08x)\n", This, TRACE ("-- (%p)->(%s,0x%08x)\n", This,
strRet->uType == STRRET_CSTR ? strRet->u.cStr : strRet->uType == STRRET_CSTR ? strRet->u.cStr :

View file

@ -771,7 +771,7 @@ IShellFolder_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
DWORD dwFlags, LPSTRRET strRet) DWORD dwFlags, LPSTRRET strRet)
{ {
IGenericSFImpl *This = impl_from_IShellFolder2(iface); IGenericSFImpl *This = impl_from_IShellFolder2(iface);
WCHAR wszPath[MAX_PATH+1]; LPWSTR pszPath;
HRESULT hr = S_OK; HRESULT hr = S_OK;
int len = 0; int len = 0;
@ -782,12 +782,16 @@ IShellFolder_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
if (!pidl || !strRet) if (!pidl || !strRet)
return E_INVALIDARG; return E_INVALIDARG;
pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
if (!pszPath)
return E_OUTOFMEMORY;
if (_ILIsDesktop(pidl)) { /* empty pidl */ if (_ILIsDesktop(pidl)) { /* empty pidl */
if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) && if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) &&
(GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER)) (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
{ {
if (This->sPathTarget) if (This->sPathTarget)
lstrcpynW(wszPath, This->sPathTarget, MAX_PATH); lstrcpynW(pszPath, This->sPathTarget, MAX_PATH);
} else { } else {
/* pidl has to contain exactly one non null SHITEMID */ /* pidl has to contain exactly one non null SHITEMID */
hr = E_INVALIDARG; hr = E_INVALIDARG;
@ -797,24 +801,32 @@ IShellFolder_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
(GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) && (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) &&
This->sPathTarget) This->sPathTarget)
{ {
lstrcpynW(wszPath, This->sPathTarget, MAX_PATH); lstrcpynW(pszPath, This->sPathTarget, MAX_PATH);
PathAddBackslashW(wszPath); PathAddBackslashW(pszPath);
len = lstrlenW(wszPath); len = lstrlenW(pszPath);
} }
_ILSimpleGetTextW(pidl, wszPath + len, MAX_PATH + 1 - len); _ILSimpleGetTextW(pidl, pszPath + len, MAX_PATH + 1 - len);
if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(wszPath, dwFlags); if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
} else { } else {
hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, wszPath, MAX_PATH); hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, pszPath, MAX_PATH);
} }
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
strRet->uType = STRRET_CSTR; /* Win9x always returns ANSI strings, NT always returns Unicode strings */
if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, strRet->u.cStr, MAX_PATH, if (GetVersion() & 0x80000000) {
NULL, NULL)) strRet->uType = STRRET_CSTR;
strRet->u.cStr[0] = '\0'; if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
} NULL, NULL))
strRet->u.cStr[0] = '\0';
CoTaskMemFree(pszPath);
} else {
strRet->uType = STRRET_WSTR;
strRet->u.pOleStr = pszPath;
}
} else
CoTaskMemFree(pszPath);
TRACE ("-- (%p)->(%s)\n", This, strRet->u.cStr); TRACE ("-- (%p)->(%s)\n", This, strRet->uType == STRRET_CSTR ? strRet->u.cStr : debugstr_w(strRet->u.pOleStr));
return hr; return hr;
} }

View file

@ -554,7 +554,7 @@ static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
{ {
IGenericSFImpl *This = (IGenericSFImpl *)iface; IGenericSFImpl *This = (IGenericSFImpl *)iface;
WCHAR wszPath[MAX_PATH]; LPWSTR pszPath;
HRESULT hr = S_OK; HRESULT hr = S_OK;
TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet); TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
@ -563,14 +563,18 @@ static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
if (!strRet) if (!strRet)
return E_INVALIDARG; return E_INVALIDARG;
wszPath[0] = 0; pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
if (!pszPath)
return E_OUTOFMEMORY;
pszPath[0] = 0;
if (!pidl->mkid.cb) if (!pidl->mkid.cb)
{ {
/* parsing name like ::{...} */ /* parsing name like ::{...} */
wszPath[0] = ':'; pszPath[0] = ':';
wszPath[1] = ':'; pszPath[1] = ':';
SHELL32_GUIDToStringW(&CLSID_MyComputer, &wszPath[2]); SHELL32_GUIDToStringW(&CLSID_MyComputer, &pszPath[2]);
} }
else if (_ILIsPidlSimple(pidl)) else if (_ILIsPidlSimple(pidl))
{ {
@ -622,11 +626,11 @@ static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
* Only the folder itself can know it * Only the folder itself can know it
*/ */
hr = SHELL32_GetDisplayNameOfChild (iface, pidl, hr = SHELL32_GetDisplayNameOfChild (iface, pidl,
dwFlags, wszPath, MAX_PATH); dwFlags, pszPath, MAX_PATH);
} }
else else
{ {
LPWSTR p = wszPath; LPWSTR p = pszPath;
/* parsing name like ::{...} */ /* parsing name like ::{...} */
p[0] = ':'; p[0] = ':';
@ -645,18 +649,18 @@ static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
else else
{ {
/* user friendly name */ /* user friendly name */
HCR_GetClassNameW (clsid, wszPath, MAX_PATH); HCR_GetClassNameW (clsid, pszPath, MAX_PATH);
} }
} }
else else
{ {
/* append my own path */ /* append my own path */
_ILSimpleGetTextW (pidl, wszPath, MAX_PATH); _ILSimpleGetTextW (pidl, pszPath, MAX_PATH);
} }
} }
else if (_ILIsDrive(pidl)) else if (_ILIsDrive(pidl))
{ {
_ILSimpleGetTextW (pidl, wszPath, MAX_PATH); /* append my own path */ _ILSimpleGetTextW (pidl, pszPath, MAX_PATH); /* append my own path */
/* long view "lw_name (C:)" */ /* long view "lw_name (C:)" */
if (!(dwFlags & SHGDN_FORPARSING)) if (!(dwFlags & SHGDN_FORPARSING))
@ -666,14 +670,14 @@ static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
static const WCHAR wszOpenBracket[] = {' ','(',0}; static const WCHAR wszOpenBracket[] = {' ','(',0};
static const WCHAR wszCloseBracket[] = {')',0}; static const WCHAR wszCloseBracket[] = {')',0};
GetVolumeInformationW (wszPath, wszDrive, GetVolumeInformationW (pszPath, wszDrive,
sizeof(wszDrive)/sizeof(wszDrive[0]) - 6, sizeof(wszDrive)/sizeof(wszDrive[0]) - 6,
&dwVolumeSerialNumber, &dwVolumeSerialNumber,
&dwMaximumComponetLength, &dwFileSystemFlags, NULL, 0); &dwMaximumComponetLength, &dwFileSystemFlags, NULL, 0);
strcatW (wszDrive, wszOpenBracket); strcatW (wszDrive, wszOpenBracket);
lstrcpynW (wszDrive + strlenW(wszDrive), wszPath, 3); lstrcpynW (wszDrive + strlenW(wszDrive), pszPath, 3);
strcatW (wszDrive, wszCloseBracket); strcatW (wszDrive, wszCloseBracket);
strcpyW (wszPath, wszDrive); strcpyW (pszPath, wszDrive);
} }
} }
else else
@ -686,18 +690,30 @@ static HRESULT WINAPI ISF_MyComputer_fnGetDisplayNameOf (IShellFolder2 *iface,
else else
{ {
/* Complex pidl. Let the child folder do the work */ /* Complex pidl. Let the child folder do the work */
hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, wszPath, MAX_PATH); hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, pszPath, MAX_PATH);
} }
if (SUCCEEDED (hr)) if (SUCCEEDED (hr))
{ {
strRet->uType = STRRET_CSTR; /* Win9x always returns ANSI strings, NT always returns Unicode strings */
if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, strRet->u.cStr, MAX_PATH, if (GetVersion() & 0x80000000)
NULL, NULL)) {
strRet->u.cStr[0] = '\0'; strRet->uType = STRRET_CSTR;
if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
NULL, NULL))
strRet->u.cStr[0] = '\0';
CoTaskMemFree(pszPath);
}
else
{
strRet->uType = STRRET_WSTR;
strRet->u.pOleStr = pszPath;
}
} }
else
CoTaskMemFree(pszPath);
TRACE ("-- (%p)->(%s)\n", This, debugstr_w(wszPath)); TRACE ("-- (%p)->(%s)\n", This, strRet->uType == STRRET_CSTR ? strRet->u.cStr : debugstr_w(strRet->u.pOleStr));
return hr; return hr;
} }