Index: /trunk/include/iprt/ldr.h
===================================================================
--- /trunk/include/iprt/ldr.h	(revision 46592)
+++ /trunk/include/iprt/ldr.h	(revision 46593)
@@ -195,7 +195,32 @@
  * resolution of subsequently loaded libraries. */
 #define RTLDRLOAD_FLAGS_GLOBAL      RT_BIT_32(0)
+/** Do not unload the library upon RTLdrClose. (For system libs.) */
+#define RTLDRLOAD_FLAGS_NO_UNLOAD   RT_BIT_32(1)
 /** The mask of valid flag bits. */
-#define RTLDRLOAD_FLAGS_VALID_MASK  UINT32_C(0x00000001)
+#define RTLDRLOAD_FLAGS_VALID_MASK  UINT32_C(0x00000003)
 /** @} */
+
+/**
+ * Loads a dynamic load library (/shared object) image file residing in one of
+ * the default system library locations.
+ *
+ * Only the system library locations are searched. No suffix is required.
+ *
+ * @returns iprt status code.
+ * @param   pszFilename Image filename. No path.
+ * @param   fNoUnload   Do not unload the library when RTLdrClose is called.
+ * @param   phLdrMod    Where to store the handle to the loaded module.
+ */
+RTDECL(int) RTLdrLoadSystem(const char *pszFilename, bool fNoUnload, PRTLDRMOD phLdrMod);
+
+/**
+ * Combines RTLdrLoadSystem and RTLdrGetSymbol, with fNoUnload set to true.
+ *
+ * @returns The symbol value, NULL on failure.  (If you care for a less boolean
+ *          status, go thru the necessary API calls yourself.)
+ * @param   pszFilename Image filename. No path.
+ * @param   pszSymbol       Symbol name.
+ */
+RTDECL(void *) RTLdrGetSystemSymbol(const char *pszFilename, const char *pszSymbol);
 
 /**
@@ -210,4 +235,14 @@
  */
 RTDECL(int) RTLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
+
+/**
+ * Gets the native module handle for a module loaded by RTLdrLoad, RTLdrLoadEx,
+ * RTLdrLoadSystem,  or RTLdrLoadAppPriv.
+ *
+ * @returns Native handle on success, ~(uintptr_t)0 on failure.
+ * @param   hLdrMod     The loader module handle.
+ */
+RTDECL(uintptr_t) RTLdrGetNativeHandle(RTLDRMOD hLdrMod);
+
 
 /**
@@ -359,4 +394,17 @@
 RTDECL(int) RTLdrGetSymbolEx(RTLDRMOD hLdrMod, const void *pvBits, RTLDRADDR BaseAddress, const char *pszSymbol,
                              PRTLDRADDR pValue);
+
+
+/**
+ * Gets the address of a named exported function.
+ *
+ * Same as RTLdrGetSymbol, but skips the status code and pointer to return
+ * variable stuff.
+ *
+ * @returns Pointer to the function if found, NULL if not.
+ * @param   hLdrMod         The loader module handle.
+ * @param   pszSymbol       Function name.
+ */
+RTDECL(PFNRT) RTLdrGetFunction(RTLDRMOD hLdrMod, const char *pszSymbol);
 
 /**
Index: /trunk/include/iprt/mangling.h
===================================================================
--- /trunk/include/iprt/mangling.h	(revision 46592)
+++ /trunk/include/iprt/mangling.h	(revision 46593)
@@ -632,7 +632,10 @@
 # define RTLdrGetEndian                                 RT_MANGLER(RTLdrGetEndian)
 # define RTLdrGetFormat                                 RT_MANGLER(RTLdrGetFormat)
+# define RTLdrGetFunction                               RT_MANGLER(RTLdrGetFunction)
+# define RTLdrGetNativeHandle                           RT_MANGLER(RTLdrGetNativeHandle)
 # define RTLdrGetSuff                                   RT_MANGLER(RTLdrGetSuff)
 # define RTLdrGetSymbol                                 RT_MANGLER(RTLdrGetSymbol)
 # define RTLdrGetSymbolEx                               RT_MANGLER(RTLdrGetSymbolEx)
+# define RTLdrGetSystemSymbol                           RT_MANGLER(RTLdrGetSystemSymbol)
 # define RTLdrGetType                                   RT_MANGLER(RTLdrGetType)
 # define RTLdrIsLoadable                                RT_MANGLER(RTLdrIsLoadable)
@@ -642,4 +645,5 @@
 # define RTLdrLoadAppPriv                               RT_MANGLER(RTLdrLoadAppPriv)
 # define RTLdrLoadEx                                    RT_MANGLER(RTLdrLoadEx)
+# define RTLdrLoadSystem                                RT_MANGLER(RTLdrLoadSystem)
 # define RTLdrOpen                                      RT_MANGLER(RTLdrOpen)
 # define RTLdrOpenInMemory                              RT_MANGLER(RTLdrOpenInMemory)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 46593)
@@ -1800,5 +1800,5 @@
             vboxVDbgVEHandlerRegister();
 #endif
-            int rc = RTR3InitDll(0);
+            int rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
             AssertRC(rc);
             if (RT_SUCCESS(rc))
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp	(revision 46593)
@@ -28,16 +28,36 @@
 }
 
+/**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+    {
+        SetLastError(ERROR_FILENAME_EXCED_RANGE);
+        return NULL;
+    }
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
+}
 
 HRESULT VBoxDispD3DOpen(VBOXDISPD3D *pD3D)
 {
 #ifdef VBOX_WDDM_WOW64
-    pD3D->hD3DLib = LoadLibraryW(L"VBoxD3D9wddm-x86.dll");
+    pD3D->hD3DLib = loadSystemDll("VBoxD3D9wddm-x86.dll");
 #else
-    pD3D->hD3DLib = LoadLibraryW(L"VBoxD3D9wddm.dll");
+    pD3D->hD3DLib = loadSystemDll("VBoxD3D9wddm.dll");
 #endif
     if (!pD3D->hD3DLib)
     {
         DWORD winErr = GetLastError();
-        WARN((__FUNCTION__": LoadLibraryW failed, winErr = (%d)", winErr));
+        WARN((__FUNCTION__": LoadLibrary failed, winErr = (%d)", winErr));
         return E_FAIL;
     }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispKmt.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispKmt.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispKmt.cpp	(revision 46593)
@@ -23,4 +23,22 @@
 #endif
 
+/**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+        return NULL;
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
+}
+
 HRESULT vboxDispKmtCallbacksInit(PVBOXDISPKMT_CALLBACKS pCallbacks)
 {
@@ -29,5 +47,5 @@
     memset(pCallbacks, 0, sizeof (*pCallbacks));
 
-    pCallbacks->hGdi32 = LoadLibraryW(L"gdi32.dll");
+    pCallbacks->hGdi32 = loadSystemDll("gdi32.dll");
     if (pCallbacks->hGdi32 != NULL)
     {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxScreen.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxScreen.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxScreen.cpp	(revision 46593)
@@ -1,4 +1,3 @@
 /* $Id$ */
-
 /** @file
  * VBoxVideo Display D3D User mode dll
@@ -6,5 +5,5 @@
 
 /*
- * Copyright (C) 2011-2012 Oracle Corporation
+ * Copyright (C) 2011-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -341,4 +340,22 @@
 }
 
+/**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+        return NULL;
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
+}
+
 //HRESULT vboxScreenMonInit(PVBOXSCREENMON pMon)
 HRESULT vboxScreenMonInit()
@@ -351,5 +368,5 @@
     pMon->LoData.ScreenLayout.EscapeHdr.escapeCode = VBOXESC_SCREENLAYOUT;
 
-    pMon->hGdi32 = LoadLibraryW(L"gdi32.dll");
+    pMon->hGdi32 = loadSystemDll("gdi32.dll");
     if (pMon->hGdi32 != NULL)
     {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/switcher/sw_common.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/switcher/sw_common.c	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/switcher/sw_common.c	(revision 46593)
@@ -1,4 +1,3 @@
 /* $Id$ */
-
 /** @file
  * VBox D3D8/9 dll switcher
@@ -6,5 +5,5 @@
 
 /*
- * Copyright (C) 2009-2012 Oracle Corporation
+ * Copyright (C) 2009-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -23,4 +22,22 @@
 static char* gsBlackListDll[] = {"awt.dll", "wpfgfx_v0400.dll", "wpfgfx_v0300.dll", NULL};
 
+/**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+        return NULL;
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
+}
+
 /* Checks if 3D is enabled for VM and it works on host machine */
 BOOL isVBox3DEnabled(void)
@@ -31,7 +48,7 @@
 
 #ifdef VBOX_WDDM_WOW64
-    hDLL = LoadLibrary("VBoxOGL-x86.dll");
+    hDLL = loadSystemDll("VBoxOGL-x86.dll");
 #else
-    hDLL = LoadLibrary("VBoxOGL.dll");
+    hDLL = loadSystemDll("VBoxOGL.dll");
 #endif
 
@@ -66,6 +83,6 @@
     int i;
 
-	if (!GetModuleFileName(NULL, name, 1000))
-		return TRUE;
+    if (!GetModuleFileName(NULL, name, 1000))
+        return TRUE;
 
     /*Extract filename*/
@@ -108,12 +125,10 @@
 
     if (isVBox3DEnabled() && checkOptions())
-    {
         dllName = vboxName;
-    } else
-    {
+    else
         dllName = msName;
-    }
 
-    hDLL = LoadLibrary(dllName);
+    hDLL = loadSystemDll(dllName);
     FillD3DExports(hDLL); 
 }
+
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 46593)
@@ -5308,4 +5308,22 @@
 }
 
+/**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+        return NULL;
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
+}
+
 static BOOL InitAdapters(IWineD3DImpl *This)
 {
@@ -5323,20 +5341,20 @@
     if(!mod_gl) {
 #ifdef USE_WIN32_OPENGL
-#define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
-#if defined(VBOX_WITH_WDDM) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
+# define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
+# if defined(VBOX_WITH_WDDM) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
         BOOL (APIENTRY *pDrvValidateVersion)(DWORD) DECLSPEC_HIDDEN;
-#ifdef VBOX_WDDM_WOW64
-        mod_gl = LoadLibraryA("VBoxOGL-x86.dll");
-#else
-        mod_gl = LoadLibraryA("VBoxOGL.dll");
-#endif
-#else
-        mod_gl = LoadLibraryA("opengl32.dll");
-#endif
+#  ifdef VBOX_WDDM_WOW64
+        mod_gl = loadSystemDll("VBoxOGL-x86.dll");
+#  else
+        mod_gl = loadSystemDll("VBoxOGL.dll");
+#  endif
+# else
+        mod_gl = loadSystemDll("opengl32.dll");
+# endif
         if(!mod_gl) {
             ERR("Can't load opengl32.dll!\n");
             goto nogl_adapter;
         }
-#if defined(VBOX_WITH_WDDM) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
+# if defined(VBOX_WITH_WDDM) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
         /* init properly */
         pDrvValidateVersion = (void*)GetProcAddress(mod_gl, "DrvValidateVersion");
@@ -5349,7 +5367,7 @@
             goto nogl_adapter;
         }
-#endif
+# endif
 #else
-#define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
+# define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
         /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
         mod_gl = GetModuleHandleA("gdi32.dll");
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/switcher/sw_common.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/switcher/sw_common.c	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/switcher/sw_common.c	(revision 46593)
@@ -1,4 +1,3 @@
 /* $Id$ */
-
 /** @file
  * VBox D3D8/9 dll switcher
@@ -6,5 +5,5 @@
 
 /*
- * Copyright (C) 2009 Oracle Corporation
+ * Copyright (C) 2009-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -23,4 +22,22 @@
 static char* gsBlackListDll[] = {"awt.dll", "wpfgfx_v0400.dll", "wpfgfx_v0300.dll", NULL};
 
+/**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+        return NULL;
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
+}
+
 /* Checks if 3D is enabled for VM and it works on host machine */
 BOOL isVBox3DEnabled(void)
@@ -31,7 +48,7 @@
 
 #ifdef VBOX_WDDM_WOW64
-    hDLL = LoadLibrary("VBoxOGL-x86.dll");
+    hDLL = loadSystemDll("VBoxOGL-x86.dll");
 #else
-    hDLL = LoadLibrary("VBoxOGL.dll");
+    hDLL = loadSystemDll("VBoxOGL.dll");
 #endif
 
@@ -108,12 +125,10 @@
 
     if (isVBox3DEnabled() && checkOptions())
-    {
         dllName = vboxName;
-    } else
-    {
+    else
         dllName = msName;
-    }
 
-    hDLL = LoadLibrary(dllName);
+    hDLL = loadSystemDll(dllName);
     FillD3DExports(hDLL); 
 }
+
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/directx.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/directx.c	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/directx.c	(revision 46593)
@@ -5121,4 +5121,22 @@
 }
 
+/**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+        return NULL;
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
+}
+
 /* Do not call while under the GL lock. */
 static BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, UINT ordinal)
@@ -5142,13 +5160,13 @@
 #ifdef USE_WIN32_OPENGL
     {
-#ifndef VBOX
+# ifndef VBOX
         HMODULE mod_gl = GetModuleHandleA("opengl32.dll");
-#else
+# else
         BOOL (APIENTRY *pDrvValidateVersion)(DWORD) DECLSPEC_HIDDEN;
-# ifdef VBOX_WDDM_WOW64
-        HMODULE mod_gl = LoadLibraryA("VBoxOGL-x86.dll");
-# else
-        HMODULE mod_gl = LoadLibraryA("VBoxOGL.dll");
-# endif
+#  ifdef VBOX_WDDM_WOW64
+        HMODULE mod_gl = loadSystemDll("VBoxOGL-x86.dll");
+#  else
+        HMODULE mod_gl = loadSystemDll("VBoxOGL.dll");
+#  endif
         if (!mod_gl)
         {
@@ -5169,11 +5187,11 @@
         }
 
-# define VBOX_USE_FUNC(f) p##f = (void *)GetProcAddress(mod_gl, #f);
+#  define VBOX_USE_FUNC(f) p##f = (void *)GetProcAddress(mod_gl, #f);
         VBOX_GL_FUNCS_GEN
-# undef VBOX_USE_FUNC
-#endif
-#define USE_GL_FUNC(f) gl_info->gl_ops.gl.p_##f = (void *)GetProcAddress(mod_gl, #f);
+#  undef VBOX_USE_FUNC
+# endif
+# define USE_GL_FUNC(f) gl_info->gl_ops.gl.p_##f = (void *)GetProcAddress(mod_gl, #f);
         ALL_WGL_FUNCS
-#undef USE_GL_FUNC
+# undef USE_GL_FUNC
         gl_info->gl_ops.wgl.p_wglSwapBuffers = (void *)GetProcAddress(mod_gl, "wglSwapBuffers");
     }
Index: /trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/VBoxGuestInstallHelper.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/VBoxGuestInstallHelper.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/VBoxGuestInstallHelper.cpp	(revision 46593)
@@ -197,4 +197,22 @@
 
 /**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+        return NULL;
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
+}
+
+/**
  * Disables the Windows File Protection for a specified file
  * using an undocumented SFC API call. Don't try this at home!
@@ -214,5 +232,5 @@
     if (SUCCEEDED(hr))
     {
-        HMODULE hSFC = LoadLibrary("sfc_os.dll");
+        HMODULE hSFC = loadSystemDll("sfc_os.dll");
         if (NULL != hSFC)
         {
Index: /trunk/src/VBox/Additions/WINNT/Installer/VBoxDrvInst.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Installer/VBoxDrvInst.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/Installer/VBoxDrvInst.cpp	(revision 46593)
@@ -130,4 +130,22 @@
      if (pCallbackContext)
          fwprintf((FILE*)pCallbackContext, _T("(%u) %u - %s\n"), Event, dwError, pEventDescription);
+}
+
+/**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+        return NULL;
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
 }
 
@@ -146,5 +164,5 @@
 {
     HRESULT hr = S_OK;
-    HMODULE hDIFxAPI = LoadLibrary(_T("DIFxAPI.dll"));
+    HMODULE hDIFxAPI = loadSystemDll("DIFxAPI.dll");
     if (NULL == hDIFxAPI)
     {
Index: /trunk/src/VBox/Additions/WINNT/SharedFolders/np/vboxmrxnp.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/SharedFolders/np/vboxmrxnp.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/SharedFolders/np/vboxmrxnp.cpp	(revision 46593)
@@ -1598,5 +1598,5 @@
     {
         case DLL_PROCESS_ATTACH:
-            RTR3InitDll(0);
+            RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
             VbglR3Init();
             LogRel(("VBOXNP: DLL loaded.\n"));
Index: /trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp	(revision 46593)
@@ -363,5 +363,5 @@
         case DLL_PROCESS_ATTACH:
         {
-            int rc = RTR3InitDll(0 /* Flags */);
+            int rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
             if (RT_SUCCESS(rc))
                 rc = VbglR3Init();
Index: /trunk/src/VBox/Additions/WINNT/VBoxGINA/VBoxGINA.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxGINA/VBoxGINA.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/VBoxGINA/VBoxGINA.cpp	(revision 46593)
@@ -20,4 +20,5 @@
 #include <iprt/buildconfig.h>
 #include <iprt/initterm.h>
+#include <iprt/ldr.h>
 
 #include <VBox/VBoxGuestLib.h>
