From d559ca9c982f9766acc5db3ea887ef2bc27acdff Mon Sep 17 00:00:00 2001 From: Getequ Date: Thu, 16 Aug 2018 21:10:41 +0700 Subject: [PATCH] [ADVAPI32][SHELL32][DESK.CPL] Kill copy-paste of RegLoadMUIString. (#748) RegLoadMUIStringW/A is part of advapi32.dll . shell32.dll and desk.cpl contained exact line-by-line copy of that function. --- dll/cpl/desk/CMakeLists.txt | 6 +- dll/cpl/desk/desk.h | 9 - dll/cpl/desk/muireg.c | 144 ------------- dll/win32/advapi32/CMakeLists.txt | 2 +- dll/win32/advapi32/advapi32.spec | 2 + dll/win32/advapi32/reg/reg.c | 191 ------------------ dll/win32/advapi32_vista/CMakeLists.txt | 2 + .../RegLoadMUIString.c} | 29 +-- dll/win32/advapi32_vista/advapi32_vista.spec | 2 + dll/win32/shell32/CMakeLists.txt | 3 +- 10 files changed, 14 insertions(+), 376 deletions(-) delete mode 100644 dll/cpl/desk/muireg.c rename dll/win32/{shell32/vista.c => advapi32_vista/RegLoadMUIString.c} (88%) diff --git a/dll/cpl/desk/CMakeLists.txt b/dll/cpl/desk/CMakeLists.txt index ae7fb83825a..24d9bb1e604 100644 --- a/dll/cpl/desk/CMakeLists.txt +++ b/dll/cpl/desk/CMakeLists.txt @@ -2,6 +2,9 @@ add_definitions(-D_WIN32) spec2def(desk.cpl desk.spec) +remove_definitions(-D_WIN32_WINNT=0x502) +add_definitions(-D_WIN32_WINNT=0x600) + list(APPEND SOURCE advmon.c appearance.c @@ -20,7 +23,6 @@ list(APPEND SOURCE general.c draw.c theme.c - muireg.c desk.h) file(GLOB desk_rc_deps resources/*.*) @@ -34,6 +36,6 @@ add_library(desk SHARED set_module_type(desk cpl UNICODE) target_link_libraries(desk uuid) -add_importlibs(desk user32 advapi32 gdi32 comctl32 comdlg32 ole32 setupapi shell32 shlwapi uxtheme gdiplus msvcrt kernel32 ntdll) +add_importlibs(desk user32 advapi32 advapi32_vista gdi32 comctl32 comdlg32 ole32 setupapi shell32 shlwapi uxtheme gdiplus msvcrt kernel32 ntdll) add_pch(desk desk.h SOURCE) add_cd_file(TARGET desk DESTINATION reactos/system32 FOR all) diff --git a/dll/cpl/desk/desk.h b/dll/cpl/desk/desk.h index 3c479251cfe..3bb02f3a743 100644 --- a/dll/cpl/desk/desk.h +++ b/dll/cpl/desk/desk.h @@ -122,13 +122,4 @@ HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY,LPCWSTR,UINT,IDataObject*); INT_PTR CALLBACK AdvGeneralPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); -LONG -RegLoadMUIStringW(IN HKEY hKey, - IN LPCWSTR pszValue OPTIONAL, - OUT LPWSTR pszOutBuf, - IN DWORD cbOutBuf, - OUT LPDWORD pcbData OPTIONAL, - IN DWORD Flags, - IN LPCWSTR pszDirectory OPTIONAL); - #endif /* _DESK_H */ diff --git a/dll/cpl/desk/muireg.c b/dll/cpl/desk/muireg.c deleted file mode 100644 index 8754b43655b..00000000000 --- a/dll/cpl/desk/muireg.c +++ /dev/null @@ -1,144 +0,0 @@ -#include "desk.h" - -/****************************************************************************** - * load_string [Internal] - * - * This is basically a copy of user32/resource.c's LoadStringW. Necessary to - * avoid importing user32, which is higher level than advapi32. Helper for - * RegLoadMUIString. - */ -static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars) -{ - HGLOBAL hMemory; - HRSRC hResource; - WCHAR *pString; - int idxString; - - /* Negative values have to be inverted. */ - if (HIWORD(resId) == 0xffff) - resId = (UINT)(-((INT)resId)); - - /* Load the resource into memory and get a pointer to it. */ - hResource = FindResourceW(hModule, MAKEINTRESOURCEW(LOWORD(resId >> 4) + 1), (LPWSTR)RT_STRING); - if (!hResource) return 0; - hMemory = LoadResource(hModule, hResource); - if (!hMemory) return 0; - pString = LockResource(hMemory); - - /* Strings are length-prefixed. Lowest nibble of resId is an index. */ - idxString = resId & 0xf; - while (idxString--) pString += *pString + 1; - - /* If no buffer is given, return length of the string. */ - if (!pwszBuffer) return *pString; - - /* Else copy over the string, respecting the buffer size. */ - cMaxChars = (*pString < cMaxChars) ? *pString : (cMaxChars - 1); - if (cMaxChars >= 0) - { - memcpy(pwszBuffer, pString+1, cMaxChars * sizeof(WCHAR)); - pwszBuffer[cMaxChars] = L'\0'; - } - - return cMaxChars; -} - - -/************************************************************************ - * RegLoadMUIStringW - * - * @implemented - */ -LONG -RegLoadMUIStringW(IN HKEY hKey, - IN LPCWSTR pszValue OPTIONAL, - OUT LPWSTR pszOutBuf, - IN DWORD cbOutBuf, - OUT LPDWORD pcbData OPTIONAL, - IN DWORD Flags, - IN LPCWSTR pszDirectory OPTIONAL) -{ - DWORD dwValueType, cbData; - LPWSTR pwszTempBuffer = NULL, pwszExpandedBuffer = NULL; - LONG result; - - /* Parameter sanity checks. */ - if (!hKey || !pszOutBuf) - return ERROR_INVALID_PARAMETER; - - if (pszDirectory && *pszDirectory) - { - //FIXME("BaseDir parameter not yet supported!\n"); - return ERROR_INVALID_PARAMETER; - } - - /* Check for value existence and correctness of it's type, allocate a buffer and load it. */ - result = RegQueryValueExW(hKey, pszValue, NULL, &dwValueType, NULL, &cbData); - if (result != ERROR_SUCCESS) goto cleanup; - if (!(dwValueType == REG_SZ || dwValueType == REG_EXPAND_SZ) || !cbData) - { - result = ERROR_FILE_NOT_FOUND; - goto cleanup; - } - pwszTempBuffer = HeapAlloc(GetProcessHeap(), 0, cbData); - if (!pwszTempBuffer) - { - result = ERROR_NOT_ENOUGH_MEMORY; - goto cleanup; - } - result = RegQueryValueExW(hKey, pszValue, NULL, &dwValueType, (LPBYTE)pwszTempBuffer, &cbData); - if (result != ERROR_SUCCESS) goto cleanup; - - /* Expand environment variables, if appropriate, or copy the original string over. */ - if (dwValueType == REG_EXPAND_SZ) - { - cbData = ExpandEnvironmentStringsW(pwszTempBuffer, NULL, 0) * sizeof(WCHAR); - if (!cbData) goto cleanup; - pwszExpandedBuffer = HeapAlloc(GetProcessHeap(), 0, cbData); - if (!pwszExpandedBuffer) - { - result = ERROR_NOT_ENOUGH_MEMORY; - goto cleanup; - } - ExpandEnvironmentStringsW(pwszTempBuffer, pwszExpandedBuffer, cbData); - } - else - { - pwszExpandedBuffer = HeapAlloc(GetProcessHeap(), 0, cbData); - memcpy(pwszExpandedBuffer, pwszTempBuffer, cbData); - } - - /* If the value references a resource based string, parse the value and load the string. - * Else just copy over the original value. */ - result = ERROR_SUCCESS; - if (*pwszExpandedBuffer != L'@') /* '@' is the prefix for resource based string entries. */ - { - lstrcpynW(pszOutBuf, pwszExpandedBuffer, cbOutBuf / sizeof(WCHAR)); - } - else - { - WCHAR *pComma = wcsrchr(pwszExpandedBuffer, L','); - UINT uiStringId; - HMODULE hModule; - - /* Format of the expanded value is 'path_to_dll,-resId' */ - if (!pComma || pComma[1] != L'-') - { - result = ERROR_BADKEY; - goto cleanup; - } - - uiStringId = _wtoi(pComma+2); - *pComma = L'\0'; - - hModule = LoadLibraryExW(pwszExpandedBuffer + 1, NULL, LOAD_LIBRARY_AS_DATAFILE); - if (!hModule || !load_string(hModule, uiStringId, pszOutBuf, cbOutBuf / sizeof(WCHAR))) - result = ERROR_BADKEY; - FreeLibrary(hModule); - } - -cleanup: - HeapFree(GetProcessHeap(), 0, pwszTempBuffer); - HeapFree(GetProcessHeap(), 0, pwszExpandedBuffer); - return result; -} diff --git a/dll/win32/advapi32/CMakeLists.txt b/dll/win32/advapi32/CMakeLists.txt index 196e67ee71f..ff7961c492f 100644 --- a/dll/win32/advapi32/CMakeLists.txt +++ b/dll/win32/advapi32/CMakeLists.txt @@ -62,6 +62,6 @@ add_library(advapi32 SHARED set_module_type(advapi32 win32dll UNICODE ENTRYPOINT DllMain 12) target_link_libraries(advapi32 cryptlib wine ${PSEH_LIB}) add_delay_importlibs(advapi32 secur32) -add_importlibs(advapi32 rpcrt4 kernel32 ntdll) +add_importlibs(advapi32 advapi32_vista rpcrt4 kernel32 ntdll) add_pch(advapi32 advapi32.h SOURCE) add_cd_file(TARGET advapi32 DESTINATION reactos/system32 FOR all) diff --git a/dll/win32/advapi32/advapi32.spec b/dll/win32/advapi32/advapi32.spec index d30aa734fb8..3414463328a 100644 --- a/dll/win32/advapi32/advapi32.spec +++ b/dll/win32/advapi32/advapi32.spec @@ -682,3 +682,5 @@ 682 stub WmiSetSingleItemW 683 stub Wow64Win32ApiEntry 684 stdcall WriteEncryptedFileRaw(ptr ptr ptr) +685 stdcall -version=0x600+ RegLoadMUIStringW(ptr wstr wstr long ptr long wstr) advapi32_vista.RegLoadMUIStringW +686 stdcall -version=0x600+ RegLoadMUIStringA(ptr str str long ptr long str) advapi32_vista.RegLoadMUIStringA diff --git a/dll/win32/advapi32/reg/reg.c b/dll/win32/advapi32/reg/reg.c index 61845636caa..37ac117de60 100644 --- a/dll/win32/advapi32/reg/reg.c +++ b/dll/win32/advapi32/reg/reg.c @@ -5151,195 +5151,4 @@ RegUnLoadKeyW(HKEY hKey, return ERROR_SUCCESS; } - -/****************************************************************************** - * load_string [Internal] - * - * This is basically a copy of user32/resource.c's LoadStringW. Necessary to - * avoid importing user32, which is higher level than advapi32. Helper for - * RegLoadMUIString. - */ -static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars) -{ - HGLOBAL hMemory; - HRSRC hResource; - WCHAR *pString; - int idxString; - - /* Negative values have to be inverted. */ - if (HIWORD(resId) == 0xffff) - resId = (UINT)(-((INT)resId)); - - /* Load the resource into memory and get a pointer to it. */ - hResource = FindResourceW(hModule, MAKEINTRESOURCEW(LOWORD(resId >> 4) + 1), (LPWSTR)RT_STRING); - if (!hResource) return 0; - hMemory = LoadResource(hModule, hResource); - if (!hMemory) return 0; - pString = LockResource(hMemory); - - /* Strings are length-prefixed. Lowest nibble of resId is an index. */ - idxString = resId & 0xf; - while (idxString--) pString += *pString + 1; - - /* If no buffer is given, return length of the string. */ - if (!pwszBuffer) return *pString; - - /* Else copy over the string, respecting the buffer size. */ - cMaxChars = (*pString < cMaxChars) ? *pString : (cMaxChars - 1); - if (cMaxChars >= 0) - { - memcpy(pwszBuffer, pString+1, cMaxChars * sizeof(WCHAR)); - pwszBuffer[cMaxChars] = L'\0'; - } - - return cMaxChars; -} - - -/************************************************************************ - * RegLoadMUIStringW - * - * @implemented - */ -LONG WINAPI -RegLoadMUIStringW(IN HKEY hKey, - IN LPCWSTR pszValue OPTIONAL, - OUT LPWSTR pszOutBuf, - IN DWORD cbOutBuf, - OUT LPDWORD pcbData OPTIONAL, - IN DWORD Flags, - IN LPCWSTR pszDirectory OPTIONAL) -{ - DWORD dwValueType, cbData; - LPWSTR pwszTempBuffer = NULL, pwszExpandedBuffer = NULL; - LONG result; - - /* Parameter sanity checks. */ - if (!hKey || !pszOutBuf) - return ERROR_INVALID_PARAMETER; - - if (pszDirectory && *pszDirectory) - { - FIXME("BaseDir parameter not yet supported!\n"); - return ERROR_INVALID_PARAMETER; - } - - /* Check for value existence and correctness of it's type, allocate a buffer and load it. */ - result = RegQueryValueExW(hKey, pszValue, NULL, &dwValueType, NULL, &cbData); - if (result != ERROR_SUCCESS) goto cleanup; - if (!(dwValueType == REG_SZ || dwValueType == REG_EXPAND_SZ) || !cbData) - { - result = ERROR_FILE_NOT_FOUND; - goto cleanup; - } - pwszTempBuffer = HeapAlloc(GetProcessHeap(), 0, cbData); - if (!pwszTempBuffer) - { - result = ERROR_NOT_ENOUGH_MEMORY; - goto cleanup; - } - result = RegQueryValueExW(hKey, pszValue, NULL, &dwValueType, (LPBYTE)pwszTempBuffer, &cbData); - if (result != ERROR_SUCCESS) goto cleanup; - - /* Expand environment variables, if appropriate, or copy the original string over. */ - if (dwValueType == REG_EXPAND_SZ) - { - cbData = ExpandEnvironmentStringsW(pwszTempBuffer, NULL, 0) * sizeof(WCHAR); - if (!cbData) goto cleanup; - pwszExpandedBuffer = HeapAlloc(GetProcessHeap(), 0, cbData); - if (!pwszExpandedBuffer) - { - result = ERROR_NOT_ENOUGH_MEMORY; - goto cleanup; - } - ExpandEnvironmentStringsW(pwszTempBuffer, pwszExpandedBuffer, cbData); - } - else - { - pwszExpandedBuffer = HeapAlloc(GetProcessHeap(), 0, cbData); - memcpy(pwszExpandedBuffer, pwszTempBuffer, cbData); - } - - /* If the value references a resource based string, parse the value and load the string. - * Else just copy over the original value. */ - result = ERROR_SUCCESS; - if (*pwszExpandedBuffer != L'@') /* '@' is the prefix for resource based string entries. */ - { - lstrcpynW(pszOutBuf, pwszExpandedBuffer, cbOutBuf / sizeof(WCHAR)); - } - else - { - WCHAR *pComma = wcsrchr(pwszExpandedBuffer, L','); - UINT uiStringId; - HMODULE hModule; - - /* Format of the expanded value is 'path_to_dll,-resId' */ - if (!pComma || pComma[1] != L'-') - { - result = ERROR_BADKEY; - goto cleanup; - } - - uiStringId = _wtoi(pComma+2); - *pComma = L'\0'; - - hModule = LoadLibraryExW(pwszExpandedBuffer + 1, NULL, LOAD_LIBRARY_AS_DATAFILE); - if (!hModule || !load_string(hModule, uiStringId, pszOutBuf, cbOutBuf / sizeof(WCHAR))) - result = ERROR_BADKEY; - FreeLibrary(hModule); - } - -cleanup: - HeapFree(GetProcessHeap(), 0, pwszTempBuffer); - HeapFree(GetProcessHeap(), 0, pwszExpandedBuffer); - return result; -} - - -/************************************************************************ - * RegLoadMUIStringA - * - * @implemented - */ -LONG WINAPI -RegLoadMUIStringA(IN HKEY hKey, - IN LPCSTR pszValue OPTIONAL, - OUT LPSTR pszOutBuf, - IN DWORD cbOutBuf, - OUT LPDWORD pcbData OPTIONAL, - IN DWORD Flags, - IN LPCSTR pszDirectory OPTIONAL) -{ - UNICODE_STRING valueW, baseDirW; - WCHAR *pwszBuffer; - DWORD cbData = cbOutBuf * sizeof(WCHAR); - LONG result; - - valueW.Buffer = baseDirW.Buffer = pwszBuffer = NULL; - if (!RtlCreateUnicodeStringFromAsciiz(&valueW, pszValue) || - !RtlCreateUnicodeStringFromAsciiz(&baseDirW, pszDirectory) || - !(pwszBuffer = HeapAlloc(GetProcessHeap(), 0, cbData))) - { - result = ERROR_NOT_ENOUGH_MEMORY; - goto cleanup; - } - - result = RegLoadMUIStringW(hKey, valueW.Buffer, pwszBuffer, cbData, NULL, Flags, - baseDirW.Buffer); - - if (result == ERROR_SUCCESS) - { - cbData = WideCharToMultiByte(CP_ACP, 0, pwszBuffer, -1, pszOutBuf, cbOutBuf, NULL, NULL); - if (pcbData) - *pcbData = cbData; - } - -cleanup: - HeapFree(GetProcessHeap(), 0, pwszBuffer); - RtlFreeUnicodeString(&baseDirW); - RtlFreeUnicodeString(&valueW); - - return result; -} - /* EOF */ diff --git a/dll/win32/advapi32_vista/CMakeLists.txt b/dll/win32/advapi32_vista/CMakeLists.txt index 4ba2a0a537c..34fc459a134 100644 --- a/dll/win32/advapi32_vista/CMakeLists.txt +++ b/dll/win32/advapi32_vista/CMakeLists.txt @@ -9,10 +9,12 @@ list(APPEND SOURCE DllMain.c RegDeleteTree.c RegSetKeyValue.c + RegLoadMUIString.c ${CMAKE_CURRENT_BINARY_DIR}/advapi32_vista.def) add_library(advapi32_vista SHARED ${SOURCE}) set_module_type(advapi32_vista win32dll ENTRYPOINT DllMain 12) +target_link_libraries(advapi32_vista wine) add_importlibs(advapi32_vista advapi32 kernel32 ntdll) add_dependencies(advapi32_vista psdk) add_cd_file(TARGET advapi32_vista DESTINATION reactos/system32 FOR all) diff --git a/dll/win32/shell32/vista.c b/dll/win32/advapi32_vista/RegLoadMUIString.c similarity index 88% rename from dll/win32/shell32/vista.c rename to dll/win32/advapi32_vista/RegLoadMUIString.c index 93ec06c07b4..8d80949660c 100644 --- a/dll/win32/shell32/vista.c +++ b/dll/win32/advapi32_vista/RegLoadMUIString.c @@ -1,35 +1,10 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: Copied from advapi32/reg/reg.c - * PURPOSE: Registry functions - * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) - * Thomas Weidenmueller - * UPDATE HISTORY: - * Created 01/11/98 - * 19990309 EA Stubs - * 20050502 Fireball imported some stuff from WINE - */ +#include "advapi32_vista.h" -/* FIXME: This file should go away once we properly handle Vista+ APIs */ - -#include - -#define WIN32_NO_STATUS -#define _INC_WINDOWS -#define COM_NO_WINDOWS_H - -#include -#include -#include #include -#define NTOS_MODE_USER -#include - #include #include -WINE_DEFAULT_DEBUG_CHANNEL(shell); +WINE_DEFAULT_DEBUG_CHANNEL(reg); /****************************************************************************** * load_string [Internal] diff --git a/dll/win32/advapi32_vista/advapi32_vista.spec b/dll/win32/advapi32_vista/advapi32_vista.spec index a3a38a65b72..969207292f6 100644 --- a/dll/win32/advapi32_vista/advapi32_vista.spec +++ b/dll/win32/advapi32_vista/advapi32_vista.spec @@ -2,3 +2,5 @@ @ stdcall RegDeleteTreeA(long str) @ stdcall RegDeleteTreeW(long wstr) @ stdcall RegSetKeyValueW(long wstr wstr long ptr long) +@ stdcall RegLoadMUIStringW(ptr wstr wstr long ptr long wstr) +@ stdcall RegLoadMUIStringA(ptr str str long ptr long str) diff --git a/dll/win32/shell32/CMakeLists.txt b/dll/win32/shell32/CMakeLists.txt index 65d5f0e3b84..c5d247abba6 100644 --- a/dll/win32/shell32/CMakeLists.txt +++ b/dll/win32/shell32/CMakeLists.txt @@ -100,7 +100,6 @@ add_library(shell32 SHARED wine/shellstring.c wine/shlmenu.c wine/shpolicy.c - vista.c shell32.rc ${CMAKE_CURRENT_BINARY_DIR}/shell32_stubs.c ${CMAKE_CURRENT_BINARY_DIR}/shell32.def) @@ -112,7 +111,7 @@ set_source_files_properties(shell32.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT set_module_type(shell32 win32dll UNICODE) target_link_libraries(shell32 shellmenu shelldesktop atlnew wine uuid recyclebin) add_delay_importlibs(shell32 powrprof shdocvw devmgr winspool.drv winmm mpr uxtheme ole32 oleaut32 userenv browseui version fmifs) -add_importlibs(shell32 advapi32 gdi32 user32 comctl32 comdlg32 shlwapi msvcrt kernel32 ntdll) +add_importlibs(shell32 advapi32 advapi32_vista gdi32 user32 comctl32 comdlg32 shlwapi msvcrt kernel32 ntdll) add_dependencies(shell32 stdole2) # shell32_shldisp.tlb needs stdole2.tlb add_pch(shell32 precomp.h SOURCE) add_cd_file(TARGET shell32 DESTINATION reactos/system32 FOR all)