[ADVAPI32_VISTA] Introduce this module to hold Vista+ exports that we need to provide...
authorAmine Khaldi <amine.khaldi@reactos.org>
Mon, 16 Nov 2015 21:53:56 +0000 (21:53 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Mon, 16 Nov 2015 21:53:56 +0000 (21:53 +0000)
svn path=/trunk/; revision=69903

reactos/dll/win32/CMakeLists.txt
reactos/dll/win32/advapi32_vista/CMakeLists.txt [new file with mode: 0644]
reactos/dll/win32/advapi32_vista/DllMain.c [new file with mode: 0644]
reactos/dll/win32/advapi32_vista/RegDeleteTree.c [new file with mode: 0644]
reactos/dll/win32/advapi32_vista/advapi32_vista.h [new file with mode: 0644]
reactos/dll/win32/advapi32_vista/advapi32_vista.spec [new file with mode: 0644]

index 97ea7c5..8bc2b62 100644 (file)
@@ -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 (file)
index 0000000..0b9d7a7
--- /dev/null
@@ -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 (file)
index 0000000..0902d84
--- /dev/null
@@ -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 (file)
index 0000000..0a9f619
--- /dev/null
@@ -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 (file)
index 0000000..33c480e
--- /dev/null
@@ -0,0 +1,12 @@
+
+#pragma once
+
+/* PSDK/NDK Headers */
+#define WIN32_NO_STATUS
+#include <windef.h>
+#include <winbase.h>
+#include <winreg.h>
+
+#include <ndk/rtlfuncs.h>
+
+/* 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 (file)
index 0000000..4ba49c3
--- /dev/null
@@ -0,0 +1,3 @@
+
+@ stdcall RegDeleteTreeA(long str)
+@ stdcall RegDeleteTreeW(long wstr)