@@ -83,5 +84,5 @@
         case DLL_PROCESS_ATTACH:
         {
-            RTR3InitDll(0 /* Flags */);
+            RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
             VbglR3Init();
 
@@ -115,12 +116,12 @@
                          DWORD *pdwDllVersion)
 {
-    HINSTANCE hDll;
-
     VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: dwWinlogonVersion: %ld\n", dwWinlogonVersion);
 
     /* Load the standard Microsoft GINA DLL. */
-    if (!(hDll = LoadLibrary(TEXT("MSGINA.DLL"))))
-    {
-        VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed loading MSGINA! Last error=%ld\n", GetLastError());
+    RTLDRMOD hLdrMod;
+    int rc = RTLdrLoadSystem("MSGINA.DLL", true /*fNoUnload*/, &hLdrMod);
+    if (RT_FAILURE(rc))
+    {
+        VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: failed loading MSGINA! rc=%Rrc\n", rc);
         return FALSE;
     }
@@ -129,5 +130,5 @@
      * Now get the entry points of the MSGINA
      */
-    GWlxNegotiate = (PGWLXNEGOTIATE)GetProcAddress(hDll, "WlxNegotiate");
+    GWlxNegotiate = (PGWLXNEGOTIATE)RTLdrGetFunction(hLdrMod, "WlxNegotiate");
     if (!GWlxNegotiate)
     {
@@ -135,5 +136,5 @@
         return FALSE;
     }
-    GWlxInitialize = (PGWLXINITIALIZE)GetProcAddress(hDll, "WlxInitialize");
+    GWlxInitialize = (PGWLXINITIALIZE)RTLdrGetFunction(hLdrMod, "WlxInitialize");
     if (!GWlxInitialize)
     {
@@ -142,5 +143,5 @@
     }
     GWlxDisplaySASNotice =
-        (PGWLXDISPLAYSASNOTICE)GetProcAddress(hDll, "WlxDisplaySASNotice");
+        (PGWLXDISPLAYSASNOTICE)RTLdrGetFunction(hLdrMod, "WlxDisplaySASNotice");
     if (!GWlxDisplaySASNotice)
     {
@@ -149,5 +150,5 @@
     }
     GWlxLoggedOutSAS =
-        (PGWLXLOGGEDOUTSAS)GetProcAddress(hDll, "WlxLoggedOutSAS");
+        (PGWLXLOGGEDOUTSAS)RTLdrGetFunction(hLdrMod, "WlxLoggedOutSAS");
     if (!GWlxLoggedOutSAS)
     {
@@ -156,5 +157,5 @@
     }
     GWlxActivateUserShell =
-        (PGWLXACTIVATEUSERSHELL)GetProcAddress(hDll, "WlxActivateUserShell");
+        (PGWLXACTIVATEUSERSHELL)RTLdrGetFunction(hLdrMod, "WlxActivateUserShell");
     if (!GWlxActivateUserShell)
     {
@@ -163,5 +164,5 @@
     }
     GWlxLoggedOnSAS =
-        (PGWLXLOGGEDONSAS)GetProcAddress(hDll, "WlxLoggedOnSAS");
+        (PGWLXLOGGEDONSAS)RTLdrGetFunction(hLdrMod, "WlxLoggedOnSAS");
     if (!GWlxLoggedOnSAS)
     {
@@ -170,5 +171,5 @@
     }
     GWlxDisplayLockedNotice =
-        (PGWLXDISPLAYLOCKEDNOTICE)GetProcAddress(hDll, "WlxDisplayLockedNotice");
+        (PGWLXDISPLAYLOCKEDNOTICE)RTLdrGetFunction(hLdrMod, "WlxDisplayLockedNotice");
     if (!GWlxDisplayLockedNotice)
     {
@@ -176,5 +177,5 @@
         return FALSE;
     }
-    GWlxIsLockOk = (PGWLXISLOCKOK)GetProcAddress(hDll, "WlxIsLockOk");
+    GWlxIsLockOk = (PGWLXISLOCKOK)RTLdrGetFunction(hLdrMod, "WlxIsLockOk");
     if (!GWlxIsLockOk)
     {
@@ -183,5 +184,5 @@
     }
     GWlxWkstaLockedSAS =
-        (PGWLXWKSTALOCKEDSAS)GetProcAddress(hDll, "WlxWkstaLockedSAS");
+        (PGWLXWKSTALOCKEDSAS)RTLdrGetFunction(hLdrMod, "WlxWkstaLockedSAS");
     if (!GWlxWkstaLockedSAS)
     {
@@ -189,5 +190,5 @@
         return FALSE;
     }
-    GWlxIsLogoffOk = (PGWLXISLOGOFFOK)GetProcAddress(hDll, "WlxIsLogoffOk");
+    GWlxIsLogoffOk = (PGWLXISLOGOFFOK)RTLdrGetFunction(hLdrMod, "WlxIsLogoffOk");
     if (!GWlxIsLogoffOk)
     {
@@ -195,5 +196,5 @@
         return FALSE;
     }
-    GWlxLogoff = (PGWLXLOGOFF)GetProcAddress(hDll, "WlxLogoff");
+    GWlxLogoff = (PGWLXLOGOFF)RTLdrGetFunction(hLdrMod, "WlxLogoff");
     if (!GWlxLogoff)
     {
@@ -201,5 +202,5 @@
         return FALSE;
     }
-    GWlxShutdown = (PGWLXSHUTDOWN)GetProcAddress(hDll, "WlxShutdown");
+    GWlxShutdown = (PGWLXSHUTDOWN)RTLdrGetFunction(hLdrMod, "WlxShutdown");
     if (!GWlxShutdown)
     {
@@ -208,16 +209,16 @@
     }
     /* GINA 1.1, optional */
-    GWlxStartApplication = (PGWLXSTARTAPPLICATION)GetProcAddress(hDll, "WlxStartApplication");
-    GWlxScreenSaverNotify = (PGWLXSCREENSAVERNOTIFY)GetProcAddress(hDll, "WlxScreenSaverNotify");
+    GWlxStartApplication = (PGWLXSTARTAPPLICATION)RTLdrGetFunction(hLdrMod, "WlxStartApplication");
+    GWlxScreenSaverNotify = (PGWLXSCREENSAVERNOTIFY)RTLdrGetFunction(hLdrMod, "WlxScreenSaverNotify");
     /* GINA 1.3, optional */
-    GWlxNetworkProviderLoad = (PGWLXNETWORKPROVIDERLOAD)GetProcAddress( hDll, "WlxNetworkProviderLoad");
-    GWlxDisplayStatusMessage = (PGWLXDISPLAYSTATUSMESSAGE)GetProcAddress( hDll, "WlxDisplayStatusMessage");
-    GWlxGetStatusMessage = (PGWLXGETSTATUSMESSAGE)GetProcAddress( hDll, "WlxGetStatusMessage");
-    GWlxRemoveStatusMessage = (PGWLXREMOVESTATUSMESSAGE)GetProcAddress( hDll, "WlxRemoveStatusMessage");
+    GWlxNetworkProviderLoad = (PGWLXNETWORKPROVIDERLOAD)RTLdrGetFunction(hLdrMod, "WlxNetworkProviderLoad");
+    GWlxDisplayStatusMessage = (PGWLXDISPLAYSTATUSMESSAGE)RTLdrGetFunction(hLdrMod, "WlxDisplayStatusMessage");
+    GWlxGetStatusMessage = (PGWLXGETSTATUSMESSAGE)RTLdrGetFunction(hLdrMod, "WlxGetStatusMessage");
+    GWlxRemoveStatusMessage = (PGWLXREMOVESTATUSMESSAGE)RTLdrGetFunction(hLdrMod, "WlxRemoveStatusMessage");
     /* GINA 1.4, optional */
     GWlxGetConsoleSwitchCredentials =
-        (PGWLXGETCONSOLESWITCHCREDENTIALS)GetProcAddress(hDll, "WlxGetConsoleSwitchCredentials");
-    GWlxReconnectNotify = (PGWLXRECONNECTNOTIFY)GetProcAddress(hDll, "WlxReconnectNotify");
-    GWlxDisconnectNotify = (PGWLXDISCONNECTNOTIFY)GetProcAddress(hDll, "WlxDisconnectNotify");
+        (PGWLXGETCONSOLESWITCHCREDENTIALS)RTLdrGetFunction(hLdrMod, "WlxGetConsoleSwitchCredentials");
+    GWlxReconnectNotify = (PGWLXRECONNECTNOTIFY)RTLdrGetFunction(hLdrMod, "WlxReconnectNotify");
+    GWlxDisconnectNotify = (PGWLXDISCONNECTNOTIFY)RTLdrGetFunction(hLdrMod, "WlxDisconnectNotify");
     VBoxGINAVerbose(0, "VBoxGINA::WlxNegotiate: optional function pointers:\n"
                     "  WlxStartApplication: %p\n"
Index: /trunk/src/VBox/Additions/WINNT/VBoxMMR/dllmain.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxMMR/dllmain.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/VBoxMMR/dllmain.cpp	(revision 46593)
@@ -45,5 +45,5 @@
             if (isWMP)
             {
-                RTR3InitDll(0);
+                RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
                 VbglR3Init();
                 VBoxMMRHookLog("VBoxMMR: Hooking wmplayer process\n");
Index: /trunk/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.cpp	(revision 46593)
@@ -1343,17 +1343,27 @@
 }
 
-void InstallHooksForModule(const char *pszName, HookEntry hooks[])
-{
-    HMODULE hMod = LoadLibraryA(pszName);
-    if (hMod != NULL)
-    {
-        VBoxMMRHookLog("VBoxMMR: Hooking %s -> %x \n", pszName, hMod);
-        const IMAGE_IMPORT_DESCRIPTOR *pDescriptor = GetImportDescriptor(hMod);
-        InstallHooks(pDescriptor, (PBYTE) hMod, hooks);
+void InstallHooksForSystemModule(const char *pszName, HookEntry hooks[])
+{
+    /* Construct the full path to the given module and load it. */
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, MAX_PATH);
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName <= sizeof(szPath))
+    {
+        szPath[cchPath] = '\\';
+        memcpy(&szPath[cchPath + 1], pszName, cbName);
+
+        HMODULE hMod = LoadLibraryA(szPath);
+        if (hMod != NULL)
+        {
+            VBoxMMRHookLog("VBoxMMR: Hooking %s -> %x \n", pszName, hMod);
+            const IMAGE_IMPORT_DESCRIPTOR *pDescriptor = GetImportDescriptor(hMod);
+            InstallHooks(pDescriptor, (PBYTE) hMod, hooks);
+        }
+        else
+            VBoxMMRHookLog("VBoxMMR: Error hooking %s -> not found (last error %u)\n", pszName, GetLastError());
     }
     else
-    {
         VBoxMMRHookLog("VBoxMMR: Error hooking %s -> not found\n", pszName);
-    }
 }
 
@@ -1382,10 +1392,10 @@
         }
 
-        InstallHooksForModule("winmm.dll", g_WinMMHooks);
-        InstallHooksForModule("tsmf.dll", g_TSMFHooks);
-        InstallHooksForModule("DSHOWRDPFILTER.dll", g_TSMFHooks);
-        InstallHooksForModule("MSMPEG2VDEC.dll", g_DShowHooks);
-        InstallHooksForModule("MFDS.dll", g_DShowHooks);
-        InstallHooksForModule("mf.dll", g_MFHooks);
+        InstallHooksForSystemModule("winmm.dll", g_WinMMHooks);
+        InstallHooksForSystemModule("tsmf.dll", g_TSMFHooks);
+        InstallHooksForSystemModule("DSHOWRDPFILTER.dll", g_TSMFHooks);
+        InstallHooksForSystemModule("MSMPEG2VDEC.dll", g_DShowHooks);
+        InstallHooksForSystemModule("MFDS.dll", g_DShowHooks);
+        InstallHooksForSystemModule("mf.dll", g_MFHooks);
 
         ULONG ret = RegisterTraceGuids(
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxLA.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxLA.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxLA.cpp	(revision 46593)
@@ -27,4 +27,5 @@
 #include <iprt/alloc.h>
 #include <iprt/list.h>
+#include <iprt/ldr.h>
 
 #define LALOG(a) do { if (gCtx.fLogEnabled) LogRel(a); } while(0)
@@ -87,6 +88,4 @@
         char *pszPropWaitPattern; /* Which properties are monitored. */
     } activeClient;
-
-    HMODULE hModuleKernel32;
 
     BOOL (WINAPI * pfnProcessIdToSessionId)(DWORD dwProcessId, DWORD *pSessionId);
@@ -1250,14 +1249,5 @@
     RT_ZERO(gCtx.activeClient);
 
-    gCtx.hModuleKernel32 = LoadLibrary("KERNEL32");
-
-    if (gCtx.hModuleKernel32)
-    {
-        *(uintptr_t *)&gCtx.pfnProcessIdToSessionId = (uintptr_t)GetProcAddress(gCtx.hModuleKernel32, "ProcessIdToSessionId");
-    }
-    else
-    {
-        gCtx.pfnProcessIdToSessionId = NULL;
-    }
+    *(void **)&gCtx.pfnProcessIdToSessionId = RTLdrGetSystemSymbol("KERNEL32", "ProcessIdToSessionId");
     *pfStartThread = true;
     *ppInstance = &gCtx;
@@ -1280,10 +1270,5 @@
     ActionExecutorDeleteActions(&pCtx->listDetachActions);
 
-    if (pCtx->hModuleKernel32)
-    {
-        FreeLibrary(pCtx->hModuleKernel32);
-        pCtx->pfnProcessIdToSessionId = NULL;
-    }
-    pCtx->hModuleKernel32 = NULL;
+    pCtx->pfnProcessIdToSessionId = NULL;
 }
 
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxMMR.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxMMR.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxMMR.cpp	(revision 46593)
@@ -18,8 +18,9 @@
 #include "VBoxTray.h"
 #include "VBoxMMR.h"
+#include <iprt/ldr.h>
 
 struct VBOXMMRCONTEXT
 {
-    HINSTANCE hMod;
+    RTLDRMOD  hModHook;
     HHOOK     hHook;
 };
@@ -32,15 +33,15 @@
 void VBoxMMRCleanup(VBOXMMRCONTEXT *pCtx)
 {
-    if (NULL != pCtx->hHook)
+    if (pCtx->hHook)
     {
         UnhookWindowsHookEx(pCtx->hHook);
+        pCtx->hHook = NULL;
     }
 
-    if (pCtx->hMod)
+    if (pCtx->hModHook != NIL_RTLDRMOD)
     {
-        FreeLibrary(pCtx->hMod);
+        RTLdrClose(pCtx->hModHook);
+        pCtx->hModHook = NIL_RTLDRMOD;
     }
-
-    return;
 }
 
@@ -50,36 +51,36 @@
     bool *pfStartThread)
 {
-    HOOKPROC pHook = NULL;
-
     LogRel2(("VBoxMMR: Initializing\n"));
 
-    gCtx.hMod = LoadLibraryA(g_pszMMRDLL);
-    if (NULL == gCtx.hMod)
+    int rc = RTLdrLoadAppPriv(g_pszMMRDLL, &gCtx.hModHook);
+    if (RT_SUCCESS(rc))
     {
-        LogRel2(("VBoxMMR: Hooking library not found\n"));
-        VBoxMMRCleanup(&gCtx);
-        return VERR_NOT_FOUND;
+        HOOKPROC pHook = (HOOKPROC)RTLdrGetFunction(gCtx.hModHook, g_pszMMRPROC);
+        if (pHook)
+        {
+            HMODULE hMod = (HMODULE)RTLdrGetNativeHandle(gCtx.hModHook);
+            Assert(hMod != (HMODULE)~(uintptr_t)0);
+            gCtx.hHook = SetWindowsHookEx(WH_CBT, pHook, hMod, 0);
+            if (gCtx.hHook)
+            {
+                *ppInstance = &gCtx;
+                return VINF_SUCCESS;
+            }
+
+            rc = RTErrConvertFromWin32(GetLastError());
+            LogRel2(("VBoxMMR: Error installing hooking proc: %Rrc\n", rc));
+        }
+        else
+        {
+            LogRel2(("VBoxMMR: Hooking proc not found\n"));
+            rc = VERR_NOT_FOUND;
+        }
     }
+    else
+        LogRel2(("VBoxMMR: Hooking library not found (%Rrc)\n", rc));
 
-    pHook = (HOOKPROC) GetProcAddress(gCtx.hMod, g_pszMMRPROC);
-    if (NULL == pHook)
-    {
-        LogRel2(("VBoxMMR: Hooking proc not found\n"));
-        VBoxMMRCleanup(&gCtx);
-        return VERR_NOT_FOUND;
-    }
-
-    gCtx.hHook = SetWindowsHookEx(WH_CBT, pHook, gCtx.hMod, 0);
-    if (NULL == gCtx.hHook)
-    {
-        int rc = RTErrConvertFromWin32(GetLastError());
-        LogRel2(("VBoxMMR: Error installing hooking proc: %d\n", rc));
-        VBoxMMRCleanup(&gCtx);
-        return rc;
-    }
-
-    *ppInstance = &gCtx;
-
-    return VINF_SUCCESS;
+    RTLdrClose(gCtx.hModHook);
+    gCtx.hModHook = NIL_RTLDRMOD;
+    return rc;
 }
 
@@ -95,2 +96,3 @@
     return 0;
 }
