Author: cfinck
Date: Wed Apr 15 02:13:20 2009
New Revision: 40512
URL:
http://svn.reactos.org/svn/reactos?rev=40512&view=rev
Log:
Fix and slightly optimize _SHGetUserShellFolderPath
Note to Wine guys: Registry functions take and give everything in bytes!
Modified:
trunk/reactos/dll/win32/shell32/shellpath.c
Modified: trunk/reactos/dll/win32/shell32/shellpath.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shellpat…
==============================================================================
--- trunk/reactos/dll/win32/shell32/shellpath.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/shellpath.c [iso-8859-1] Wed Apr 15 02:13:20 2009
@@ -924,7 +924,7 @@
HRESULT hr;
WCHAR shellFolderPath[MAX_PATH], userShellFolderPath[MAX_PATH];
LPCWSTR pShellFolderPath, pUserShellFolderPath;
- DWORD dwDisp, dwType, dwPathLen = MAX_PATH;
+ DWORD dwDisp, dwType, dwPathLen;
HKEY userShellFolderKey, shellFolderKey;
TRACE("%p,%s,%s,%p\n",rootKey, debugstr_w(userPrefix), debugstr_w(value),
@@ -962,21 +962,25 @@
return E_FAIL;
}
+ dwPathLen = MAX_PATH * sizeof(WCHAR);
+
if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType,
(LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType ==
REG_SZ))
{
LONG ret;
- path[dwPathLen / sizeof(WCHAR)] = '\0';
+ dwPathLen /= sizeof(WCHAR);
+
+ path[dwPathLen] = '\0';
if (dwType == REG_EXPAND_SZ && path[0] == '%')
{
WCHAR szTemp[MAX_PATH];
- ExpandEnvironmentStringsW(path, szTemp, MAX_PATH);
- lstrcpynW(path, szTemp, MAX_PATH);
- }
- ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path,
- (wcslen(path) + 1) * sizeof(WCHAR));
+ dwPathLen = ExpandEnvironmentStringsW(path, szTemp, MAX_PATH);
+ lstrcpynW(path, szTemp, dwPathLen);
+ }
+
+ ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path, dwPathLen *
sizeof(WCHAR));
if (ret != ERROR_SUCCESS)
hr = HRESULT_FROM_WIN32(ret);
else
@@ -984,6 +988,7 @@
}
else
hr = E_FAIL;
+
RegCloseKey(shellFolderKey);
RegCloseKey(userShellFolderKey);
TRACE("returning 0x%08x\n", hr);