From 2ef63b5190d1c1e47393e1a9ad608d77143d968d Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Tue, 14 Apr 2009 22:13:20 +0000 Subject: [PATCH] Fix and slightly optimize _SHGetUserShellFolderPath Note to Wine guys: Registry functions take and give everything in bytes! svn path=/trunk/; revision=40512 --- reactos/dll/win32/shell32/shellpath.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/reactos/dll/win32/shell32/shellpath.c b/reactos/dll/win32/shell32/shellpath.c index 9e9468846d9..68021fba37c 100644 --- a/reactos/dll/win32/shell32/shellpath.c +++ b/reactos/dll/win32/shell32/shellpath.c @@ -924,7 +924,7 @@ static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix, 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 @@ static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix, 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); + dwPathLen = ExpandEnvironmentStringsW(path, szTemp, MAX_PATH); + lstrcpynW(path, szTemp, dwPathLen); } - ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path, - (wcslen(path) + 1) * sizeof(WCHAR)); + + 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 @@ static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix, } else hr = E_FAIL; + RegCloseKey(shellFolderKey); RegCloseKey(userShellFolderKey); TRACE("returning 0x%08x\n", hr);