+
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSeamless.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSeamless.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSeamless.cpp	(revision 46593)
@@ -25,4 +25,5 @@
 #include <VBox/VMMDev.h>
 #include <iprt/assert.h>
+#include <iprt/ldr.h>
 #include <VBoxGuestInternal.h>
 
@@ -31,5 +32,5 @@
     const VBOXSERVICEENV *pEnv;
 
-    HMODULE    hModule;
+    RTLDRMOD hModHook;
 
     BOOL    (* pfnVBoxHookInstallWindowTracker)(HMODULE hDll);
@@ -55,4 +56,5 @@
     *pfStartThread = false;
     gCtx.pEnv = pEnv;
+    gCtx.hModHook = NIL_RTLDRMOD;
 
     OSVERSIONINFO OSinfo;
@@ -72,9 +74,9 @@
     {
         /* Will fail if SetWinEventHook is not present (version < NT4 SP6 apparently) */
-        gCtx.hModule = LoadLibrary(VBOXHOOK_DLL_NAME);
-        if (gCtx.hModule)
-        {
-            *(uintptr_t *)&gCtx.pfnVBoxHookInstallWindowTracker = (uintptr_t)GetProcAddress(gCtx.hModule, "VBoxHookInstallWindowTracker");
-            *(uintptr_t *)&gCtx.pfnVBoxHookRemoveWindowTracker  = (uintptr_t)GetProcAddress(gCtx.hModule, "VBoxHookRemoveWindowTracker");
+        rc = RTLdrLoadAppPriv(VBOXHOOK_DLL_NAME, &gCtx.hModHook);
+        if (RT_SUCCESS(rc))
+        {
+            *(PFNRT *)&gCtx.pfnVBoxHookInstallWindowTracker = RTLdrGetFunction(gCtx.hModHook, "VBoxHookInstallWindowTracker");
+            *(PFNRT *)&gCtx.pfnVBoxHookRemoveWindowTracker  = RTLdrGetFunction(gCtx.hModHook, "VBoxHookRemoveWindowTracker");
 
             /* rc should contain success status */
@@ -90,8 +92,5 @@
         }
         else
-        {
-            rc = RTErrConvertFromWin32(GetLastError());
             Log(("VBoxTray: VBoxSeamlessInit: LoadLibrary of \"%s\" failed with rc=%Rrc\n", VBOXHOOK_DLL_NAME, rc));
-        }
     }
 
@@ -109,7 +108,9 @@
     if (gCtx.pfnVBoxHookRemoveWindowTracker)
         gCtx.pfnVBoxHookRemoveWindowTracker();
-    if (gCtx.hModule)
-        FreeLibrary(gCtx.hModule);
-    gCtx.hModule = 0;
+    if (gCtx.hModHook != NIL_RTLDRMOD)
+    {
+        RTLdrClose(gCtx.hModHook);
+        gCtx.hModHook = NIL_RTLDRMOD;
+    }
     return;
 }
@@ -122,5 +123,7 @@
         VBoxSeamlessCheckWindows();
 
-        gCtx.pfnVBoxHookInstallWindowTracker(gCtx.hModule);
+        HMODULE hMod = (HMODULE)RTLdrGetNativeHandle(gCtx.hModHook);
+        Assert(hMod != (HMODULE)~(uintptr_t)0);
+        gCtx.pfnVBoxHookInstallWindowTracker(hMod);
     }
 }
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp	(revision 46593)
@@ -41,4 +41,5 @@
 
 #include <iprt/buildconfig.h>
+#include <iprt/ldr.h>
 
 /* Default desktop state tracking */
@@ -63,5 +64,5 @@
  * of the window passed to vboxStInit */
 static int vboxStInit(HWND hWnd);
-static void vboxStTerm();
+static void vboxStTerm(void);
 /* @returns true on "IsActiveConsole" state change */
 static BOOL vboxStHandleEvent(WPARAM EventID, LPARAM SessionID);
@@ -549,12 +550,8 @@
         {
             BOOL (WINAPI * pfnConvertStringSecurityDescriptorToSecurityDescriptorA)(LPCSTR StringSecurityDescriptor, DWORD StringSDRevision, PSECURITY_DESCRIPTOR  *SecurityDescriptor, PULONG  SecurityDescriptorSize);
-
-            HMODULE hModule = LoadLibrary("ADVAPI32.DLL");
-            if (!hModule)
-            {
-                dwErr = GetLastError();
-                Log(("VBoxTray: Loading module ADVAPI32.DLL failed with last error = %08X\n", dwErr));
-            }
-            else
+            *(void **)&pfnConvertStringSecurityDescriptorToSecurityDescriptorA =
+                RTLdrGetSystemSymbol("ADVAPI32.DLL", "ConvertStringSecurityDescriptorToSecurityDescriptorA");
+            Log(("VBoxTray: pfnConvertStringSecurityDescriptorToSecurityDescriptorA = %x\n", pfnConvertStringSecurityDescriptorToSecurityDescriptorA));
+            if (pfnConvertStringSecurityDescriptorToSecurityDescriptorA)
             {
                 PSECURITY_DESCRIPTOR    pSD;
@@ -563,32 +560,26 @@
                 BOOL                    fSaclDefaulted = FALSE;
 
-                *(uintptr_t *)&pfnConvertStringSecurityDescriptorToSecurityDescriptorA = (uintptr_t)GetProcAddress(hModule, "ConvertStringSecurityDescriptorToSecurityDescriptorA");
-
-                Log(("VBoxTray: pfnConvertStringSecurityDescriptorToSecurityDescriptorA = %x\n", pfnConvertStringSecurityDescriptorToSecurityDescriptorA));
-                if (pfnConvertStringSecurityDescriptorToSecurityDescriptorA)
+                fRC = pfnConvertStringSecurityDescriptorToSecurityDescriptorA("S:(ML;;NW;;;LW)", /* this means "low integrity" */
+                                                                              SDDL_REVISION_1, &pSD, NULL);
+                if (!fRC)
                 {
-                    fRC = pfnConvertStringSecurityDescriptorToSecurityDescriptorA("S:(ML;;NW;;;LW)", /* this means "low integrity" */
-                                                                                  SDDL_REVISION_1, &pSD, NULL);
+                    dwErr = GetLastError();
+                    Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorA failed with last error = %08X\n", dwErr));
+                }
+                else
+                {
+                    fRC = GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted);
                     if (!fRC)
                     {
                         dwErr = GetLastError();
-                        Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorA failed with last error = %08X\n", dwErr));
+                        Log(("VBoxTray: GetSecurityDescriptorSacl failed with last error = %08X\n", dwErr));
                     }
                     else
                     {
-                        fRC = GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted);
+                        fRC = SetSecurityDescriptorSacl(SecAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE);
                         if (!fRC)
                         {
                             dwErr = GetLastError();
-                            Log(("VBoxTray: GetSecurityDescriptorSacl failed with last error = %08X\n", dwErr));
-                        }
-                        else
-                        {
-                            fRC = SetSecurityDescriptorSacl(SecAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE);
-                            if (!fRC)
-                            {
-                                dwErr = GetLastError();
-                                Log(("VBoxTray: SetSecurityDescriptorSacl failed with last error = %08X\n", dwErr));
-                            }
+                            Log(("VBoxTray: SetSecurityDescriptorSacl failed with last error = %08X\n", dwErr));
                         }
                     }
@@ -1015,5 +1006,5 @@
 {
     HWND hWTSAPIWnd;
-    HMODULE hWTSAPI32;
+    RTLDRMOD hLdrModWTSAPI32;
     BOOL fIsConsole;
     WTS_CONNECTSTATE_CLASS enmConnectState;
@@ -1032,7 +1023,9 @@
     USHORT *pProtocolType = NULL;
     DWORD cbBuf = 0;
-    if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSConnectState, (LPTSTR *)&penmConnectState, &cbBuf))
-    {
-        if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientProtocolType, (LPTSTR *)&pProtocolType, &cbBuf))
+    if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSConnectState,
+                                               (LPTSTR *)&penmConnectState, &cbBuf))
+    {
+        if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientProtocolType,
+                                                   (LPTSTR *)&pProtocolType, &cbBuf))
         {
             gVBoxSt.fIsConsole = (*pProtocolType == 0);
@@ -1040,10 +1033,8 @@
             return VINF_SUCCESS;
         }
-        else
-        {
-            DWORD dwErr = GetLastError();
-            WARN(("VBoxTray: WTSQuerySessionInformationA WTSClientProtocolType failed, error = %08X\n", dwErr));
-            rc = RTErrConvertFromWin32(dwErr);
-        }
+
+        DWORD dwErr = GetLastError();
+        WARN(("VBoxTray: WTSQuerySessionInformationA WTSClientProtocolType failed, error = %08X\n", dwErr));
+        rc = RTErrConvertFromWin32(dwErr);
     }
     else
@@ -1063,37 +1054,31 @@
 static int vboxStInit(HWND hWnd)
 {
-    int rc = VINF_SUCCESS;
-    memset(&gVBoxSt, 0, sizeof (gVBoxSt));
-    gVBoxSt.hWTSAPI32 = LoadLibrary("WTSAPI32.DLL");
-    if (gVBoxSt.hWTSAPI32)
-    {
-        *(uintptr_t *)&gVBoxSt.pfnWTSRegisterSessionNotification = (uintptr_t)GetProcAddress(gVBoxSt.hWTSAPI32, "WTSRegisterSessionNotification");
-        if (!gVBoxSt.pfnWTSRegisterSessionNotification)
-        {
+    RT_ZERO(gVBoxSt);
+    int rc = RTLdrLoadSystem("WTSAPI32.DLL", false /*fNoUnload*/, &gVBoxSt.hLdrModWTSAPI32);
+    if (RT_SUCCESS(rc))
+    {
+        rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSRegisterSessionNotification",
+                            (void **)&gVBoxSt.pfnWTSRegisterSessionNotification);
+        if (RT_SUCCESS(rc))
+        {
+            rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSUnRegisterSessionNotification",
+                                (void **)&gVBoxSt.pfnWTSUnRegisterSessionNotification);
+            if (RT_SUCCESS(rc))
+            {
+                rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSQuerySessionInformationA",
+                                    (void **)&gVBoxSt.pfnWTSQuerySessionInformationA);
+                if (RT_FAILURE(rc))
+                    WARN(("VBoxTray: WTSQuerySessionInformationA not found\n"));
+            }
+            else
+                WARN(("VBoxTray: WTSUnRegisterSessionNotification not found\n"));
+        }
+        else
             WARN(("VBoxTray: WTSRegisterSessionNotification not found\n"));
-            rc = VERR_NOT_SUPPORTED;
-        }
-
-        *(uintptr_t *)&gVBoxSt.pfnWTSUnRegisterSessionNotification = (uintptr_t)GetProcAddress(gVBoxSt.hWTSAPI32, "WTSUnRegisterSessionNotification");
-        if (!gVBoxSt.pfnWTSUnRegisterSessionNotification)
-        {
-            WARN(("VBoxTray: WTSUnRegisterSessionNotification not found\n"));
-            rc = VERR_NOT_SUPPORTED;
-        }
-
-        *(uintptr_t *)&gVBoxSt.pfnWTSQuerySessionInformationA = (uintptr_t)GetProcAddress(gVBoxSt.hWTSAPI32, "WTSQuerySessionInformationA");
-        if (!gVBoxSt.pfnWTSQuerySessionInformationA)
-        {
-            WARN(("VBoxTray: WTSQuerySessionInformationA not found\n"));
-            rc = VERR_NOT_SUPPORTED;
-        }
-
-        if (rc == VINF_SUCCESS)
+        if (RT_SUCCESS(rc))
         {
             gVBoxSt.hWTSAPIWnd = hWnd;
             if (gVBoxSt.pfnWTSRegisterSessionNotification(gVBoxSt.hWTSAPIWnd, NOTIFY_FOR_THIS_SESSION))
-            {
                 vboxStCheckState();
-            }
             else
             {
@@ -1102,9 +1087,9 @@
                 if (dwErr == RPC_S_INVALID_BINDING)
                 {
-                    gVBoxSt.idDelayedInitTimer = SetTimer(gVBoxSt.hWTSAPIWnd, TIMERID_VBOXTRAY_ST_DELAYED_INIT_TIMER, 2000, (TIMERPROC)NULL);
-                    rc = VINF_SUCCESS;
-
+                    gVBoxSt.idDelayedInitTimer = SetTimer(gVBoxSt.hWTSAPIWnd, TIMERID_VBOXTRAY_ST_DELAYED_INIT_TIMER,
+                                                          2000, (TIMERPROC)NULL);
                     gVBoxSt.fIsConsole = TRUE;
                     gVBoxSt.enmConnectState = WTSActive;
+                    rc = VINF_SUCCESS;
                 }
                 else
@@ -1116,14 +1101,10 @@
         }
 
-        FreeLibrary(gVBoxSt.hWTSAPI32);
+        RTLdrClose(gVBoxSt.hLdrModWTSAPI32);
     }
     else
-    {
-        DWORD dwErr = GetLastError();
-        WARN(("VBoxTray: WTSAPI32 load failed, error = %08X\n", dwErr));
-        rc = RTErrConvertFromWin32(dwErr);
-    }
-
-    memset(&gVBoxSt, 0, sizeof (gVBoxSt));
+        WARN(("VBoxTray: WTSAPI32 load failed, rc = %Rrc\n", rc));
+
+    RT_ZERO(gVBoxSt);
     gVBoxSt.fIsConsole = TRUE;
     gVBoxSt.enmConnectState = WTSActive;
@@ -1131,7 +1112,7 @@
 }
 
-static void vboxStTerm()
-{
-    if (gVBoxSt.hWTSAPIWnd)
+static void vboxStTerm(void)
+{
+    if (!gVBoxSt.hWTSAPIWnd)
     {
         WARN(("VBoxTray: vboxStTerm called for non-initialized St\n"));
@@ -1154,6 +1135,6 @@
     }
 
-    FreeLibrary(gVBoxSt.hWTSAPI32);
-    memset(&gVBoxSt, 0, sizeof (gVBoxSt));
+    RTLdrClose(gVBoxSt.hLdrModWTSAPI32);
+    RT_ZERO(gVBoxSt);
 }
 
@@ -1228,8 +1209,7 @@
     BOOL fIsInputDesktop;
     UINT_PTR idTimer;
-    HMODULE hHookModule;
+    RTLDRMOD hLdrModHook;
     BOOL (* pfnVBoxHookInstallActiveDesktopTracker)(HMODULE hDll);
     BOOL (* pfnVBoxHookRemoveActiveDesktopTracker)();
-    HMODULE hUSER32;
     HDESK (WINAPI * pfnGetThreadDesktop)(DWORD dwThreadId);
     HDESK (WINAPI * pfnOpenInputDesktop)(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess);
@@ -1289,88 +1269,84 @@
     }
 
