diff --git a/reactos/dll/win32/CMakeLists.txt b/reactos/dll/win32/CMakeLists.txt index 97ea7c5cd78..8bc2b62b237 100644 --- a/reactos/dll/win32/CMakeLists.txt +++ b/reactos/dll/win32/CMakeLists.txt @@ -4,6 +4,7 @@ add_subdirectory(aclui) add_subdirectory(activeds) add_subdirectory(actxprxy) add_subdirectory(advapi32) +add_subdirectory(advapi32_vista) add_subdirectory(advpack) add_subdirectory(atl) add_subdirectory(atl100) diff --git a/reactos/dll/win32/advapi32_vista/CMakeLists.txt b/reactos/dll/win32/advapi32_vista/CMakeLists.txt new file mode 100644 index 00000000000..0b9d7a75378 --- /dev/null +++ b/reactos/dll/win32/advapi32_vista/CMakeLists.txt @@ -0,0 +1,17 @@ + +remove_definitions(-D_WIN32_WINNT=0x502 -DWINVER=0x502) +add_definitions(-D_WIN32_WINNT=0x600 -DWINVER=0x600) + +add_definitions(-D_ADVAPI32_) +spec2def(advapi32_vista.dll advapi32_vista.spec ADD_IMPORTLIB) + +list(APPEND SOURCE + DllMain.c + RegDeleteTree.c + ${CMAKE_CURRENT_BINARY_DIR}/advapi32_vista.def) + +add_library(advapi32_vista SHARED ${SOURCE}) +set_module_type(advapi32_vista win32dll ENTRYPOINT DllMain 12) +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/reactos/dll/win32/advapi32_vista/DllMain.c b/reactos/dll/win32/advapi32_vista/DllMain.c new file mode 100644 index 00000000000..0902d8455d7 --- /dev/null +++ b/reactos/dll/win32/advapi32_vista/DllMain.c @@ -0,0 +1,14 @@ + +#include "advapi32_vista.h" + +BOOL +WINAPI +DllMain(HANDLE hDll, + DWORD dwReason, + LPVOID lpReserved) +{ + /* For now, there isn't much to do */ + if (dwReason == DLL_PROCESS_ATTACH) + DisableThreadLibraryCalls(hDll); + return TRUE; +} diff --git a/reactos/dll/win32/advapi32_vista/RegDeleteTree.c b/reactos/dll/win32/advapi32_vista/RegDeleteTree.c new file mode 100644 index 00000000000..0a9f6192fb7 --- /dev/null +++ b/reactos/dll/win32/advapi32_vista/RegDeleteTree.c @@ -0,0 +1,102 @@ + +#include "advapi32_vista.h" + +/* heap allocation helpers */ +static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1); +static inline void *heap_alloc( size_t len ) +{ + return HeapAlloc( GetProcessHeap(), 0, len ); +} + +static inline BOOL heap_free( void *mem ) +{ + return HeapFree( GetProcessHeap(), 0, mem ); +} + +/* Taken from Wine advapi32/registry.c */ + +/****************************************************************************** + * RegDeleteTreeW [ADVAPI32.@] + * + */ +LSTATUS WINAPI RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey) +{ + LONG ret; + DWORD dwMaxSubkeyLen, dwMaxValueLen; + DWORD dwMaxLen, dwSize; + WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf; + HKEY hSubKey = hKey; + + if(lpszSubKey) + { + ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey); + if (ret) return ret; + } + + /* Get highest length for keys, values */ + ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL, + &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL); + if (ret) goto cleanup; + + dwMaxSubkeyLen++; + dwMaxValueLen++; + dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen); + if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR)) + { + /* Name too big: alloc a buffer for it */ + if (!(lpszName = heap_alloc( dwMaxLen*sizeof(WCHAR)))) + { + ret = ERROR_NOT_ENOUGH_MEMORY; + goto cleanup; + } + } + + + /* Recursively delete all the subkeys */ + while (TRUE) + { + dwSize = dwMaxLen; + if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL, + NULL, NULL, NULL)) break; + + ret = RegDeleteTreeW(hSubKey, lpszName); + if (ret) goto cleanup; + } + + if (lpszSubKey) + ret = RegDeleteKeyW(hKey, lpszSubKey); + else + while (TRUE) + { + dwSize = dwMaxLen; + if (RegEnumValueW(hKey, 0, lpszName, &dwSize, + NULL, NULL, NULL, NULL)) break; + + ret = RegDeleteValueW(hKey, lpszName); + if (ret) goto cleanup; + } + +cleanup: + /* Free buffer if allocated */ + if (lpszName != szNameBuf) + heap_free( lpszName); + if(lpszSubKey) + RegCloseKey(hSubKey); + return ret; +} + +/****************************************************************************** + * RegDeleteTreeA [ADVAPI32.@] + * + */ +LSTATUS WINAPI RegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey) +{ + LONG ret; + UNICODE_STRING lpszSubKeyW; + + if (lpszSubKey) RtlCreateUnicodeStringFromAsciiz( &lpszSubKeyW, lpszSubKey); + else lpszSubKeyW.Buffer = NULL; + ret = RegDeleteTreeW( hKey, lpszSubKeyW.Buffer); + RtlFreeUnicodeString( &lpszSubKeyW ); + return ret; +} diff --git a/reactos/dll/win32/advapi32_vista/advapi32_vista.h b/reactos/dll/win32/advapi32_vista/advapi32_vista.h new file mode 100644 index 00000000000..33c480e1c35 --- /dev/null +++ b/reactos/dll/win32/advapi32_vista/advapi32_vista.h @@ -0,0 +1,12 @@ + +#pragma once + +/* PSDK/NDK Headers */ +#define WIN32_NO_STATUS +#include +#include +#include + +#include + +/* EOF */ diff --git a/reactos/dll/win32/advapi32_vista/advapi32_vista.spec b/reactos/dll/win32/advapi32_vista/advapi32_vista.spec new file mode 100644 index 00000000000..4ba49c3270a --- /dev/null +++ b/reactos/dll/win32/advapi32_vista/advapi32_vista.spec @@ -0,0 +1,3 @@ + +@ stdcall RegDeleteTreeA(long str) +@ stdcall RegDeleteTreeW(long wstr)