-    memset(&gVBoxDt, 0, sizeof (gVBoxDt));
+    RT_ZERO(gVBoxDt);
 
     gVBoxDt.hNotifyEvent = CreateEvent(NULL, FALSE, FALSE, VBOXHOOK_GLOBAL_DT_EVENT_NAME);
     if (gVBoxDt.hNotifyEvent != NULL)
     {
-        gVBoxDt.hHookModule = LoadLibrary(VBOXHOOK_DLL_NAME);
-        if (gVBoxDt.hHookModule)
-        {
-            *(uintptr_t *)&gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker = (uintptr_t)GetProcAddress(gVBoxDt.hHookModule, "VBoxHookInstallActiveDesktopTracker");
-            if (!gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker)
-            {
+        /* Load the hook dll and resolve the necessary entry points. */
+        rc = RTLdrLoadAppPriv(VBOXHOOK_DLL_NAME, &gVBoxDt.hLdrModHook);
+        if (RT_SUCCESS(rc))
+        {
+            rc = RTLdrGetSymbol(gVBoxDt.hLdrModHook, "VBoxHookInstallActiveDesktopTracker",
+                                (void **)&gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker);
+            if (RT_SUCCESS(rc))
+            {
+                rc = RTLdrGetSymbol(gVBoxDt.hLdrModHook, "VBoxHookRemoveActiveDesktopTracker",
+                                    (void **)&gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker);
+                if (RT_FAILURE(rc))
+                    WARN(("VBoxTray: VBoxHookRemoveActiveDesktopTracker not found\n"));
+            }
+            else
                 WARN(("VBoxTray: VBoxHookInstallActiveDesktopTracker not found\n"));
-                rc = VERR_NOT_SUPPORTED;
-            }
-
-            *(uintptr_t *)&gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker  = (uintptr_t)GetProcAddress(gVBoxDt.hHookModule, "VBoxHookInstallActiveDesktopTracker");
-            if (!gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker)
-            {
-                WARN(("VBoxTray: VBoxHookRemoveActiveDesktopTracker not found\n"));
-                rc = VERR_NOT_SUPPORTED;
-            }
-
-            if (VINF_SUCCESS == rc)
-            {
-                gVBoxDt.hUSER32 = LoadLibrary("User32.dll");
-                if (gVBoxDt.hUSER32)
+            if (RT_SUCCESS(rc))
+            {
+                /* Try get the system APIs we need. */
+                *(void **)&gVBoxDt.pfnGetThreadDesktop = RTLdrGetSystemSymbol("User32.dll", "GetThreadDesktop");
+                if (!gVBoxDt.pfnGetThreadDesktop)
                 {
-                    *(uintptr_t *)&gVBoxDt.pfnGetThreadDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "GetThreadDesktop");
-                    if (!gVBoxDt.pfnGetThreadDesktop)
+                    WARN(("VBoxTray: GetThreadDesktop not found\n"));
+                    rc = VERR_NOT_SUPPORTED;
+                }
+
+                *(void **)&gVBoxDt.pfnOpenInputDesktop = RTLdrGetSystemSymbol("User32.dll", "OpenInputDesktop");
+                if (!gVBoxDt.pfnOpenInputDesktop)
+                {
+                    WARN(("VBoxTray: OpenInputDesktop not found\n"));
+                    rc = VERR_NOT_SUPPORTED;
+                }
+
+                *(void **)&gVBoxDt.pfnCloseDesktop = RTLdrGetSystemSymbol("User32.dll", "CloseDesktop");
+                if (!gVBoxDt.pfnCloseDesktop)
+                {
+                    WARN(("VBoxTray: CloseDesktop not found\n"));
+                    rc = VERR_NOT_SUPPORTED;
+                }
+
+                if (RT_SUCCESS(rc))
+                {
+                    BOOL fRc = FALSE;
+                    /* For Vista and up we need to change the integrity of the security descriptor, too. */
+                    if (gMajorVersion >= 6)
                     {
-                        WARN(("VBoxTray: GetThreadDesktop not found\n"));
-                        rc = VERR_NOT_SUPPORTED;
-                    }
-
-                    *(uintptr_t *)&gVBoxDt.pfnOpenInputDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "OpenInputDesktop");
-                    if (!gVBoxDt.pfnOpenInputDesktop)
-                    {
-                        WARN(("VBoxTray: OpenInputDesktop not found\n"));
-                        rc = VERR_NOT_SUPPORTED;
-                    }
-
-                    *(uintptr_t *)&gVBoxDt.pfnCloseDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "CloseDesktop");
-                    if (!gVBoxDt.pfnCloseDesktop)
-                    {
-                        WARN(("VBoxTray: CloseDesktop not found\n"));
-                        rc = VERR_NOT_SUPPORTED;
-                    }
-
-                    if (VINF_SUCCESS == rc)
-                    {
-                        BOOL bRc = FALSE;
-                        /* For Vista and up we need to change the integrity of the security descriptor, too. */
-                        if (gMajorVersion >= 6)
+                        HMODULE hModHook = (HMODULE)RTLdrGetNativeHandle(gVBoxDt.hLdrModHook);
+                        Assert((uintptr_t)hModHook != ~(uintptr_t)0);
+                        fRc = gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker(hModHook);
+                        if (!fRc)
                         {
-                            bRc = gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker(gVBoxDt.hHookModule);
-                            if (!bRc)
-                            {
-                                DWORD dwErr = GetLastError();
-                                WARN(("VBoxTray: pfnVBoxHookInstallActiveDesktopTracker failed, last error = %08X\n", dwErr));
-                            }
-                        }
-
-                        if (!bRc)
-                        {
-                            gVBoxDt.idTimer = SetTimer(ghwndToolWindow, TIMERID_VBOXTRAY_DT_TIMER, 500, (TIMERPROC)NULL);
-                            if (!gVBoxDt.idTimer)
-                            {
-                                DWORD dwErr = GetLastError();
-                                WARN(("VBoxTray: SetTimer error %08X\n", dwErr));
-                                rc = RTErrConvertFromWin32(dwErr);
-                            }
-                        }
-
-                        if (RT_SUCCESS(rc))
-                        {
-                            gVBoxDt.fIsInputDesktop = vboxDtCalculateIsInputDesktop();
-                            return VINF_SUCCESS;
+                            DWORD dwErr = GetLastError();
+                            WARN(("VBoxTray: pfnVBoxHookInstallActiveDesktopTracker failed, last error = %08X\n", dwErr));
                         }
                     }
-                    FreeLibrary(gVBoxDt.hUSER32);
+
+                    if (!fRc)
+                    {
+                        gVBoxDt.idTimer = SetTimer(ghwndToolWindow, TIMERID_VBOXTRAY_DT_TIMER, 500, (TIMERPROC)NULL);
+                        if (!gVBoxDt.idTimer)
+                        {
+                            DWORD dwErr = GetLastError();
+                            WARN(("VBoxTray: SetTimer error %08X\n", dwErr));
+                            rc = RTErrConvertFromWin32(dwErr);
+                        }
+                    }
+
+                    if (RT_SUCCESS(rc))
+                    {
+                        gVBoxDt.fIsInputDesktop = vboxDtCalculateIsInputDesktop();
+                        return VINF_SUCCESS;
+                    }
                 }
             }
 
-            FreeLibrary(gVBoxDt.hHookModule);
+            RTLdrClose(gVBoxDt.hLdrModHook);
         }
         else
@@ -1391,5 +1367,5 @@
 
 
-    memset(&gVBoxDt, 0, sizeof (gVBoxDt));
+    RT_ZERO(gVBoxDt);
     gVBoxDt.fIsInputDesktop = TRUE;
 
@@ -1399,14 +1375,13 @@
 static void vboxDtTerm()
 {
-    if (!gVBoxDt.hHookModule)
+    if (!gVBoxDt.hLdrModHook)
         return;
 
     gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker();
 
-    FreeLibrary(gVBoxDt.hUSER32);
-    FreeLibrary(gVBoxDt.hHookModule);
+    RTLdrClose(gVBoxDt.hLdrModHook);
     CloseHandle(gVBoxDt.hNotifyEvent);
 
-    memset(&gVBoxDt, 0, sizeof (gVBoxDt));
+    RT_ZERO(gVBoxDt);
 }
 /* @returns true on "IsInputDesktop" state change */
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp	(revision 46593)
@@ -25,4 +25,5 @@
 #include <VBoxGuestInternal.h>
 #include <iprt/assert.h>
+#include <iprt/ldr.h>
 
 
@@ -256,5 +257,5 @@
     BOOL fSavedThemeEnabled;
 
-    HMODULE hModule;
+    RTLDRMOD hModUxTheme;
 
     HRESULT (* pfnEnableTheming)(BOOL fEnable);
@@ -274,14 +275,15 @@
     gCtx.fSavedThemeEnabled = FALSE;
 
-    gCtx.hModule = LoadLibrary("UxTheme");
-
-    if (gCtx.hModule)
-    {
-        *(uintptr_t *)&gCtx.pfnEnableTheming = (uintptr_t)GetProcAddress(gCtx.hModule, "EnableTheming");
-        *(uintptr_t *)&gCtx.pfnIsThemeActive = (uintptr_t)GetProcAddress(gCtx.hModule, "IsThemeActive");
+    int rc = RTLdrLoadSystem("UxTheme.dll", false /*fNoUnload*/, &gCtx.hModUxTheme);
+    if (RT_SUCCESS(rc))
+    {
+        *(PFNRT *)&gCtx.pfnEnableTheming = RTLdrGetFunction(gCtx.hModUxTheme, "EnableTheming");
+        *(PFNRT *)&gCtx.pfnIsThemeActive = RTLdrGetFunction(gCtx.hModUxTheme, "IsThemeActive");
     }
     else
     {
-        gCtx.pfnEnableTheming = 0;
+        gCtx.hModUxTheme = NIL_RTLDRMOD;
+        gCtx.pfnEnableTheming = NULL;
+        gCtx.pfnIsThemeActive = NULL;
     }
 
@@ -297,7 +299,9 @@
     VBOXVRDPCONTEXT *pCtx = (VBOXVRDPCONTEXT *)pInstance;
     vboxExperienceRestore (pCtx->level);
-    if (gCtx.hModule)
-        FreeLibrary(gCtx.hModule);
-    gCtx.hModule = 0;
+    if (gCtx.hModUxTheme != NIL_RTLDRMOD)
+    {
+        RTLdrClose(gCtx.hModUxTheme);
+        gCtx.hModUxTheme = NIL_RTLDRMOD;
+    }
     return;
 }
Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxServicePageSharing.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxServicePageSharing.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxServicePageSharing.cpp	(revision 46593)
@@ -24,4 +24,5 @@
 #include <iprt/asm.h>
 #include <iprt/mem.h>
+#include <iprt/ldr.h>
 #include <iprt/process.h>
 #include <iprt/env.h>
@@ -81,6 +82,5 @@
 
 typedef NTSTATUS (WINAPI *PFNZWQUERYSYSTEMINFORMATION)(ULONG, PVOID, ULONG, PULONG);
-static PFNZWQUERYSYSTEMINFORMATION ZwQuerySystemInformation = NULL;
-static HMODULE hNtdll = 0;
+static PFNZWQUERYSYSTEMINFORMATION g_pfnZwQuerySystemInformation = NULL;
 
 
@@ -366,5 +366,5 @@
 
     /* Check all loaded kernel modules. */
-    if (ZwQuerySystemInformation)
+    if (g_pfnZwQuerySystemInformation)
     {
         ULONG                cbBuffer = 0;
@@ -372,5 +372,5 @@
         PRTL_PROCESS_MODULES pSystemModules;
 
-        NTSTATUS ret = ZwQuerySystemInformation(SystemModuleInformation, (PVOID)&cbBuffer, 0, &cbBuffer);
+        NTSTATUS ret = g_pfnZwQuerySystemInformation(SystemModuleInformation, (PVOID)&cbBuffer, 0, &cbBuffer);
         if (!cbBuffer)
         {
@@ -383,5 +383,5 @@
             goto skipkernelmodules;
 
-        ret = ZwQuerySystemInformation(SystemModuleInformation, pBuffer, cbBuffer, &cbBuffer);
+        ret = g_pfnZwQuerySystemInformation(SystemModuleInformation, pBuffer, cbBuffer, &cbBuffer);
         if (ret != STATUS_SUCCESS)
         {
@@ -553,10 +553,7 @@
 
 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4)
-    hNtdll = LoadLibrary("ntdll.dll");
-
-    if (hNtdll)
-        ZwQuerySystemInformation = (PFNZWQUERYSYSTEMINFORMATION)GetProcAddress(hNtdll, "ZwQuerySystemInformation");
-
-    rc =  VbglR3GetSessionId(&g_idSession);
+    g_pfnZwQuerySystemInformation = (PFNZWQUERYSYSTEMINFORMATION)RTLdrGetSystemSymbol("ntdll.dll", "ZwQuerySystemInformation");
+
+    rc = VbglR3GetSessionId(&g_idSession);
     if (RT_FAILURE(rc))
     {
@@ -738,10 +735,4 @@
 {
     VBoxServiceVerbose(3, "VBoxServicePageSharingTerm\n");
-
-#if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4)
-    if (hNtdll)
-        FreeLibrary(hNtdll);
-#endif
-    return;
 }
 
Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp	(revision 46593)
@@ -44,4 +44,5 @@
 #include <iprt/assert.h>
 #include <iprt/mem.h>
+#include <iprt/ldr.h>
 #include <VBox/param.h>
 #include <iprt/semaphore.h>
@@ -124,43 +125,30 @@
 
 #ifdef RT_OS_WINDOWS
-    /** @todo Use RTLdr instead of LoadLibrary/GetProcAddress here! */
-
-    /* NtQuerySystemInformation might be dropped in future releases, so load it dynamically as per Microsoft's recommendation */
-    HMODULE hMod = LoadLibrary("NTDLL.DLL");
-    if (hMod)
-    {
-        *(uintptr_t *)&gCtx.pfnNtQuerySystemInformation = (uintptr_t)GetProcAddress(hMod, "NtQuerySystemInformation");
-        if (gCtx.pfnNtQuerySystemInformation)
-            VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnNtQuerySystemInformation = %x\n", gCtx.pfnNtQuerySystemInformation);
-        else
-        {
-            VBoxServiceVerbose(3, "VBoxStatsInit: NTDLL.NtQuerySystemInformation not found!\n");
-            return VERR_SERVICE_DISABLED;
-        }
+    /* NtQuerySystemInformation might be dropped in future releases, so load
+       it dynamically as per Microsoft's recommendation. */
+    *(void **)&gCtx.pfnNtQuerySystemInformation = RTLdrGetSystemSymbol("NTDLL.DLL", "NtQuerySystemInformation");
+    if (gCtx.pfnNtQuerySystemInformation)
+        VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnNtQuerySystemInformation = %x\n", gCtx.pfnNtQuerySystemInformation);
+    else
+    {
+        VBoxServiceVerbose(3, "VBoxStatsInit: NTDLL.NtQuerySystemInformation not found!\n");
+        return VERR_SERVICE_DISABLED;
     }
 
     /* GlobalMemoryStatus is win2k and up, so load it dynamically */
-    hMod = LoadLibrary("KERNEL32.DLL");
-    if (hMod)
-    {
-        *(uintptr_t *)&gCtx.pfnGlobalMemoryStatusEx = (uintptr_t)GetProcAddress(hMod, "GlobalMemoryStatusEx");
-        if (gCtx.pfnGlobalMemoryStatusEx)
-            VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.GlobalMemoryStatusEx = %x\n", gCtx.pfnGlobalMemoryStatusEx);
-        else
-        {
-            /** @todo Now fails in NT4; do we care? */
-            VBoxServiceVerbose(3, "VBoxStatsInit: KERNEL32.GlobalMemoryStatusEx not found!\n");
-            return VERR_SERVICE_DISABLED;
-        }
-    }
+    *(void **)&gCtx.pfnGlobalMemoryStatusEx = RTLdrGetSystemSymbol("KERNEL32.DLL", "GlobalMemoryStatusEx");
+    if (gCtx.pfnGlobalMemoryStatusEx)
+        VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.GlobalMemoryStatusEx = %x\n", gCtx.pfnGlobalMemoryStatusEx);
+    else
+    {
+        /** @todo Now fails in NT4; do we care? */
+        VBoxServiceVerbose(3, "VBoxStatsInit: KERNEL32.GlobalMemoryStatusEx not found!\n");
+        return VERR_SERVICE_DISABLED;
+    }
+
     /* GetPerformanceInfo is xp and up, so load it dynamically */
-    hMod = LoadLibrary("PSAPI.DLL");
-    if (hMod)
-    {
-        *(uintptr_t *)&gCtx.pfnGetPerformanceInfo = (uintptr_t)GetProcAddress(hMod, "GetPerformanceInfo");
-        if (gCtx.pfnGetPerformanceInfo)
-            VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnGetPerformanceInfo= %x\n", gCtx.pfnGetPerformanceInfo);
-        /* failure is not fatal */
-    }
+    *(void **)&gCtx.pfnGetPerformanceInfo = RTLdrGetSystemSymbol("PSAPI.DLL", "GetPerformanceInfo");
+    if (gCtx.pfnGetPerformanceInfo)
+        VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnGetPerformanceInfo= %x\n", gCtx.pfnGetPerformanceInfo);
 #endif /* RT_OS_WINDOWS */
 
Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp	(revision 46593)
@@ -169,18 +169,17 @@
             /* Loading the module and getting the symbol for each and every process is expensive
              * -- since this function (at the moment) only is used for debugging purposes it's okay. */
-            RTLDRMOD hMod;
-            rc = RTLdrLoad("kernel32.dll", &hMod);
-            if (RT_SUCCESS(rc))
+            PFNQUERYFULLPROCESSIMAGENAME pfnQueryFullProcessImageName;
+            pfnQueryFullProcessImageName = (PFNQUERYFULLPROCESSIMAGENAME)
+                RTLdrGetSystemSymbol("kernel32.dll", "QueryFullProcessImageNameA");
+            /** @todo r=bird: WTF don't we query the UNICODE name? */
+            if (pfnQueryFullProcessImageName)
             {
-                PFNQUERYFULLPROCESSIMAGENAME pfnQueryFullProcessImageName;
-                rc = RTLdrGetSymbol(hMod, "QueryFullProcessImageNameA", (void **)&pfnQueryFullProcessImageName);
-                if (RT_SUCCESS(rc))
-                {
-                    DWORD dwLen = cbName / sizeof(TCHAR);
-                    if (!pfnQueryFullProcessImageName(h, 0 /*PROCESS_NAME_NATIVE*/, pszName, &dwLen))
-                        rc = VERR_ACCESS_DENIED;
-                }
-
-                RTLdrClose(hMod);
+                /** @todo r=bird: Completely bogus use of TCHAR.
+                 *  !!ALL USE OF TCHAR IS HEREWITH BANNED IN ALL VBOX SOURCES!!
+                 *  We use WCHAR when talking to windows, everything else is WRONG. (We don't
+                 *  want Chinese MBCS being treated as UTF-8.) */
+                DWORD dwLen = cbName / sizeof(TCHAR);
+                if (!pfnQueryFullProcessImageName(h, 0 /*PROCESS_NAME_NATIVE*/, pszName, &dwLen))
+                    rc = VERR_ACCESS_DENIED;
             }
         }
Index: /trunk/src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.cpp
===================================================================
--- /trunk/src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.cpp	(revision 46592)
+++ /trunk/src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.cpp	(revision 46593)
@@ -261,5 +261,5 @@
     }
 
-    int rc = RTR3InitDll(0);
+    int rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
     if (RT_SUCCESS(rc))
     {
Index: /trunk/src/VBox/Debugger/VBoxDbgStatsQt4.cpp
===================================================================
--- /trunk/src/VBox/Debugger/VBoxDbgStatsQt4.cpp	(revision 46592)
+++ /trunk/src/VBox/Debugger/VBoxDbgStatsQt4.cpp	(revision 46593)
@@ -353,4 +353,15 @@
      */
     static ssize_t getNodePath(PCDBGGUISTATSNODE pNode, char *psz, ssize_t cch);
+
+    /**
+     * Calculates the full path of a node, returning the string pointer.
+     *
+     * @returns @a psz. On failure, NULL.
+     *
+     * @param   pNode       The node.
+     * @param   psz         The output buffer.
+     * @param   cch         The size of the buffer.
+     */
+    static char *getNodePath2(PCDBGGUISTATSNODE pNode, char *psz, ssize_t cch);
 
     /**
@@ -1312,4 +1323,14 @@
 
 
+/*static*/ char *
+VBoxDbgStatsModel::getNodePath2(PCDBGGUISTATSNODE pNode, char *psz, ssize_t cch)
+{
+    if (VBoxDbgStatsModel::getNodePath(pNode, psz, cch) < 0)
+        return NULL;
+    return psz;
+}
+
+
+
 /*static*/ bool
 VBoxDbgStatsModel::isNodeAncestorOf(PCDBGGUISTATSNODE pAncestor, PCDBGGUISTATSNODE pDescendant)
@@ -1434,4 +1455,8 @@
 VBoxDbgStatsModel::updateCallbackHandleOutOfOrder(const char *pszName)
 {
+#if defined(VBOX_STRICT) || defined(LOG_ENABLED)
+    char szStrict[1024];
+#endif
+
     /*
      * We might be inserting a new node between pPrev and pNode
@@ -1451,4 +1476,9 @@
     PDBGGUISTATSNODE pNode = m_pUpdateParent->papChildren[m_iUpdateChild];
     PDBGGUISTATSNODE const pPrev = prevDataNode(pNode);
+    AssertMsg(strcmp(pszName, getNodePath2(pNode, szStrict, sizeof(szStrict))), ("%s\n", szStrict));
+    AssertMsg(strcmp(pszName, getNodePath2(pPrev, szStrict, sizeof(szStrict))), ("%s\n", szStrict));
+    Log(("updateCallbackHandleOutOfOrder: pszName='%s' m_szUpdateParent='%s' m_cchUpdateParent=%u pNode='%s'\n",
+         pszName, m_szUpdateParent, m_cchUpdateParent, getNodePath2(pNode, szStrict, sizeof(szStrict))));
+
     pNode = pNode->pParent;
     while (pNode != m_pRoot)
@@ -1459,4 +1489,5 @@
         m_cchUpdateParent -= pNode->cchName + 1;
         m_szUpdateParent[m_cchUpdateParent] = '\0';
+        Log2(("updateCallbackHandleOutOfOrder: m_szUpdateParent='%s' m_cchUpdateParent=%u, removed '/%s' (%u)\n", m_szUpdateParent, m_cchUpdateParent, pNode->pszName, __LINE__));
         pNode = pNode->pParent;
     }
@@ -1470,5 +1501,5 @@
     {
         /* Find the end of this component. */
-        const char *const pszSubName = &pszName[m_cchUpdateParent];
+        const char * const pszSubName = &pszName[m_cchUpdateParent];
         const char *pszEnd = strchr(pszSubName, '/');
         if (!pszEnd)
@@ -1482,4 +1513,5 @@
         m_szUpdateParent[m_cchUpdateParent] = '\0';
         Assert(m_cchUpdateParent < sizeof(m_szUpdateParent));
+        Log2(("updateCallbackHandleOutOfOrder: m_szUpdateParent='%s' m_cchUpdateParent=%u (%u)\n", m_szUpdateParent, m_cchUpdateParent, __LINE__));
 
         if (!pNode->cChildren)
@@ -1571,4 +1603,5 @@
     m_pUpdateParent = pNode->pParent;
     m_iUpdateChild = pNode->iSelf;
+    Log2(("updateCallbackHandleOutOfOrder: m_szUpdateParent='%s' m_cchUpdateParent=%u (%u)\n", m_szUpdateParent, m_cchUpdateParent, __LINE__));
 
     return pNode;
Index: /trunk/src/VBox/Devices/Network/slirp/ip_icmp.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/ip_icmp.c	(revision 46592)
+++ /trunk/src/VBox/Devices/Network/slirp/ip_icmp.c	(revision 46593)
@@ -57,6 +57,7 @@
 #include "ip_icmp.h"
 #ifdef RT_OS_WINDOWS
-#include <Icmpapi.h>
-#include <Iphlpapi.h>
+# include <Icmpapi.h>
+# include <Iphlpapi.h>
+# include <iprt/ldr.h>
 #endif
 
@@ -116,39 +117,36 @@
     fd_nonblock(pData->icmp_socket.s);
     NSOCK_INC();
+
 #else /* RT_OS_WINDOWS */
-    pData->hmIcmpLibrary = LoadLibrary("Iphlpapi.dll");
-    if (pData->hmIcmpLibrary != NULL)
-    {
-        pData->pfIcmpParseReplies = (long (WINAPI *)(void *, long))
-                                    GetProcAddress(pData->hmIcmpLibrary, "IcmpParseReplies");
-        pData->pfIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))
-                                    GetProcAddress(pData->hmIcmpLibrary, "IcmpCloseHandle");
-        pData->pfGetAdaptersAddresses = (ULONG (WINAPI *)(ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG))
-                                    GetProcAddress(pData->hmIcmpLibrary, "GetAdaptersAddresses");
-        if (pData->pfGetAdaptersAddresses == NULL)
+    /* Resolve symbols we need. */
+    {
+        RTLDRMOD hLdrMod;
+        int rc = RTLdrLoadSystem("Iphlpapi.dll", true /*fNoUnload*/, &hLdrMod);
+        if (RT_SUCCESS(rc))
         {
-            LogRel(("NAT: Can't find GetAdapterAddresses in Iphlpapi.dll\n"));
+            pData->pfIcmpParseReplies = (long (WINAPI *)(void *, long))RTLdrGetFunction(hLdrMod, "IcmpParseReplies");
+            pData->pfIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))RTLdrGetFunction(hLdrMod, "IcmpCloseHandle");
+            rc = RTLdrGetSymbol(hLdrMod, "GetAdaptersAddresses", (void **)&pData->pfGetAdaptersAddresses);
+            if (RT_FAILURE(rc))
+                LogRel(("NAT: Can't find GetAdapterAddresses in Iphlpapi.dll\n"));
+            RTLdrClose(hLdrMod);
         }
-    }
-
+
+        if (pData->pfIcmpParseReplies == NULL)
+        {
+            int rc = RTLdrLoadSystem("Icmp.dll", true /*fNoUnload*/, &hLdrMod);
+            if (RT_FAILURE(rc))
+            {
+                LogRel(("NAT: Icmp.dll could not be loaded: %Rrc\n", rc));
+                return 1;
+            }
+            pData->pfIcmpParseReplies = (long (WINAPI *)(void *, long))RTLdrGetFunction(hLdrMod, "IcmpParseReplies");
+            pData->pfIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))RTLdrGetFunction(hLdrMod, "IcmpCloseHandle");
+            RTLdrClose(hLdrMod);
+        }
+    }
     if (pData->pfIcmpParseReplies == NULL)
     {
-        if(pData->pfGetAdaptersAddresses == NULL)
-            FreeLibrary(pData->hmIcmpLibrary);
-        pData->hmIcmpLibrary = LoadLibrary("Icmp.dll");
-        if (pData->hmIcmpLibrary == NULL)
-        {
-            LogRel(("NAT: Icmp.dll could not be loaded\n"));
-            return 1;
-        }
-        pData->pfIcmpParseReplies = (long (WINAPI *)(void *, long))
-                                    GetProcAddress(pData->hmIcmpLibrary, "IcmpParseReplies");
-        pData->pfIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))
-                                    GetProcAddress(pData->hmIcmpLibrary, "IcmpCloseHandle");
-    }
-    if (pData->pfIcmpParseReplies == NULL)
-    {
         LogRel(("NAT: Can't find IcmpParseReplies symbol\n"));
-        FreeLibrary(pData->hmIcmpLibrary);
         return 1;
     }
@@ -156,12 +154,13 @@
     {
         LogRel(("NAT: Can't find IcmpCloseHandle symbol\n"));
-        FreeLibrary(pData->hmIcmpLibrary);
         return 1;
     }
+
     pData->icmp_socket.sh = IcmpCreateFile();
     pData->phEvents[VBOX_ICMP_EVENT_INDEX] = CreateEvent(NULL, FALSE, FALSE, NULL);
-    pData->szIcmpBuffer = sizeof(ICMP_ECHO_REPLY) * 10;
-    pData->pvIcmpBuffer = RTMemAlloc(pData->szIcmpBuffer);
+    pData->cbIcmpBuffer = sizeof(ICMP_ECHO_REPLY) * 10;
+    pData->pvIcmpBuffer = RTMemAlloc(pData->cbIcmpBuffer);
 #endif /* RT_OS_WINDOWS */
+
     LIST_INIT(&pData->icmp_msg_head);
     return 0;
@@ -177,5 +176,4 @@
 #ifdef RT_OS_WINDOWS
     pData->pfIcmpCloseHandle(pData->icmp_socket.sh);
-    FreeLibrary(pData->hmIcmpLibrary);
     RTMemFree(pData->pvIcmpBuffer);
 #else
@@ -529,5 +527,5 @@
                                        &ipopt /*=RequestOptions*/,
                                        pData->pvIcmpBuffer /*=ReplyBuffer*/,
-                                       pData->szIcmpBuffer /*=ReplySize*/,
+                                       pData->cbIcmpBuffer /*=ReplySize*/,
                                        1 /*=Timeout in ms*/);
                 error = GetLastError();
@@ -710,9 +708,9 @@
     {
         /* DEBUG : append message to ICMP packet */
-        int message_len;
+        size_t message_len;
         message_len = strlen(message);
         if (message_len > ICMP_MAXDATALEN)
             message_len = ICMP_MAXDATALEN;
-        m_append(pData, m, message_len, message);
+        m_append(pData, m, (int)message_len, message);
     }
 #else
Index: /trunk/src/VBox/Devices/Network/slirp/slirp_state.h
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/slirp_state.h	(revision 46592)
+++ /trunk/src/VBox/Devices/Network/slirp/slirp_state.h	(revision 46593)
@@ -202,11 +202,10 @@
 # ifdef RT_OS_WINDOWS
     void *pvIcmpBuffer;
-    size_t szIcmpBuffer;
-    /* Accordin MSDN specification IcmpParseReplies
-     * function should be detected in runtime
+    uint32_t cbIcmpBuffer;
+    /* According MSDN specification IcmpParseReplies
+     * function should be detected at runtime.
      */
     long (WINAPI * pfIcmpParseReplies)(void *, long);
     BOOL (WINAPI * pfIcmpCloseHandle)(HANDLE);
-    HMODULE hmIcmpLibrary;
 # endif
 #if defined(RT_OS_WINDOWS)
Index: /trunk/src/VBox/Devices/Network/slirp/socket.c
===================================================================
--- /trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 46592)
+++ /trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 46593)
@@ -1479,5 +1479,5 @@
     int size;
 
-    len = pData->pfIcmpParseReplies(pData->pvIcmpBuffer, pData->szIcmpBuffer);
+    len = pData->pfIcmpParseReplies(pData->pvIcmpBuffer, pData->cbIcmpBuffer);
     if (len < 0)
     {
Index: /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILineEdit.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILineEdit.cpp	(revision 46592)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILineEdit.cpp	(revision 46593)
@@ -1,11 +1,9 @@
 /* $Id$ */
 /** @file
- *
- * VBox frontends: Qt GUI ("VirtualBox"):
- * QILineEdit class implementation
+ * VirtualBox Qt GUI - QILineEdit class implementation.
  */
 
 /*
- * Copyright (C) 2008-2010 Oracle Corporation
+ * Copyright (C) 2008-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -24,6 +22,10 @@
 
 #if defined (Q_WS_WIN32)
-#include <QWindowsVistaStyle>
-#include <QLibrary>
+# include <QWindowsVistaStyle>
+# include <QLibrary>
+#endif
+#if defined (Q_WS_WIN32)
+# include <Windows.h>
+# include "iprt/ldr.h"
 #endif
 
@@ -62,8 +64,11 @@
         /* Check if l&f style theme is really active else painting performed by
          * Windows Classic theme and there is no such shifting error. */
-        typedef bool (*IsAppThemedFunction)();
-        IsAppThemedFunction isAppThemed =
-            (IsAppThemedFunction) QLibrary::resolve ("uxtheme", "IsAppThemed");
-        if (isAppThemed && isAppThemed()) sa -= QSize (23, 0);
+        typedef BOOL (WINAPI *PFNISAPPTHEMED)(VOID);
+        static PFNISAPPTHEMED s_pfnIsAppThemed = (PFNISAPPTHEMED)~(uintptr_t)0;
+        if (s_pfnIsAppThemed == (PFNISAPPTHEMED)~(uintptr_t)0 )
+            s_pfnIsAppThemed = (PFNISAPPTHEMED)RTLdrGetSystemSymbol("uxtheme.dll", "IsAppThemed");
+
+        if (s_pfnIsAppThemed && s_pfnIsAppThemed())
+            sa -= QSize(23, 0);
     }
 #endif
Index: /trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp	(revision 46592)
+++ /trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp	(revision 46593)
@@ -2140,6 +2140,4 @@
 
 
-#define NETSHELL_LIBRARY _T("netshell.dll")
-
 /**
  *  Use the IShellFolder API to rename the connection.
@@ -2187,4 +2185,22 @@
 
     return hr;
+}
+
+/**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+        return NULL;
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
 }
 
@@ -2209,5 +2225,5 @@
         if (FAILED(status))
             return E_FAIL;
-        hNetShell = LoadLibrary (NETSHELL_LIBRARY);
+        hNetShell = loadSystemDll("netshell.dll");
         if (hNetShell == NULL)
             return E_FAIL;
Index: /trunk/src/VBox/Main/src-client/win/dllmain.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/win/dllmain.cpp	(revision 46592)
+++ /trunk/src/VBox/Main/src-client/win/dllmain.cpp	(revision 46593)
@@ -46,5 +46,5 @@
 
         // idempotent, so doesn't harm, and needed for COM embedding scenario
-        RTR3InitDll(0);
+        RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
     }
     else if (dwReason == DLL_PROCESS_DETACH)
Index: /trunk/src/VBox/Main/src-server/win/PerformanceWin.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/win/PerformanceWin.cpp	(revision 46592)
+++ /trunk/src/VBox/Main/src-server/win/PerformanceWin.cpp	(revision 46593)
@@ -34,4 +34,5 @@
 
 #include <iprt/err.h>
+#include <iprt/ldr.h>
 #include <iprt/mp.h>
 #include <iprt/mem.h>
@@ -87,5 +88,4 @@
     PFNGST  mpfnGetSystemTimes;
     PFNNQSI mpfnNtQuerySystemInformation;
-    HMODULE mhNtDll;
 
     ULONG   totalRAM;
@@ -97,25 +97,15 @@
 }
 
-CollectorWin::CollectorWin() : CollectorHAL(), mhNtDll(0)
-{
-    mpfnGetSystemTimes = (PFNGST)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),
-                                                "GetSystemTimes");
+CollectorWin::CollectorWin() : CollectorHAL(), mpfnNtQuerySystemInformation(NULL)
+{
+    /* Note! Both kernel32.dll and ntdll.dll can be assumed to always be present. */
+    mpfnGetSystemTimes = (PFNGST)RTLdrGetSystemSymbol("kernel32.dll", "GetSystemTimes");
     if (!mpfnGetSystemTimes)
     {
         /* Fall back to deprecated NtQuerySystemInformation */
-        if (!(mhNtDll = LoadLibrary(TEXT("ntdll.dll"))))
-        {
-            LogRel(("Failed to load NTDLL.DLL with error 0x%x. GetSystemTimes() is"
-                    " not available either. CPU and VM metrics will not be collected.\n",
-                    GetLastError()));
-            mpfnNtQuerySystemInformation = 0;
-        }
-        else if (!(mpfnNtQuerySystemInformation = (PFNNQSI)GetProcAddress(mhNtDll,
-                                                                          "NtQuerySystemInformation")))
-        {
-            LogRel(("Neither GetSystemTimes() nor NtQuerySystemInformation() is"
-                    " not available. CPU and VM metrics will not be collected.\n"));
-            mpfnNtQuerySystemInformation = 0;
-        }
+        mpfnNtQuerySystemInformation = (PFNNQSI)RTLdrGetSystemSymbol("ntdll.dll", "NtQuerySystemInformation");
+        if (!mpfnNtQuerySystemInformation)
+            LogRel(("Warning! Neither GetSystemTimes() nor NtQuerySystemInformation() is not available.\n"
+                    "         CPU and VM metrics will not be collected! (lasterr %u)\n", GetLastError()));
     }
 
@@ -130,6 +120,4 @@
 CollectorWin::~CollectorWin()
 {
-    if (mhNtDll)
-        FreeLibrary(mhNtDll);
 }
 
Index: /trunk/src/VBox/Runtime/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Runtime/Makefile.kmk	(revision 46592)
+++ /trunk/src/VBox/Runtime/Makefile.kmk	(revision 46593)
@@ -595,4 +595,5 @@
 	r3/win/fileio-win.cpp \
 	r3/win/fs-win.cpp \
+	r3/win/init-win.cpp \
 	r3/win/ldrNative-win.cpp \
 	r3/win/localipc-win.cpp \
Index: /trunk/src/VBox/Runtime/VBox/VBoxRTDeps.cpp
===================================================================
--- /trunk/src/VBox/Runtime/VBox/VBoxRTDeps.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/VBox/VBoxRTDeps.cpp	(revision 46593)
@@ -36,5 +36,5 @@
 #include <iprt/system.h>
 
-#include <libxml/xmlmodule.h>
+#include <libxml/catalog.h>
 #include <libxml/globals.h>
 #include <openssl/md5.h>
@@ -58,5 +58,5 @@
     (PFNRT)SUPTracerFireProbe,
 #endif
-    (PFNRT)xmlModuleOpen,
+    (PFNRT)xmlLoadCatalogs,
     (PFNRT)MD5_Init,
     (PFNRT)RC4,
Index: /trunk/src/VBox/Runtime/common/ldr/ldr.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/ldr/ldr.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/common/ldr/ldr.cpp	(revision 46593)
@@ -94,4 +94,15 @@
 
 
+RTDECL(PFNRT) RTLdrGetFunction(RTLDRMOD hLdrMod, const char *pszSymbol)
+{
+    PFNRT pfn;
+    int rc = RTLdrGetSymbol(hLdrMod, pszSymbol, (void **)&pfn);
+    if (RT_SUCCESS(rc))
+        return pfn;
+    return NULL;
+}
+RT_EXPORT_SYMBOL(RTLdrGetFunction);
+
+
 RTDECL(RTLDRFMT) RTLdrGetFormat(RTLDRMOD hLdrMod)
 {
Index: /trunk/src/VBox/Runtime/common/ldr/ldrNative.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/ldr/ldrNative.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/common/ldr/ldrNative.cpp	(revision 46593)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2011 Oracle Corporation
+ * Copyright (C) 2006-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -63,5 +63,5 @@
  * Operations for a native module.
  */
-static const RTLDROPS s_rtldrNativeOps =
+static const RTLDROPS g_rtldrNativeOps =
 {
     "native",
@@ -131,5 +131,5 @@
         pMod->Core.u32Magic     = RTLDRMOD_MAGIC;
         pMod->Core.eState       = LDR_STATE_LOADED;
-        pMod->Core.pOps         = &s_rtldrNativeOps;
+        pMod->Core.pOps         = &g_rtldrNativeOps;
         pMod->Core.pReader      = NULL;
         pMod->Core.enmFormat    = RTLDRFMT_NATIVE;
@@ -148,4 +148,5 @@
 #endif
         pMod->hNative           = ~(uintptr_t)0;
+        pMod->fFlags            = fFlags;
 
         /*
@@ -171,4 +172,52 @@
 
 
+RTDECL(int) RTLdrLoadSystem(const char *pszFilename, bool fNoUnload, PRTLDRMOD phLdrMod)
+{
+    LogFlow(("RTLdrLoadSystem: pszFilename=%p:{%s} fNoUnload=%RTbool phLdrMod=%p\n",
+             pszFilename, pszFilename, fNoUnload, phLdrMod));
+
+    /*
+     * Validate input.
+     */
+    AssertPtrReturn(phLdrMod, VERR_INVALID_PARAMETER);
+    *phLdrMod = NIL_RTLDRMOD;
+    AssertPtrReturn(pszFilename, VERR_INVALID_PARAMETER);
+    AssertMsgReturn(!RTPathHavePath(pszFilename), ("%s\n", pszFilename), VERR_INVALID_PARAMETER);
+
+    /*
+     * Check the filename.
+     */
+    size_t cchFilename = strlen(pszFilename);
+    AssertMsgReturn(cchFilename < (RTPATH_MAX / 4) * 3, ("%zu\n", cchFilename), VERR_INVALID_PARAMETER);
+
+    const char *pszExt = "";
+    if (!RTPathHaveExt(pszFilename))
+        pszExt = RTLdrGetSuff();
+
+    /*
+     * Let the platform specific code do the rest.
+     */
+    int rc = rtldrNativeLoadSystem(pszFilename, pszExt, fNoUnload ? RTLDRLOAD_FLAGS_NO_UNLOAD : 0, phLdrMod);
+    LogFlow(("RTLdrLoadSystem: returns %Rrc\n", rc));
+    return rc;
+}
+
+
+RTDECL(void *) RTLdrGetSystemSymbol(const char *pszFilename, const char *pszSymbol)
+{
+    void    *pvRet = NULL;
+    RTLDRMOD hLdrMod;
+    int rc = RTLdrLoadSystem(pszFilename, true /*fNoUnload*/, &hLdrMod);
+    if (RT_SUCCESS(rc))
+    {
+        rc = RTLdrGetSymbol(hLdrMod, pszSymbol, &pvRet);
+        if (RT_FAILURE(rc))
+            pvRet = NULL; /* paranoia */
+        RTLdrClose(hLdrMod);
+    }
+    return pvRet;
+}
+
+
 /**
  * Loads a dynamic load library (/shared object) image file residing in the
@@ -258,2 +307,13 @@
 RT_EXPORT_SYMBOL(RTLdrGetSuff);
 
+
+RTDECL(uintptr_t) RTLdrGetNativeHandle(RTLDRMOD hLdrMod)
+{
+    PRTLDRMODNATIVE pThis = (PRTLDRMODNATIVE)hLdrMod;
+    AssertPtrReturn(pThis, ~(uintptr_t)0);
+    AssertReturn(pThis->Core.u32Magic == RTLDRMOD_MAGIC, ~(uintptr_t)0);
+    AssertReturn(pThis->Core.pOps == &g_rtldrNativeOps, ~(uintptr_t)0);
+    return pThis->hNative;
+}
+RT_EXPORT_SYMBOL(RTLdrGetNativeHandle);
+
Index: /trunk/src/VBox/Runtime/common/misc/thread.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/misc/thread.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/common/misc/thread.cpp	(revision 46593)
@@ -184,4 +184,18 @@
     return rc;
 }
+
+
+#ifdef IN_RING3
+/**
+ * Called when IPRT was first initialized in unobtrusive mode and later changed
+ * to obtrustive.
+ *
+ * This is only applicable in ring-3.
+ */
+DECLHIDDEN(void) rtThreadReInitObtrusive(void)
+{
+    rtThreadNativeReInitObtrusive();
+}
+#endif
 
 
Index: /trunk/src/VBox/Runtime/include/internal/ldr.h
===================================================================
--- /trunk/src/VBox/Runtime/include/internal/ldr.h	(revision 46592)
+++ /trunk/src/VBox/Runtime/include/internal/ldr.h	(revision 46593)
@@ -459,5 +459,9 @@
     /** The native handle. */
     uintptr_t           hNative;
-} RTLDRMODNATIVE, *PRTLDRMODNATIVE;
+    /** The load flags (RTLDRLOAD_FLAGS_XXX). */
+    uint32_t            fFlags;
+} RTLDRMODNATIVE;
+/** Pointer to a native module. */
+typedef RTLDRMODNATIVE *PRTLDRMODNATIVE;
 
 /** @copydoc RTLDROPS::pfnGetSymbol */
@@ -472,8 +476,19 @@
  * @param   pszFilename     The image filename.
  * @param   phHandle        Where to store the module handle on success.
- * @param   fFlags          See RTLDRFLAGS_.
+ * @param   fFlags          RTLDRLOAD_FLAGS_XXX.
  * @param   pErrInfo        Where to return extended error information. Optional.
  */
 int rtldrNativeLoad(const char *pszFilename, uintptr_t *phHandle, uint32_t fFlags, PRTERRINFO pErrInfo);
+
+/**
+ * Load a system library.
+ *
+ * @returns iprt status code.
+ * @param   pszFilename     The image filename.
+ * @param   pszExt          Extension to add. NULL if none.
+ * @param   fFlags          RTLDRLOAD_FLAGS_XXX.
+ * @param   phLdrMod        Where to return the module handle on success.
+ */
+int rtldrNativeLoadSystem(const char *pszFilename, const char *pszExt, uint32_t fFlags, PRTLDRMOD phLdrMod);
 
 int rtldrPEOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF offNtHdrs, PRTLDRMOD phLdrMod);
Index: /trunk/src/VBox/Runtime/include/internal/thread.h
===================================================================
--- /trunk/src/VBox/Runtime/include/internal/thread.h	(revision 46592)
+++ /trunk/src/VBox/Runtime/include/internal/thread.h	(revision 46593)
@@ -140,4 +140,14 @@
 DECLHIDDEN(int) rtThreadNativeInit(void);
 
+#ifdef IN_RING3
+/**
+ * Called when IPRT was first initialized in unobtrusive mode and later changed
+ * to obtrustive.
+ *
+ * This is only applicable in ring-3.
+ */
+DECLHIDDEN(void) rtThreadNativeReInitObtrusive(void);
+#endif
+
 /**
  * Create a native thread.
@@ -200,4 +210,7 @@
 DECLHIDDEN(PRTTHREADINT) rtThreadGet(RTTHREAD Thread);
 DECLHIDDEN(int)          rtThreadInit(void);
+#ifdef IN_RING3
+DECLHIDDEN(void)         rtThreadReInitObtrusive(void);
+#endif
 DECLHIDDEN(void)         rtThreadTerm(void);
 DECLHIDDEN(void)         rtThreadInsert(PRTTHREADINT pThread, RTNATIVETHREAD NativeThread);
Index: /trunk/src/VBox/Runtime/r3/init.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/init.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/r3/init.cpp	(revision 46593)
@@ -67,8 +67,8 @@
 #include <stdlib.h>
 
+#include "init.h"
 #include "internal/alignmentchecks.h"
 #include "internal/path.h"
 #include "internal/process.h"
-#include "internal/thread.h"
 #include "internal/thread.h"
 #include "internal/time.h"
@@ -140,4 +140,13 @@
  */
 RTDATADECL(bool) g_fRTAlignmentChecks = false;
+#endif
+
+
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_HAIKU) \
+ || defined(RT_OS_LINUX)  || defined(RT_OS_OS2)     || defined(RT_OS_SOLARIS) /** @todo add host init hooks everywhere. */
+/* Stubs */
+DECLHIDDEN(int)  rtR3InitNativeFirst(uint32_t fFlags) { return VINF_SUCCESS; }
+DECLHIDDEN(int)  rtR3InitNativeFinal(uint32_t fFlags) { return VINF_SUCCESS; }
+DECLHIDDEN(void) rtR3InitNativeObtrusive(void) { }
 #endif
 
@@ -351,4 +360,17 @@
 {
     /*
+     * Early native initialization.
+     */
+    int rc = rtR3InitNativeFirst(fFlags);
+    AssertMsgRCReturn(rc, ("rtR3InitNativeFirst failed with %Rrc\n", rc), rc);
+
+    /*
+     * Disable error popups.
+     */
+#if defined(RT_OS_OS2) /** @todo move to private code. */
+    DosError(FERR_DISABLEHARDERR);
+#endif
+
+    /*
      * Init C runtime locale before we do anything that may end up converting
      * paths or we'll end up using the "C" locale for path conversion.
@@ -366,14 +388,4 @@
 
     /*
-     * Disable error popups.
-     */
-#ifdef RT_OS_WINDOWS
-    UINT fOldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
-    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX | fOldErrMode);
-#elif defined(RT_OS_OS2)
-    DosError(FERR_DISABLEHARDERR);
-#endif
-
-    /*
      * Save the init flags.
      */
@@ -403,5 +415,5 @@
      * without having initialized TLS entries and suchlike.
      */
-    int rc = rtThreadInit();
+    rc = rtThreadInit();
     AssertMsgRCReturn(rc, ("Failed to initialize threads, rc=%Rrc!\n", rc), rc);
 
@@ -505,4 +517,10 @@
 #endif
 
+    /*
+     * Final native initialization.
+     */
+    rc = rtR3InitNativeFinal(fFlags);
+    AssertMsgRCReturn(rc, ("rtR3InitNativeFinal failed with %Rrc\n", rc), rc);
+
     return VINF_SUCCESS;
 }
@@ -546,8 +564,16 @@
         }
 #endif
-        if (!pszProgramPath)
-            return VINF_SUCCESS;
-
-        int rc = rtR3InitProgramPath(pszProgramPath);
+
+        if (   !(fFlags      & RTR3INIT_FLAGS_UNOBTRUSIVE)
+            && (g_fInitFlags & RTR3INIT_FLAGS_UNOBTRUSIVE))
+        {
+            g_fInitFlags &= ~RTR3INIT_FLAGS_UNOBTRUSIVE;
+            rtR3InitNativeObtrusive();
+            rtThreadReInitObtrusive();
+        }
+
+        int rc = VINF_SUCCESS;
+        if (pszProgramPath)
+            rc = rtR3InitProgramPath(pszProgramPath);
         if (RT_SUCCESS(rc))
             rc = rtR3InitArgv(fFlags, cArgs, papszArgs);
Index: /trunk/src/VBox/Runtime/r3/init.h
===================================================================
--- /trunk/src/VBox/Runtime/r3/init.h	(revision 46593)
+++ /trunk/src/VBox/Runtime/r3/init.h	(revision 46593)
@@ -0,0 +1,58 @@
+/* $Id$ */
+/** @file
+ * IPRT - Ring-3 initialization.
+ */
+
+/*
+ * Copyright (C) 2006-2013 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+
+#ifndef ___r3_init_h
+#define ___r3_init_h
+
+#include <iprt/types.h>
+
+DECLHIDDEN(int)  rtR3InitNativeFirst(uint32_t fFlags);
+DECLHIDDEN(int)  rtR3InitNativeFinal(uint32_t fFlags);
+DECLHIDDEN(void) rtR3InitNativeObtrusive();
+
+#ifdef RT_OS_WINDOWS
+/*
+ * Windows specific stuff.
+ */
+typedef enum RTR3WINLDRPROT
+{
+    RTR3WINLDRPROT_INVALID = 0,
+    RTR3WINLDRPROT_NONE,
+    RTR3WINLDRPROT_NO_CWD,
+    RTR3WINLDRPROT_SAFE
+} RTR3WINLDRPROT;
+
+extern DECLHIDDEN(RTR3WINLDRPROT)  g_enmWinLdrProt;
+# ifdef _WINDEF_
+extern DECLHIDDEN(HMODULE)         g_hModKernel32;
+extern DECLHIDDEN(HMODULE)         g_hModNtDll;
+# endif
+
+#endif /* RT_OS_WINDOWS */
+
+#endif
+
Index: /trunk/src/VBox/Runtime/r3/os2/thread-os2.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/os2/thread-os2.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/r3/os2/thread-os2.cpp	(revision 46593)
@@ -79,5 +79,5 @@
 
 
-DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
+static void rtThreadOs2BlockSigAlarm(void)
 {
     /*
@@ -90,4 +90,15 @@
     sigaddset(&SigSet, SIGALRM);
     sigprocmask(SIG_BLOCK, &SigSet, NULL);
+}
+
+
+DECLHIDDEN(void) rtThreadNativeReInitObtrusive(void)
+{
+    rtThreadOs2BlockSigAlarm();
+}
+
+
+DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
+{
 
     *g_ppCurThread = pThread;
@@ -108,13 +119,5 @@
 static void rtThreadNativeMain(void *pvArgs)
 {
-    /*
-     * Block SIGALRM - required for timer-posix.cpp.
-     * This is done to limit harm done by OSes which doesn't do special SIGALRM scheduling.
-     * It will not help much if someone creates threads directly using pthread_create. :/
-     */
-    sigset_t SigSet;
-    sigemptyset(&SigSet);
-    sigaddset(&SigSet, SIGALRM);
-    sigprocmask(SIG_BLOCK, &SigSet, NULL);
+    rtThreadOs2BlockSigAlarm();
 
     /*
Index: /trunk/src/VBox/Runtime/r3/posix/ldrNative-posix.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/posix/ldrNative-posix.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/r3/posix/ldrNative-posix.cpp	(revision 46593)
@@ -109,5 +109,6 @@
 {
     PRTLDRMODNATIVE pModNative = (PRTLDRMODNATIVE)pMod;
-    if (!dlclose((void *)pModNative->hNative))
+    if (   (pModNative->fFlags & RTLDRLOAD_FLAGS_NO_UNLOAD)
+        || !dlclose((void *)pModNative->hNative))
     {
         pModNative->hNative = (uintptr_t)0;
@@ -118,2 +119,9 @@
 }
 
+
+int rtldrNativeLoadSystem(const char *pszFilename, const char *pszExt, uint32_t fFlags, PRTLDRMOD phLdrMod)
+{
+    /** @todo implement this in some sensible fashion. */
+    return VERR_NOT_SUPPORTED;
+}
+
Index: /trunk/src/VBox/Runtime/r3/posix/thread-posix.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/posix/thread-posix.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/r3/posix/thread-posix.cpp	(revision 46593)
@@ -121,18 +121,12 @@
 
 
-DECLHIDDEN(int) rtThreadNativeInit(void)
-{
-    /*
-     * Allocate the TLS (key in posix terms) where we store the pointer to
-     * a threads RTTHREADINT structure.
-     */
-    int rc = pthread_key_create(&g_SelfKey, rtThreadKeyDestruct);
-    if (rc)
-        return VERR_NO_TLS_FOR_SELF;
-
-#ifdef RTTHREAD_POSIX_WITH_POKE
-    /*
-     * Try register the dummy signal handler for RTThreadPoke.
-     * Avoid SIGRTMIN thru SIGRTMIN+2 because of LinuxThreads.
+#ifdef RTTHREAD_POSIX_WITH_POKE
+/**
+ * Try register the dummy signal handler for RTThreadPoke.
+ */
+static void rtThreadPosixSelectPokeSignal(void)
+{
+    /*
+     * Note! Avoid SIGRTMIN thru SIGRTMIN+2 because of LinuxThreads.
      */
     static const int s_aiSigCandidates[] =
@@ -179,5 +173,21 @@
         }
     }
+}
 #endif /* RTTHREAD_POSIX_WITH_POKE */
+
+
+DECLHIDDEN(int) rtThreadNativeInit(void)
+{
+    /*
+     * Allocate the TLS (key in posix terms) where we store the pointer to
+     * a threads RTTHREADINT structure.
+     */
+    int rc = pthread_key_create(&g_SelfKey, rtThreadKeyDestruct);
+    if (rc)
+        return VERR_NO_TLS_FOR_SELF;
+
+#ifdef RTTHREAD_POSIX_WITH_POKE
+    rtThreadPosixSelectPokeSignal();
+#endif
 
 #ifdef IPRT_MAY_HAVE_PTHREAD_SET_NAME_NP
@@ -188,45 +198,5 @@
 }
 
-
-/**
- * Destructor called when a thread terminates.
- * @param   pvValue     The key value. PRTTHREAD in our case.
- */
-static void rtThreadKeyDestruct(void *pvValue)
-{
-    /*
-     * Deal with alien threads.
-     */
-    PRTTHREADINT pThread = (PRTTHREADINT)pvValue;
-    if (pThread->fIntFlags & RTTHREADINT_FLAGS_ALIEN)
-    {
-        pthread_setspecific(g_SelfKey, pThread);
-        rtThreadTerminate(pThread, 0);
-        pthread_setspecific(g_SelfKey, NULL);
-    }
-}
-
-
-#ifdef RTTHREAD_POSIX_WITH_POKE
-/**
- * Dummy signal handler for the poke signal.
- *
- * @param   iSignal     The signal number.
- */
-static void rtThreadPosixPokeSignal(int iSignal)
-{
-    Assert(iSignal == g_iSigPokeThread);
-    NOREF(iSignal);
-}
-#endif
-
-
-/**
- * Adopts a thread, this is called immediately after allocating the
- * thread structure.
- *
- * @param   pThread     Pointer to the thread structure.
- */
-DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
+static void rtThreadPosixBlockSignals(void)
 {
     /*
@@ -246,4 +216,58 @@
         siginterrupt(g_iSigPokeThread, 1);
 #endif
+}
+
+DECLHIDDEN(void) rtThreadNativeReInitObtrusive(void)
+{
+#ifdef RTTHREAD_POSIX_WITH_POKE
+    Assert(!RTR3InitIsUnobtrusive());
+    rtThreadPosixSelectPokeSignal();
+#endif
+    rtThreadPosixBlockSignals();
+}
+
+
+/**
+ * Destructor called when a thread terminates.
+ * @param   pvValue     The key value. PRTTHREAD in our case.
+ */
+static void rtThreadKeyDestruct(void *pvValue)
+{
+    /*
+     * Deal with alien threads.
+     */
+    PRTTHREADINT pThread = (PRTTHREADINT)pvValue;
+    if (pThread->fIntFlags & RTTHREADINT_FLAGS_ALIEN)
+    {
+        pthread_setspecific(g_SelfKey, pThread);
+        rtThreadTerminate(pThread, 0);
+        pthread_setspecific(g_SelfKey, NULL);
+    }
+}
+
+
+#ifdef RTTHREAD_POSIX_WITH_POKE
+/**
+ * Dummy signal handler for the poke signal.
+ *
+ * @param   iSignal     The signal number.
+ */
+static void rtThreadPosixPokeSignal(int iSignal)
+{
+    Assert(iSignal == g_iSigPokeThread);
+    NOREF(iSignal);
+}
+#endif
+
+
+/**
+ * Adopts a thread, this is called immediately after allocating the
+ * thread structure.
+ *
+ * @param   pThread     Pointer to the thread structure.
+ */
+DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
+{
+    rtThreadPosixBlockSignals();
 
     int rc = pthread_setspecific(g_SelfKey, pThread);
@@ -278,17 +302,5 @@
 #endif
 
-    /*
-     * Block SIGALRM - required for timer-posix.cpp.
-     * This is done to limit harm done by OSes which doesn't do special SIGALRM scheduling.
-     * It will not help much if someone creates threads directly using pthread_create. :/
-     */
-    sigset_t SigSet;
-    sigemptyset(&SigSet);
-    sigaddset(&SigSet, SIGALRM);
-    sigprocmask(SIG_BLOCK, &SigSet, NULL);
-#ifdef RTTHREAD_POSIX_WITH_POKE
-    if (g_iSigPokeThread != -1)
-        siginterrupt(g_iSigPokeThread, 1);
-#endif
+    rtThreadPosixBlockSignals();
 
     /*
Index: /trunk/src/VBox/Runtime/r3/win/init-win.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/win/init-win.cpp	(revision 46593)
+++ /trunk/src/VBox/Runtime/r3/win/init-win.cpp	(revision 46593)
@@ -0,0 +1,129 @@
+/* $Id$ */
+/** @file
+ * IPRT - Init Ring-3, Windows Specific Code.
+ */
+
+/*
+ * Copyright (C) 2006-2013 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define LOG_GROUP RTLOGGROUP_DEFAULT
+#include <Windows.h>
+#ifndef LOAD_LIBRARY_SEARCH_APPLICATION_DIR
+# define LOAD_LIBRARY_SEARCH_APPLICATION_DIR    0x200
+# define LOAD_LIBRARY_SEARCH_SYSTEM32           0x800
+#endif
+
+#include "internal/iprt.h"
+#include <iprt/initterm.h>
+#include <iprt/err.h>
+#include "../init.h"
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+/** The native kernel32.dll handle. */
+DECLHIDDEN(HMODULE)         g_hModKernel32 = NULL;
+/** The native ntdll.dll handle. */
+DECLHIDDEN(HMODULE)         g_hModNtDll = NULL;
+/** Windows DLL loader protection level. */
+DECLHIDDEN(RTR3WINLDRPROT)  g_enmWinLdrProt = RTR3WINLDRPROT_NONE;
+
+
+DECLHIDDEN(int) rtR3InitNativeObtrusiveWorker(void)
+{
+    /*
+     * Disable error popups.
+     */
+    UINT fOldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
+    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX | fOldErrMode);
+
+    /*
+     * Restrict DLL searching for the process on windows versions which allow
+     * us to do so.
+     *  - The first trick works on XP SP1+ and disables the searching of the
+     *    current directory.
+     *  - The second trick is W7 w/ KB2533623 and W8+, it restrict the DLL
+     *    searching to the application directory and the System32 directory.
+     */
+    int rc = VINF_SUCCESS;
+
+    typedef BOOL (WINAPI *PFNSETDLLDIRECTORY)(LPCWSTR);
+    PFNSETDLLDIRECTORY pfnSetDllDir = (PFNSETDLLDIRECTORY)GetProcAddress(g_hModKernel32, "SetDllDirectoryW");
+    if (pfnSetDllDir)
+    {
+        if (pfnSetDllDir(L""))
+            g_enmWinLdrProt = RTR3WINLDRPROT_NO_CWD;
+        else
+            rc = VERR_INTERNAL_ERROR_3;
+    }
+
+    typedef BOOL (WINAPI *PFNSETDEFAULTDLLDIRECTORIES)(DWORD);
+    PFNSETDEFAULTDLLDIRECTORIES pfnSetDefDllDirs;
+    pfnSetDefDllDirs = (PFNSETDEFAULTDLLDIRECTORIES)GetProcAddress(g_hModKernel32, "SetDefaultDllDirectories");
+    if (pfnSetDefDllDirs)
+    {
+        if (pfnSetDefDllDirs(LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32))
+            g_enmWinLdrProt = RTR3WINLDRPROT_SAFE;
+        else if (RT_SUCCESS(rc))
+            rc = VERR_INTERNAL_ERROR_4;
+    }
+
+    return rc;
+}
+
+
+DECLHIDDEN(int) rtR3InitNativeFirst(uint32_t fFlags)
+{
+    /*
+     * Make sure we've got the handles of the two main Windows NT dlls.
+     */
+    g_hModKernel32 = GetModuleHandleW(L"kernel32.dll");
+    if (g_hModKernel32 == NULL)
+        return VERR_INTERNAL_ERROR_2;
+    g_hModNtDll    = GetModuleHandleW(L"ntdll.dll");
+    if (g_hModNtDll == NULL)
+        return VERR_INTERNAL_ERROR_2;
+
+    int rc = VINF_SUCCESS;
+    if (!(fFlags & RTR3INIT_FLAGS_UNOBTRUSIVE))
+        rc = rtR3InitNativeObtrusiveWorker();
+
+    return rc;
+}
+
+
+DECLHIDDEN(void) rtR3InitNativeObtrusive(void)
+{
+    rtR3InitNativeObtrusiveWorker();
+}
+
+
+DECLHIDDEN(int) rtR3InitNativeFinal(uint32_t fFlags)
+{
+    /* Nothing to do here. */
+    return VINF_SUCCESS;
+}
+
Index: /trunk/src/VBox/Runtime/r3/win/ldrNative-win.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/win/ldrNative-win.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/r3/win/ldrNative-win.cpp	(revision 46593)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2010 Oracle Corporation
+ * Copyright (C) 2006-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -32,35 +32,22 @@
 
 #include <iprt/ldr.h>
+#include "internal/iprt.h"
+
+#include <iprt/alloca.h>
 #include <iprt/assert.h>
+#include <iprt/err.h>
+#include <iprt/file.h>
 #include <iprt/path.h>
-#include <iprt/err.h>
-#include <iprt/alloca.h>
+#include <iprt/string.h>
+
 #include <iprt/once.h>
 #include <iprt/string.h>
 #include "internal/ldr.h"
 
-static RTONCE g_Once = RTONCE_INITIALIZER;
-
-static DECLCALLBACK(int) rtldrOnceSetDllDirectory(void *pvUser)
-{
-    HMODULE hmod = GetModuleHandle(TEXT("kernel32.dll"));
-    if (hmod)
-    {
-        typedef BOOLEAN (WINAPI *PFNSETDLLDIRECTORY)(LPCWSTR);
-        PFNSETDLLDIRECTORY pfn = (PFNSETDLLDIRECTORY)GetProcAddress(hmod, "SetDllDirectoryW");
-        if (pfn)
-        {
-            BOOL fOk = pfn(L"");
-            if (!fOk)
-                return RTErrConvertFromWin32(GetLastError());
-        }
-    }
-    return VINF_SUCCESS;
-}
 
 int rtldrNativeLoad(const char *pszFilename, uintptr_t *phHandle, uint32_t fFlags, PRTERRINFO pErrInfo)
 {
     Assert(sizeof(*phHandle) >= sizeof(HMODULE));
-    AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER);
+    AssertReturn(fFlags == 0 || fFlags == RTLDRLOAD_FLAGS_NO_UNLOAD, VERR_INVALID_PARAMETER);
 
     /*
@@ -79,15 +66,4 @@
 
     /*
-     * Don't allow loading DLLs from the current directory.
-     */
-#if 0
-    int rc = RTOnce(&g_Once, rtldrOnceSetDllDirectory, NULL);
-    if (RT_FAILURE(rc))
-        return rc;
-#else
-    int rc = VINF_SUCCESS;
-#endif
-
-    /*
      * Attempt load.
      */
@@ -103,5 +79,5 @@
      */
     DWORD dwErr = GetLastError();
-    rc = RTErrConvertFromWin32(dwErr);
+    int rc = RTErrConvertFromWin32(dwErr);
     return RTErrInfoSetF(pErrInfo, rc, "GetLastError=%u", dwErr);
 }
@@ -125,5 +101,6 @@
 {
     PRTLDRMODNATIVE pModNative = (PRTLDRMODNATIVE)pMod;
-    if (FreeLibrary((HMODULE)pModNative->hNative))
+    if (   (pModNative->fFlags & RTLDRLOAD_FLAGS_NO_UNLOAD)
+        || FreeLibrary((HMODULE)pModNative->hNative))
     {
         pModNative->hNative = (uintptr_t)INVALID_HANDLE_VALUE;
@@ -133,2 +110,33 @@
 }
 
+
+int rtldrNativeLoadSystem(const char *pszFilename, const char *pszExt, uint32_t fFlags, PRTLDRMOD phLdrMod)
+{
+    /*
+     * We only try the System32 directory.
+     */
+    WCHAR wszSysDir[MAX_PATH];
+    UINT cwcSysDir = GetSystemDirectoryW(wszSysDir, MAX_PATH);
+    if (cwcSysDir >= MAX_PATH)
+        return VERR_FILENAME_TOO_LONG;
+
+    char szPath[RTPATH_MAX];
+    char *pszPath = szPath;
+    int rc = RTUtf16ToUtf8Ex(wszSysDir, RTSTR_MAX, &pszPath, sizeof(szPath), NULL);
+    if (RT_SUCCESS(rc))
+    {
+        rc = RTPathAppend(szPath, sizeof(szPath), pszFilename);
+        if (pszExt && RT_SUCCESS(rc))
+            rc = RTStrCat(szPath, sizeof(szPath), pszExt);
+        if (RT_SUCCESS(rc))
+        {
+            if (RTFileExists(szPath))
+                rc = RTLdrLoadEx(szPath, phLdrMod, fFlags, NULL);
+            else
+                rc = VERR_MODULE_NOT_FOUND;
+        }
+    }
+
+    return rc;
+}
+
Index: /trunk/src/VBox/Runtime/r3/win/process-win.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/win/process-win.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/r3/win/process-win.cpp	(revision 46593)
@@ -58,4 +58,6 @@
 #include <iprt/string.h>
 #include <iprt/socket.h>
+
+#include "../init.h"
 
 
@@ -422,75 +424,71 @@
      * Load PSAPI.DLL and resolve the two symbols we need.
      */
-    RTLDRMOD hPsApi;
-    int rc = RTLdrLoad("PSAPI.dll", &hPsApi);
-    if (RT_FAILURE_NP(rc))
+    PFNGETMODULEBASENAME pfnGetModuleBaseName = (PFNGETMODULEBASENAME)RTLdrGetSystemSymbol("psapi.dll", "GetModuleBaseName");
+    if (!pfnGetModuleBaseName)
         return false;
-    PFNGETMODULEBASENAME    pfnGetModuleBaseName;
-    PFNENUMPROCESSES        pfnEnumProcesses;
-    rc = RTLdrGetSymbol(hPsApi, "EnumProcesses", (void**)&pfnEnumProcesses);
+    PFNENUMPROCESSES pfnEnumProcesses = (PFNENUMPROCESSES)RTLdrGetSystemSymbol("psapi.dll", "EnumProcesses");
+    if (!pfnEnumProcesses)
+        return false;
+
+    /*
+     * Get a list of PID.  We retry if it looks like there are more PIDs
+     * to be returned than what we supplied buffer space for.
+     */
+    int    rc = VINF_SUCCESS;
+    DWORD  cbPidsAllocated = 4096;
+    DWORD  cbPidsReturned  = 0;
+    DWORD *paPids;
+    for (;;)
+    {
+        paPids = (DWORD *)RTMemTmpAlloc(cbPidsAllocated);
+        AssertBreakStmt(paPids, rc = VERR_NO_TMP_MEMORY);
+        if (!pfnEnumProcesses(paPids, cbPidsAllocated, &cbPidsReturned))
+        {
+            rc = RTErrConvertFromWin32(GetLastError());
+            AssertMsgFailedBreak(("%Rrc\n", rc));
+        }
+        if (   cbPidsReturned < cbPidsAllocated
+            || cbPidsAllocated >= _512K)
+            break;
+        RTMemTmpFree(paPids);
+        cbPidsAllocated *= 2;
+    }
     if (RT_SUCCESS(rc))
-        rc = RTLdrGetSymbol(hPsApi, "GetModuleBaseName", (void**)&pfnGetModuleBaseName);
-    if (RT_SUCCESS(rc))
     {
         /*
-         * Get a list of PID.  We retry if it looks like there are more PIDs
-         * to be returned than what we supplied buffer space for.
+         * Search for the process.
+         *
+         * We ASSUME that the caller won't be specifying any names longer
+         * than RTPATH_MAX.
          */
-        DWORD  cbPidsAllocated = 4096;
-        DWORD  cbPidsReturned  = 0;
-        DWORD *paPids;
-        for (;;)
-        {
-            paPids = (DWORD *)RTMemTmpAlloc(cbPidsAllocated);
-            AssertBreakStmt(paPids, rc = VERR_NO_TMP_MEMORY);
-            if (!pfnEnumProcesses(paPids, cbPidsAllocated, &cbPidsReturned))
+        DWORD cbProcName  = RTPATH_MAX;
+        char *pszProcName = (char *)RTMemTmpAlloc(RTPATH_MAX);
+        if (pszProcName)
+        {
+            for (size_t i = 0; papszNames[i] && !fFound; i++)
             {
-                rc = RTErrConvertFromWin32(GetLastError());
-                AssertMsgFailedBreak(("%Rrc\n", rc));
-            }
-            if (   cbPidsReturned < cbPidsAllocated
-                || cbPidsAllocated >= _512K)
-                break;
-            RTMemTmpFree(paPids);
-            cbPidsAllocated *= 2;
-        }
-        if (RT_SUCCESS(rc))
-        {
-            /*
-             * Search for the process.
-             *
-             * We ASSUME that the caller won't be specifying any names longer
-             * than RTPATH_MAX.
-             */
-            DWORD cbProcName  = RTPATH_MAX;
-            char *pszProcName = (char *)RTMemTmpAlloc(RTPATH_MAX);
-            if (pszProcName)
-            {
-                for (size_t i = 0; papszNames[i] && !fFound; i++)
+                const DWORD cPids = cbPidsReturned / sizeof(DWORD);
+                for (DWORD iPid = 0; iPid < cPids && !fFound; iPid++)
                 {
-                    const DWORD cPids = cbPidsReturned / sizeof(DWORD);
-                    for (DWORD iPid = 0; iPid < cPids && !fFound; iPid++)
+                    HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, paPids[iPid]);
+                    if (hProc)
                     {
-                        HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, paPids[iPid]);
-                        if (hProc)
-                        {
-                            *pszProcName = '\0';
-                            DWORD cbRet = pfnGetModuleBaseName(hProc, 0 /*hModule = exe */, pszProcName, cbProcName);
-                            if (   cbRet > 0
-                                && _stricmp(pszProcName, papszNames[i]) == 0
-                                && RT_SUCCESS(rtProcWinGetProcessTokenHandle(paPids[iPid], pSid, phToken)))
-                                fFound = true;
-                            CloseHandle(hProc);
-                        }
+                        *pszProcName = '\0';
+                        DWORD cbRet = pfnGetModuleBaseName(hProc, 0 /*hModule = exe */, pszProcName, cbProcName);
+                        if (   cbRet > 0
+                            && _stricmp(pszProcName, papszNames[i]) == 0
+                            && RT_SUCCESS(rtProcWinGetProcessTokenHandle(paPids[iPid], pSid, phToken)))
+                            fFound = true;
+                        CloseHandle(hProc);
                     }
                 }
-                RTMemTmpFree(pszProcName);
             }
-            else
-                rc = VERR_NO_TMP_MEMORY;
-        }
-        RTMemTmpFree(paPids);
-    }
-    RTLdrClose(hPsApi);
+            RTMemTmpFree(pszProcName);
+        }
+        else
+            rc = VERR_NO_TMP_MEMORY;
+    }
+    RTMemTmpFree(paPids);
+
     return fFound;
 }
@@ -519,57 +517,46 @@
      * and reliable.  Fallback to EnumProcess on NT4.
      */
-    RTLDRMOD hKernel32;
-    int rc = RTLdrLoad("Kernel32.dll", &hKernel32);
-    if (RT_SUCCESS(rc))
-    {
-        PFNCREATETOOLHELP32SNAPSHOT pfnCreateToolhelp32Snapshot;
-        PFNPROCESS32FIRST           pfnProcess32First;
-        PFNPROCESS32NEXT            pfnProcess32Next;
-        rc = RTLdrGetSymbol(hKernel32, "CreateToolhelp32Snapshot", (void **)&pfnCreateToolhelp32Snapshot);
-        if (RT_SUCCESS(rc))
-            rc = RTLdrGetSymbol(hKernel32, "Process32First", (void**)&pfnProcess32First);
-        if (RT_SUCCESS(rc))
-            rc = RTLdrGetSymbol(hKernel32, "Process32Next", (void**)&pfnProcess32Next);
-
-        if (RT_SUCCESS(rc))
-        {
-            HANDLE hSnap = pfnCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
-            if (hSnap != INVALID_HANDLE_VALUE)
+    PFNCREATETOOLHELP32SNAPSHOT pfnCreateToolhelp32Snapshot;
+    pfnCreateToolhelp32Snapshot = (PFNCREATETOOLHELP32SNAPSHOT)GetProcAddress(g_hModKernel32, "CreateToolhelp32Snapshot");
+    PFNPROCESS32FIRST pfnProcess32First = (PFNPROCESS32FIRST)GetProcAddress(g_hModKernel32, "Process32First");
+    PFNPROCESS32NEXT  pfnProcess32Next  = (PFNPROCESS32NEXT )GetProcAddress(g_hModKernel32, "Process32Next");
+    bool fFallback = true;
+    if (pfnProcess32Next && pfnProcess32First && pfnCreateToolhelp32Snapshot)
+    {
+        HANDLE hSnap = pfnCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+        if (hSnap != INVALID_HANDLE_VALUE)
+        {
+            fFallback = false;
+            for (size_t i = 0; papszNames[i] && !fFound; i++)
             {
-                for (size_t i = 0; papszNames[i] && !fFound; i++)
+                PROCESSENTRY32 procEntry;
+                procEntry.dwSize = sizeof(PROCESSENTRY32);
+                if (pfnProcess32First(hSnap, &procEntry))
                 {
-                    PROCESSENTRY32 procEntry;
-                    procEntry.dwSize = sizeof(PROCESSENTRY32);
-                    if (pfnProcess32First(hSnap, &procEntry))
+                    do
                     {
-                        do
+                        if (   _stricmp(procEntry.szExeFile, papszNames[i]) == 0
+                            && RT_SUCCESS(rtProcWinGetProcessTokenHandle(procEntry.th32ProcessID, pSid, phToken)))
                         {
-                            if (   _stricmp(procEntry.szExeFile, papszNames[i]) == 0
-                                && RT_SUCCESS(rtProcWinGetProcessTokenHandle(procEntry.th32ProcessID, pSid, phToken)))
-                            {
-                                fFound = true;
-                                break;
-                            }
-                        } while (pfnProcess32Next(hSnap, &procEntry));
-                    }
+                            fFound = true;
+                            break;
+                        }
+                    } while (pfnProcess32Next(hSnap, &procEntry));
+                }
 #ifdef RT_STRICT
-                    else
-                    {
-                        DWORD dwErr = GetLastError();
-                        AssertMsgFailed(("dwErr=%u (%x)\n", dwErr, dwErr));
-                    }
+                else
+                {
+                    DWORD dwErr = GetLastError();
+                    AssertMsgFailed(("dwErr=%u (%x)\n", dwErr, dwErr));
+                }
 #endif
-                }
-                CloseHandle(hSnap);
             }
-            else /* hSnap == INVALID_HANDLE_VALUE */
-                rc = RTErrConvertFromWin32(GetLastError());
-        }
-        RTLdrClose(hKernel32);
+            CloseHandle(hSnap);
+        }
     }
 
     /* If we couldn't take a process snapshot for some reason or another, fall
        back on the NT4 compatible API. */
-    if (RT_FAILURE(rc))
+    if (fFallback)
         return rtProcWinFindTokenByProcessAndPsApi(papszNames, pSid, phToken);
     return fFound;
@@ -689,5 +676,5 @@
 {
     RTLDRMOD hUserenv;
-    int rc = RTLdrLoad("Userenv.dll", &hUserenv);
+    int rc = RTLdrLoadSystem("Userenv.dll", true /*fNoUnload*/, &hUserenv);
     if (RT_SUCCESS(rc))
     {
@@ -881,5 +868,5 @@
             phToken = fFound ? &hTokenUserDesktop : &hTokenLogon;
             RTLDRMOD hUserenv;
-            int rc = RTLdrLoad("Userenv.dll", &hUserenv);
+            int rc = RTLdrLoadSystem("Userenv.dll", true /*fNoUnload*/, &hUserenv);
             if (RT_SUCCESS(rc))
             {
@@ -979,40 +966,34 @@
                                   STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo, uint32_t fFlags)
 {
-    RTLDRMOD hAdvAPI32;
-    int rc = RTLdrLoad("Advapi32.dll", &hAdvAPI32);
+    PFNCREATEPROCESSWITHLOGON pfnCreateProcessWithLogonW;
+    pfnCreateProcessWithLogonW = (PFNCREATEPROCESSWITHLOGON)RTLdrGetSystemSymbol("Advapi32.dll", "CreateProcessWithLogonW");
+    if (pfnCreateProcessWithLogonW)
+        return VERR_SYMBOL_NOT_FOUND;
+
+    PRTUTF16 pwszzBlock;
+    int rc = rtProcWinCreateEnvFromAccount(pwszUser, pwszPassword, NULL /* Domain */,
+                                           hEnv, &pwszzBlock);
     if (RT_SUCCESS(rc))
     {
-        PFNCREATEPROCESSWITHLOGON pfnCreateProcessWithLogonW;
-        rc = RTLdrGetSymbol(hAdvAPI32, "CreateProcessWithLogonW", (void **)&pfnCreateProcessWithLogonW);
-        if (RT_SUCCESS(rc))
-        {
-            PRTUTF16 pwszzBlock;
-            rc = rtProcWinCreateEnvFromAccount(pwszUser, pwszPassword, NULL /* Domain */,
-                                               hEnv, &pwszzBlock);
-            if (RT_SUCCESS(rc))
-            {
-                BOOL fRc = pfnCreateProcessWithLogonW(pwszUser,
-                                                      NULL,                       /* lpDomain*/
-                                                      pwszPassword,
-                                                      1 /*LOGON_WITH_PROFILE*/,   /* dwLogonFlags */
-                                                      pwszExec,
-                                                      pwszCmdLine,
-                                                      dwCreationFlags,
-                                                      pwszzBlock,
-                                                      NULL,                       /* pCurrentDirectory */
-                                                      pStartupInfo,
-                                                      pProcInfo);
-                if (!fRc)
-                {
-                    DWORD dwErr = GetLastError();
-                    rc = rtProcWinMapErrorCodes(dwErr);
-                    if (rc == VERR_UNRESOLVED_ERROR)
-                        LogRelFunc(("pfnCreateProcessWithLogonW (%p) failed: dwErr=%u (%#x), rc=%Rrc\n",
-                                    pfnCreateProcessWithLogonW, dwErr, dwErr, rc));
-                }
-                rtProcWinDestroyEnv(pwszzBlock);
-            }
-        }
-        RTLdrClose(hAdvAPI32);
+        BOOL fRc = pfnCreateProcessWithLogonW(pwszUser,
+                                              NULL,                       /* lpDomain*/
+                                              pwszPassword,
+                                              1 /*LOGON_WITH_PROFILE*/,   /* dwLogonFlags */
+                                              pwszExec,
+                                              pwszCmdLine,
+                                              dwCreationFlags,
+                                              pwszzBlock,
+                                              NULL,                       /* pCurrentDirectory */
+                                              pStartupInfo,
+                                              pProcInfo);
+        if (!fRc)
+        {
+            DWORD dwErr = GetLastError();
+            rc = rtProcWinMapErrorCodes(dwErr);
+            if (rc == VERR_UNRESOLVED_ERROR)
+                LogRelFunc(("pfnCreateProcessWithLogonW (%p) failed: dwErr=%u (%#x), rc=%Rrc\n",
+                            pfnCreateProcessWithLogonW, dwErr, dwErr, rc));
+        }
+        rtProcWinDestroyEnv(pwszzBlock);
     }
     return rc;
Index: /trunk/src/VBox/Runtime/r3/win/symlink-win.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/win/symlink-win.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/r3/win/symlink-win.cpp	(revision 46593)
@@ -42,4 +42,5 @@
 
 #include <Windows.h>
+#include "../init.h"
 
 
@@ -134,11 +135,7 @@
     if (!s_fTried)
     {
-        HMODULE hmod = LoadLibrary("KERNEL32.DLL");
-        if (hmod)
-        {
-            PFNCREATESYMBOLICLINKW pfn = (PFNCREATESYMBOLICLINKW)GetProcAddress(hmod, "CreateSymbolicLinkW");
-            if (pfn)
-                s_pfnCreateSymbolicLinkW = pfn;
-        }
+        PFNCREATESYMBOLICLINKW pfn = (PFNCREATESYMBOLICLINKW)GetProcAddress(g_hModKernel32, "CreateSymbolicLinkW");
+        if (pfn)
+            s_pfnCreateSymbolicLinkW = pfn;
         s_fTried = true;
     }
Index: /trunk/src/VBox/Runtime/r3/win/thread-win.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/win/thread-win.cpp	(revision 46592)
+++ /trunk/src/VBox/Runtime/r3/win/thread-win.cpp	(revision 46593)
@@ -69,4 +69,10 @@
 
 
+DECLHIDDEN(void) rtThreadNativeReInitObtrusive(void)
+{
+    /* nothing to do here. */
+}
+
+
 DECLHIDDEN(void) rtThreadNativeDetach(void)
 {
Index: /trunk/src/libs/libxml2-2.6.31/Makefile.kmk
===================================================================
--- /trunk/src/libs/libxml2-2.6.31/Makefile.kmk	(revision 46592)
+++ /trunk/src/libs/libxml2-2.6.31/Makefile.kmk	(revision 46593)
@@ -65,5 +65,4 @@
 	xmlreader.c \
 	xmlregexp.c \
-	xmlmodule.c \
 	xmlsave.c \
 	xmlschemas.c \
@@ -75,4 +74,6 @@
 	xmlstring.c
 
+# xmlmodule.c - not compiling this.
+
 # For linking:
 # VBox-libxml2_LDFLAGS.win    = /VERSION:$(LIBXML_MAJOR_VERSION).$(LIBXML_MINOR_VERSION)
Index: /trunk/src/libs/xpcom18a4/ipc/ipcd/shared/src/ipcLog.cpp
===================================================================
--- /trunk/src/libs/xpcom18a4/ipc/ipcd/shared/src/ipcLog.cpp	(revision 46592)
+++ /trunk/src/libs/xpcom18a4/ipc/ipcd/shared/src/ipcLog.cpp	(revision 46593)
@@ -106,5 +106,5 @@
 #ifdef VBOX
     // initialize VBox Runtime
-    RTR3InitDll(0);
+    RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
 
     PL_strncpyz(ipcLogPrefix, prefix, sizeof(ipcLogPrefix));
Index: /trunk/src/libs/xpcom18a4/java/src/nsJavaInterfaces.cpp
===================================================================
--- /trunk/src/libs/xpcom18a4/java/src/nsJavaInterfaces.cpp	(revision 46592)
+++ /trunk/src/libs/xpcom18a4/java/src/nsJavaInterfaces.cpp	(revision 46593)
@@ -147,5 +147,5 @@
 {
 #if defined(VBOX_PATH_APP_PRIVATE_ARCH) && defined(VBOX_PATH_SHARED_LIBS)
-    rv = RTR3InitDll(0);
+    rv = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
 #else
     const char *pszHome  = nsnull;
@@ -175,7 +175,7 @@
       memcpy(pszExePath, pszHome, cchHome);
       memcpy(pszExePath + cchHome, "/javafake", sizeof("/javafake"));
-      rv = RTR3InitEx(RTR3INIT_VER_CUR, RTR3INIT_FLAGS_DLL, 0, NULL, pszExePath);
+      rv = RTR3InitEx(RTR3INIT_VER_CUR, RTR3INIT_FLAGS_DLL | RTR3INIT_FLAGS_UNOBTRUSIVE, 0, NULL, pszExePath);
     } else {
-      rv = RTR3InitDll(0);
+      rv = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
     }
 
Index: /trunk/src/libs/xpcom18a4/nsprpub/pr/src/io/prlog.c
===================================================================
--- /trunk/src/libs/xpcom18a4/nsprpub/pr/src/io/prlog.c	(revision 46592)
+++ /trunk/src/libs/xpcom18a4/nsprpub/pr/src/io/prlog.c	(revision 46593)
@@ -424,5 +424,5 @@
     if (strcmp(file, "IPRT") == 0) {
         /* initialize VBox Runtime */
-        RTR3InitDll(0);
+        RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
         newLogFile = IPRT_DEBUG_FILE;
     }
@@ -465,5 +465,5 @@
     if (strcmp(file, "IPRT") == 0) {
         /* initialize VBox Runtime */
-        RTR3InitDll(0);
+        RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
         logFile = IPRT_DEBUG_FILE;
         return PR_TRUE;
Index: /trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c
===================================================================
--- /trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c	(revision 46592)
+++ /trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c	(revision 46593)
@@ -177,5 +177,5 @@
     _pr_initialized = PR_TRUE;
 #ifdef VBOX_USE_IPRT_IN_NSPR
-    RTR3InitDll(0);
+    RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
 #endif
 #ifdef _PR_ZONE_ALLOCATOR
Index: /trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp
===================================================================
--- /trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp	(revision 46592)
+++ /trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp	(revision 46593)
@@ -801,5 +801,5 @@
 
 #if defined(VBOX_PATH_APP_PRIVATE_ARCH) && defined(VBOX_PATH_SHARED_LIBS)
-    rc = RTR3InitDll(0);
+    rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
 #else
     const char *home = getenv("VBOX_PROGRAM_PATH");
@@ -809,7 +809,7 @@
       memcpy(exepath, home, len);
       memcpy(exepath + len, "/pythonfake", sizeof("/pythonfake"));
-      rc = RTR3InitEx(RTR3INIT_VER_CUR, RTR3INIT_FLAGS_DLL, 0, NULL, exepath);
+      rc = RTR3InitEx(RTR3INIT_VER_CUR, RTR3INIT_FLAGS_DLL | RTR3INIT_FLAGS_UNOBTRUSIVE, 0, NULL, exepath);
     } else {
-      rc = RTR3InitDll(0);
+      rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
     }
 #endif
