Changeset 46593 in vbox for trunk/src/VBox/Additions/WINNT/VBoxTray
- Timestamp:
- Jun 17, 2013 2:32:51 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 86471
- Location:
- trunk/src/VBox/Additions/WINNT/VBoxTray
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxLA.cpp
r43584 r46593 27 27 #include <iprt/alloc.h> 28 28 #include <iprt/list.h> 29 #include <iprt/ldr.h> 29 30 30 31 #define LALOG(a) do { if (gCtx.fLogEnabled) LogRel(a); } while(0) … … 87 88 char *pszPropWaitPattern; /* Which properties are monitored. */ 88 89 } activeClient; 89 90 HMODULE hModuleKernel32;91 90 92 91 BOOL (WINAPI * pfnProcessIdToSessionId)(DWORD dwProcessId, DWORD *pSessionId); … … 1250 1249 RT_ZERO(gCtx.activeClient); 1251 1250 1252 gCtx.hModuleKernel32 = LoadLibrary("KERNEL32"); 1253 1254 if (gCtx.hModuleKernel32) 1255 { 1256 *(uintptr_t *)&gCtx.pfnProcessIdToSessionId = (uintptr_t)GetProcAddress(gCtx.hModuleKernel32, "ProcessIdToSessionId"); 1257 } 1258 else 1259 { 1260 gCtx.pfnProcessIdToSessionId = NULL; 1261 } 1251 *(void **)&gCtx.pfnProcessIdToSessionId = RTLdrGetSystemSymbol("KERNEL32", "ProcessIdToSessionId"); 1262 1252 *pfStartThread = true; 1263 1253 *ppInstance = &gCtx; … … 1280 1270 ActionExecutorDeleteActions(&pCtx->listDetachActions); 1281 1271 1282 if (pCtx->hModuleKernel32) 1283 { 1284 FreeLibrary(pCtx->hModuleKernel32); 1285 pCtx->pfnProcessIdToSessionId = NULL; 1286 } 1287 pCtx->hModuleKernel32 = NULL; 1272 pCtx->pfnProcessIdToSessionId = NULL; 1288 1273 } 1289 1274 -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxMMR.cpp
r42295 r46593 18 18 #include "VBoxTray.h" 19 19 #include "VBoxMMR.h" 20 #include <iprt/ldr.h> 20 21 21 22 struct VBOXMMRCONTEXT 22 23 { 23 HINSTANCE hMod;24 RTLDRMOD hModHook; 24 25 HHOOK hHook; 25 26 }; … … 32 33 void VBoxMMRCleanup(VBOXMMRCONTEXT *pCtx) 33 34 { 34 if ( NULL !=pCtx->hHook)35 if (pCtx->hHook) 35 36 { 36 37 UnhookWindowsHookEx(pCtx->hHook); 38 pCtx->hHook = NULL; 37 39 } 38 40 39 if (pCtx->hMod )41 if (pCtx->hModHook != NIL_RTLDRMOD) 40 42 { 41 FreeLibrary(pCtx->hMod); 43 RTLdrClose(pCtx->hModHook); 44 pCtx->hModHook = NIL_RTLDRMOD; 42 45 } 43 44 return;45 46 } 46 47 … … 50 51 bool *pfStartThread) 51 52 { 52 HOOKPROC pHook = NULL;53 54 53 LogRel2(("VBoxMMR: Initializing\n")); 55 54 56 gCtx.hMod = LoadLibraryA(g_pszMMRDLL);57 if ( NULL == gCtx.hMod)55 int rc = RTLdrLoadAppPriv(g_pszMMRDLL, &gCtx.hModHook); 56 if (RT_SUCCESS(rc)) 58 57 { 59 LogRel2(("VBoxMMR: Hooking library not found\n")); 60 VBoxMMRCleanup(&gCtx); 61 return VERR_NOT_FOUND; 58 HOOKPROC pHook = (HOOKPROC)RTLdrGetFunction(gCtx.hModHook, g_pszMMRPROC); 59 if (pHook) 60 { 61 HMODULE hMod = (HMODULE)RTLdrGetNativeHandle(gCtx.hModHook); 62 Assert(hMod != (HMODULE)~(uintptr_t)0); 63 gCtx.hHook = SetWindowsHookEx(WH_CBT, pHook, hMod, 0); 64 if (gCtx.hHook) 65 { 66 *ppInstance = &gCtx; 67 return VINF_SUCCESS; 68 } 69 70 rc = RTErrConvertFromWin32(GetLastError()); 71 LogRel2(("VBoxMMR: Error installing hooking proc: %Rrc\n", rc)); 72 } 73 else 74 { 75 LogRel2(("VBoxMMR: Hooking proc not found\n")); 76 rc = VERR_NOT_FOUND; 77 } 62 78 } 79 else 80 LogRel2(("VBoxMMR: Hooking library not found (%Rrc)\n", rc)); 63 81 64 pHook = (HOOKPROC) GetProcAddress(gCtx.hMod, g_pszMMRPROC); 65 if (NULL == pHook) 66 { 67 LogRel2(("VBoxMMR: Hooking proc not found\n")); 68 VBoxMMRCleanup(&gCtx); 69 return VERR_NOT_FOUND; 70 } 71 72 gCtx.hHook = SetWindowsHookEx(WH_CBT, pHook, gCtx.hMod, 0); 73 if (NULL == gCtx.hHook) 74 { 75 int rc = RTErrConvertFromWin32(GetLastError()); 76 LogRel2(("VBoxMMR: Error installing hooking proc: %d\n", rc)); 77 VBoxMMRCleanup(&gCtx); 78 return rc; 79 } 80 81 *ppInstance = &gCtx; 82 83 return VINF_SUCCESS; 82 RTLdrClose(gCtx.hModHook); 83 gCtx.hModHook = NIL_RTLDRMOD; 84 return rc; 84 85 } 85 86 … … 95 96 return 0; 96 97 } 98 -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSeamless.cpp
r45760 r46593 25 25 #include <VBox/VMMDev.h> 26 26 #include <iprt/assert.h> 27 #include <iprt/ldr.h> 27 28 #include <VBoxGuestInternal.h> 28 29 … … 31 32 const VBOXSERVICEENV *pEnv; 32 33 33 HMODULE hModule;34 RTLDRMOD hModHook; 34 35 35 36 BOOL (* pfnVBoxHookInstallWindowTracker)(HMODULE hDll); … … 55 56 *pfStartThread = false; 56 57 gCtx.pEnv = pEnv; 58 gCtx.hModHook = NIL_RTLDRMOD; 57 59 58 60 OSVERSIONINFO OSinfo; … … 72 74 { 73 75 /* Will fail if SetWinEventHook is not present (version < NT4 SP6 apparently) */ 74 gCtx.hModule = LoadLibrary(VBOXHOOK_DLL_NAME);75 if ( gCtx.hModule)76 { 77 *( uintptr_t *)&gCtx.pfnVBoxHookInstallWindowTracker = (uintptr_t)GetProcAddress(gCtx.hModule, "VBoxHookInstallWindowTracker");78 *( uintptr_t *)&gCtx.pfnVBoxHookRemoveWindowTracker = (uintptr_t)GetProcAddress(gCtx.hModule, "VBoxHookRemoveWindowTracker");76 rc = RTLdrLoadAppPriv(VBOXHOOK_DLL_NAME, &gCtx.hModHook); 77 if (RT_SUCCESS(rc)) 78 { 79 *(PFNRT *)&gCtx.pfnVBoxHookInstallWindowTracker = RTLdrGetFunction(gCtx.hModHook, "VBoxHookInstallWindowTracker"); 80 *(PFNRT *)&gCtx.pfnVBoxHookRemoveWindowTracker = RTLdrGetFunction(gCtx.hModHook, "VBoxHookRemoveWindowTracker"); 79 81 80 82 /* rc should contain success status */ … … 90 92 } 91 93 else 92 {93 rc = RTErrConvertFromWin32(GetLastError());94 94 Log(("VBoxTray: VBoxSeamlessInit: LoadLibrary of \"%s\" failed with rc=%Rrc\n", VBOXHOOK_DLL_NAME, rc)); 95 }96 95 } 97 96 … … 109 108 if (gCtx.pfnVBoxHookRemoveWindowTracker) 110 109 gCtx.pfnVBoxHookRemoveWindowTracker(); 111 if (gCtx.hModule) 112 FreeLibrary(gCtx.hModule); 113 gCtx.hModule = 0; 110 if (gCtx.hModHook != NIL_RTLDRMOD) 111 { 112 RTLdrClose(gCtx.hModHook); 113 gCtx.hModHook = NIL_RTLDRMOD; 114 } 114 115 return; 115 116 } … … 122 123 VBoxSeamlessCheckWindows(); 123 124 124 gCtx.pfnVBoxHookInstallWindowTracker(gCtx.hModule); 125 HMODULE hMod = (HMODULE)RTLdrGetNativeHandle(gCtx.hModHook); 126 Assert(hMod != (HMODULE)~(uintptr_t)0); 127 gCtx.pfnVBoxHookInstallWindowTracker(hMod); 125 128 } 126 129 } -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp
r46428 r46593 41 41 42 42 #include <iprt/buildconfig.h> 43 #include <iprt/ldr.h> 43 44 44 45 /* Default desktop state tracking */ … … 63 64 * of the window passed to vboxStInit */ 64 65 static int vboxStInit(HWND hWnd); 65 static void vboxStTerm( );66 static void vboxStTerm(void); 66 67 /* @returns true on "IsActiveConsole" state change */ 67 68 static BOOL vboxStHandleEvent(WPARAM EventID, LPARAM SessionID); … … 549 550 { 550 551 BOOL (WINAPI * pfnConvertStringSecurityDescriptorToSecurityDescriptorA)(LPCSTR StringSecurityDescriptor, DWORD StringSDRevision, PSECURITY_DESCRIPTOR *SecurityDescriptor, PULONG SecurityDescriptorSize); 551 552 HMODULE hModule = LoadLibrary("ADVAPI32.DLL"); 553 if (!hModule) 554 { 555 dwErr = GetLastError(); 556 Log(("VBoxTray: Loading module ADVAPI32.DLL failed with last error = %08X\n", dwErr)); 557 } 558 else 552 *(void **)&pfnConvertStringSecurityDescriptorToSecurityDescriptorA = 553 RTLdrGetSystemSymbol("ADVAPI32.DLL", "ConvertStringSecurityDescriptorToSecurityDescriptorA"); 554 Log(("VBoxTray: pfnConvertStringSecurityDescriptorToSecurityDescriptorA = %x\n", pfnConvertStringSecurityDescriptorToSecurityDescriptorA)); 555 if (pfnConvertStringSecurityDescriptorToSecurityDescriptorA) 559 556 { 560 557 PSECURITY_DESCRIPTOR pSD; … … 563 560 BOOL fSaclDefaulted = FALSE; 564 561 565 *(uintptr_t *)&pfnConvertStringSecurityDescriptorToSecurityDescriptorA = (uintptr_t)GetProcAddress(hModule, "ConvertStringSecurityDescriptorToSecurityDescriptorA"); 566 567 Log(("VBoxTray: pfnConvertStringSecurityDescriptorToSecurityDescriptorA = %x\n", pfnConvertStringSecurityDescriptorToSecurityDescriptorA)); 568 if (pfnConvertStringSecurityDescriptorToSecurityDescriptorA) 562 fRC = pfnConvertStringSecurityDescriptorToSecurityDescriptorA("S:(ML;;NW;;;LW)", /* this means "low integrity" */ 563 SDDL_REVISION_1, &pSD, NULL); 564 if (!fRC) 569 565 { 570 fRC = pfnConvertStringSecurityDescriptorToSecurityDescriptorA("S:(ML;;NW;;;LW)", /* this means "low integrity" */ 571 SDDL_REVISION_1, &pSD, NULL); 566 dwErr = GetLastError(); 567 Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorA failed with last error = %08X\n", dwErr)); 568 } 569 else 570 { 571 fRC = GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted); 572 572 if (!fRC) 573 573 { 574 574 dwErr = GetLastError(); 575 Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorAfailed with last error = %08X\n", dwErr));575 Log(("VBoxTray: GetSecurityDescriptorSacl failed with last error = %08X\n", dwErr)); 576 576 } 577 577 else 578 578 { 579 fRC = GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted);579 fRC = SetSecurityDescriptorSacl(SecAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE); 580 580 if (!fRC) 581 581 { 582 582 dwErr = GetLastError(); 583 Log(("VBoxTray: GetSecurityDescriptorSacl failed with last error = %08X\n", dwErr)); 584 } 585 else 586 { 587 fRC = SetSecurityDescriptorSacl(SecAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE); 588 if (!fRC) 589 { 590 dwErr = GetLastError(); 591 Log(("VBoxTray: SetSecurityDescriptorSacl failed with last error = %08X\n", dwErr)); 592 } 583 Log(("VBoxTray: SetSecurityDescriptorSacl failed with last error = %08X\n", dwErr)); 593 584 } 594 585 } … … 1015 1006 { 1016 1007 HWND hWTSAPIWnd; 1017 HMODULE hWTSAPI32;1008 RTLDRMOD hLdrModWTSAPI32; 1018 1009 BOOL fIsConsole; 1019 1010 WTS_CONNECTSTATE_CLASS enmConnectState; … … 1032 1023 USHORT *pProtocolType = NULL; 1033 1024 DWORD cbBuf = 0; 1034 if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSConnectState, (LPTSTR *)&penmConnectState, &cbBuf)) 1035 { 1036 if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientProtocolType, (LPTSTR *)&pProtocolType, &cbBuf)) 1025 if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSConnectState, 1026 (LPTSTR *)&penmConnectState, &cbBuf)) 1027 { 1028 if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientProtocolType, 1029 (LPTSTR *)&pProtocolType, &cbBuf)) 1037 1030 { 1038 1031 gVBoxSt.fIsConsole = (*pProtocolType == 0); … … 1040 1033 return VINF_SUCCESS; 1041 1034 } 1042 else 1043 { 1044 DWORD dwErr = GetLastError(); 1045 WARN(("VBoxTray: WTSQuerySessionInformationA WTSClientProtocolType failed, error = %08X\n", dwErr)); 1046 rc = RTErrConvertFromWin32(dwErr); 1047 } 1035 1036 DWORD dwErr = GetLastError(); 1037 WARN(("VBoxTray: WTSQuerySessionInformationA WTSClientProtocolType failed, error = %08X\n", dwErr)); 1038 rc = RTErrConvertFromWin32(dwErr); 1048 1039 } 1049 1040 else … … 1063 1054 static int vboxStInit(HWND hWnd) 1064 1055 { 1065 int rc = VINF_SUCCESS; 1066 memset(&gVBoxSt, 0, sizeof (gVBoxSt)); 1067 gVBoxSt.hWTSAPI32 = LoadLibrary("WTSAPI32.DLL"); 1068 if (gVBoxSt.hWTSAPI32) 1069 { 1070 *(uintptr_t *)&gVBoxSt.pfnWTSRegisterSessionNotification = (uintptr_t)GetProcAddress(gVBoxSt.hWTSAPI32, "WTSRegisterSessionNotification"); 1071 if (!gVBoxSt.pfnWTSRegisterSessionNotification) 1072 { 1056 RT_ZERO(gVBoxSt); 1057 int rc = RTLdrLoadSystem("WTSAPI32.DLL", false /*fNoUnload*/, &gVBoxSt.hLdrModWTSAPI32); 1058 if (RT_SUCCESS(rc)) 1059 { 1060 rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSRegisterSessionNotification", 1061 (void **)&gVBoxSt.pfnWTSRegisterSessionNotification); 1062 if (RT_SUCCESS(rc)) 1063 { 1064 rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSUnRegisterSessionNotification", 1065 (void **)&gVBoxSt.pfnWTSUnRegisterSessionNotification); 1066 if (RT_SUCCESS(rc)) 1067 { 1068 rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSQuerySessionInformationA", 1069 (void **)&gVBoxSt.pfnWTSQuerySessionInformationA); 1070 if (RT_FAILURE(rc)) 1071 WARN(("VBoxTray: WTSQuerySessionInformationA not found\n")); 1072 } 1073 else 1074 WARN(("VBoxTray: WTSUnRegisterSessionNotification not found\n")); 1075 } 1076 else 1073 1077 WARN(("VBoxTray: WTSRegisterSessionNotification not found\n")); 1074 rc = VERR_NOT_SUPPORTED; 1075 } 1076 1077 *(uintptr_t *)&gVBoxSt.pfnWTSUnRegisterSessionNotification = (uintptr_t)GetProcAddress(gVBoxSt.hWTSAPI32, "WTSUnRegisterSessionNotification"); 1078 if (!gVBoxSt.pfnWTSUnRegisterSessionNotification) 1079 { 1080 WARN(("VBoxTray: WTSUnRegisterSessionNotification not found\n")); 1081 rc = VERR_NOT_SUPPORTED; 1082 } 1083 1084 *(uintptr_t *)&gVBoxSt.pfnWTSQuerySessionInformationA = (uintptr_t)GetProcAddress(gVBoxSt.hWTSAPI32, "WTSQuerySessionInformationA"); 1085 if (!gVBoxSt.pfnWTSQuerySessionInformationA) 1086 { 1087 WARN(("VBoxTray: WTSQuerySessionInformationA not found\n")); 1088 rc = VERR_NOT_SUPPORTED; 1089 } 1090 1091 if (rc == VINF_SUCCESS) 1078 if (RT_SUCCESS(rc)) 1092 1079 { 1093 1080 gVBoxSt.hWTSAPIWnd = hWnd; 1094 1081 if (gVBoxSt.pfnWTSRegisterSessionNotification(gVBoxSt.hWTSAPIWnd, NOTIFY_FOR_THIS_SESSION)) 1095 {1096 1082 vboxStCheckState(); 1097 }1098 1083 else 1099 1084 { … … 1102 1087 if (dwErr == RPC_S_INVALID_BINDING) 1103 1088 { 1104 gVBoxSt.idDelayedInitTimer = SetTimer(gVBoxSt.hWTSAPIWnd, TIMERID_VBOXTRAY_ST_DELAYED_INIT_TIMER, 2000, (TIMERPROC)NULL); 1105 rc = VINF_SUCCESS; 1106 1089 gVBoxSt.idDelayedInitTimer = SetTimer(gVBoxSt.hWTSAPIWnd, TIMERID_VBOXTRAY_ST_DELAYED_INIT_TIMER, 1090 2000, (TIMERPROC)NULL); 1107 1091 gVBoxSt.fIsConsole = TRUE; 1108 1092 gVBoxSt.enmConnectState = WTSActive; 1093 rc = VINF_SUCCESS; 1109 1094 } 1110 1095 else … … 1116 1101 } 1117 1102 1118 FreeLibrary(gVBoxSt.hWTSAPI32);1103 RTLdrClose(gVBoxSt.hLdrModWTSAPI32); 1119 1104 } 1120 1105 else 1121 { 1122 DWORD dwErr = GetLastError(); 1123 WARN(("VBoxTray: WTSAPI32 load failed, error = %08X\n", dwErr)); 1124 rc = RTErrConvertFromWin32(dwErr); 1125 } 1126 1127 memset(&gVBoxSt, 0, sizeof (gVBoxSt)); 1106 WARN(("VBoxTray: WTSAPI32 load failed, rc = %Rrc\n", rc)); 1107 1108 RT_ZERO(gVBoxSt); 1128 1109 gVBoxSt.fIsConsole = TRUE; 1129 1110 gVBoxSt.enmConnectState = WTSActive; … … 1131 1112 } 1132 1113 1133 static void vboxStTerm( )1134 { 1135 if ( gVBoxSt.hWTSAPIWnd)1114 static void vboxStTerm(void) 1115 { 1116 if (!gVBoxSt.hWTSAPIWnd) 1136 1117 { 1137 1118 WARN(("VBoxTray: vboxStTerm called for non-initialized St\n")); … … 1154 1135 } 1155 1136 1156 FreeLibrary(gVBoxSt.hWTSAPI32);1157 memset(&gVBoxSt, 0, sizeof (gVBoxSt));1137 RTLdrClose(gVBoxSt.hLdrModWTSAPI32); 1138 RT_ZERO(gVBoxSt); 1158 1139 } 1159 1140 … … 1228 1209 BOOL fIsInputDesktop; 1229 1210 UINT_PTR idTimer; 1230 HMODULE hHookModule;1211 RTLDRMOD hLdrModHook; 1231 1212 BOOL (* pfnVBoxHookInstallActiveDesktopTracker)(HMODULE hDll); 1232 1213 BOOL (* pfnVBoxHookRemoveActiveDesktopTracker)(); 1233 HMODULE hUSER32;1234 1214 HDESK (WINAPI * pfnGetThreadDesktop)(DWORD dwThreadId); 1235 1215 HDESK (WINAPI * pfnOpenInputDesktop)(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess); … … 1289 1269 } 1290 1270 1291 memset(&gVBoxDt, 0, sizeof (gVBoxDt));1271 RT_ZERO(gVBoxDt); 1292 1272 1293 1273 gVBoxDt.hNotifyEvent = CreateEvent(NULL, FALSE, FALSE, VBOXHOOK_GLOBAL_DT_EVENT_NAME); 1294 1274 if (gVBoxDt.hNotifyEvent != NULL) 1295 1275 { 1296 gVBoxDt.hHookModule = LoadLibrary(VBOXHOOK_DLL_NAME); 1297 if (gVBoxDt.hHookModule) 1298 { 1299 *(uintptr_t *)&gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker = (uintptr_t)GetProcAddress(gVBoxDt.hHookModule, "VBoxHookInstallActiveDesktopTracker"); 1300 if (!gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker) 1301 { 1276 /* Load the hook dll and resolve the necessary entry points. */ 1277 rc = RTLdrLoadAppPriv(VBOXHOOK_DLL_NAME, &gVBoxDt.hLdrModHook); 1278 if (RT_SUCCESS(rc)) 1279 { 1280 rc = RTLdrGetSymbol(gVBoxDt.hLdrModHook, "VBoxHookInstallActiveDesktopTracker", 1281 (void **)&gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker); 1282 if (RT_SUCCESS(rc)) 1283 { 1284 rc = RTLdrGetSymbol(gVBoxDt.hLdrModHook, "VBoxHookRemoveActiveDesktopTracker", 1285 (void **)&gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker); 1286 if (RT_FAILURE(rc)) 1287 WARN(("VBoxTray: VBoxHookRemoveActiveDesktopTracker not found\n")); 1288 } 1289 else 1302 1290 WARN(("VBoxTray: VBoxHookInstallActiveDesktopTracker not found\n")); 1303 rc = VERR_NOT_SUPPORTED; 1304 } 1305 1306 *(uintptr_t *)&gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker = (uintptr_t)GetProcAddress(gVBoxDt.hHookModule, "VBoxHookInstallActiveDesktopTracker"); 1307 if (!gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker) 1308 { 1309 WARN(("VBoxTray: VBoxHookRemoveActiveDesktopTracker not found\n")); 1310 rc = VERR_NOT_SUPPORTED; 1311 } 1312 1313 if (VINF_SUCCESS == rc) 1314 { 1315 gVBoxDt.hUSER32 = LoadLibrary("User32.dll"); 1316 if (gVBoxDt.hUSER32) 1291 if (RT_SUCCESS(rc)) 1292 { 1293 /* Try get the system APIs we need. */ 1294 *(void **)&gVBoxDt.pfnGetThreadDesktop = RTLdrGetSystemSymbol("User32.dll", "GetThreadDesktop"); 1295 if (!gVBoxDt.pfnGetThreadDesktop) 1317 1296 { 1318 *(uintptr_t *)&gVBoxDt.pfnGetThreadDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "GetThreadDesktop"); 1319 if (!gVBoxDt.pfnGetThreadDesktop) 1297 WARN(("VBoxTray: GetThreadDesktop not found\n")); 1298 rc = VERR_NOT_SUPPORTED; 1299 } 1300 1301 *(void **)&gVBoxDt.pfnOpenInputDesktop = RTLdrGetSystemSymbol("User32.dll", "OpenInputDesktop"); 1302 if (!gVBoxDt.pfnOpenInputDesktop) 1303 { 1304 WARN(("VBoxTray: OpenInputDesktop not found\n")); 1305 rc = VERR_NOT_SUPPORTED; 1306 } 1307 1308 *(void **)&gVBoxDt.pfnCloseDesktop = RTLdrGetSystemSymbol("User32.dll", "CloseDesktop"); 1309 if (!gVBoxDt.pfnCloseDesktop) 1310 { 1311 WARN(("VBoxTray: CloseDesktop not found\n")); 1312 rc = VERR_NOT_SUPPORTED; 1313 } 1314 1315 if (RT_SUCCESS(rc)) 1316 { 1317 BOOL fRc = FALSE; 1318 /* For Vista and up we need to change the integrity of the security descriptor, too. */ 1319 if (gMajorVersion >= 6) 1320 1320 { 1321 WARN(("VBoxTray: GetThreadDesktop not found\n")); 1322 rc = VERR_NOT_SUPPORTED; 1323 } 1324 1325 *(uintptr_t *)&gVBoxDt.pfnOpenInputDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "OpenInputDesktop"); 1326 if (!gVBoxDt.pfnOpenInputDesktop) 1327 { 1328 WARN(("VBoxTray: OpenInputDesktop not found\n")); 1329 rc = VERR_NOT_SUPPORTED; 1330 } 1331 1332 *(uintptr_t *)&gVBoxDt.pfnCloseDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "CloseDesktop"); 1333 if (!gVBoxDt.pfnCloseDesktop) 1334 { 1335 WARN(("VBoxTray: CloseDesktop not found\n")); 1336 rc = VERR_NOT_SUPPORTED; 1337 } 1338 1339 if (VINF_SUCCESS == rc) 1340 { 1341 BOOL bRc = FALSE; 1342 /* For Vista and up we need to change the integrity of the security descriptor, too. */ 1343 if (gMajorVersion >= 6) 1321 HMODULE hModHook = (HMODULE)RTLdrGetNativeHandle(gVBoxDt.hLdrModHook); 1322 Assert((uintptr_t)hModHook != ~(uintptr_t)0); 1323 fRc = gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker(hModHook); 1324 if (!fRc) 1344 1325 { 1345 bRc = gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker(gVBoxDt.hHookModule); 1346 if (!bRc) 1347 { 1348 DWORD dwErr = GetLastError(); 1349 WARN(("VBoxTray: pfnVBoxHookInstallActiveDesktopTracker failed, last error = %08X\n", dwErr)); 1350 } 1351 } 1352 1353 if (!bRc) 1354 { 1355 gVBoxDt.idTimer = SetTimer(ghwndToolWindow, TIMERID_VBOXTRAY_DT_TIMER, 500, (TIMERPROC)NULL); 1356 if (!gVBoxDt.idTimer) 1357 { 1358 DWORD dwErr = GetLastError(); 1359 WARN(("VBoxTray: SetTimer error %08X\n", dwErr)); 1360 rc = RTErrConvertFromWin32(dwErr); 1361 } 1362 } 1363 1364 if (RT_SUCCESS(rc)) 1365 { 1366 gVBoxDt.fIsInputDesktop = vboxDtCalculateIsInputDesktop(); 1367 return VINF_SUCCESS; 1326 DWORD dwErr = GetLastError(); 1327 WARN(("VBoxTray: pfnVBoxHookInstallActiveDesktopTracker failed, last error = %08X\n", dwErr)); 1368 1328 } 1369 1329 } 1370 FreeLibrary(gVBoxDt.hUSER32); 1330 1331 if (!fRc) 1332 { 1333 gVBoxDt.idTimer = SetTimer(ghwndToolWindow, TIMERID_VBOXTRAY_DT_TIMER, 500, (TIMERPROC)NULL); 1334 if (!gVBoxDt.idTimer) 1335 { 1336 DWORD dwErr = GetLastError(); 1337 WARN(("VBoxTray: SetTimer error %08X\n", dwErr)); 1338 rc = RTErrConvertFromWin32(dwErr); 1339 } 1340 } 1341 1342 if (RT_SUCCESS(rc)) 1343 { 1344 gVBoxDt.fIsInputDesktop = vboxDtCalculateIsInputDesktop(); 1345 return VINF_SUCCESS; 1346 } 1371 1347 } 1372 1348 } 1373 1349 1374 FreeLibrary(gVBoxDt.hHookModule);1350 RTLdrClose(gVBoxDt.hLdrModHook); 1375 1351 } 1376 1352 else … … 1391 1367 1392 1368 1393 memset(&gVBoxDt, 0, sizeof (gVBoxDt));1369 RT_ZERO(gVBoxDt); 1394 1370 gVBoxDt.fIsInputDesktop = TRUE; 1395 1371 … … 1399 1375 static void vboxDtTerm() 1400 1376 { 1401 if (!gVBoxDt.h HookModule)1377 if (!gVBoxDt.hLdrModHook) 1402 1378 return; 1403 1379 1404 1380 gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker(); 1405 1381 1406 FreeLibrary(gVBoxDt.hUSER32); 1407 FreeLibrary(gVBoxDt.hHookModule); 1382 RTLdrClose(gVBoxDt.hLdrModHook); 1408 1383 CloseHandle(gVBoxDt.hNotifyEvent); 1409 1384 1410 memset(&gVBoxDt, 0, sizeof (gVBoxDt));1385 RT_ZERO(gVBoxDt); 1411 1386 } 1412 1387 /* @returns true on "IsInputDesktop" state change */ -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp
r33966 r46593 25 25 #include <VBoxGuestInternal.h> 26 26 #include <iprt/assert.h> 27 #include <iprt/ldr.h> 27 28 28 29 … … 256 257 BOOL fSavedThemeEnabled; 257 258 258 HMODULE hModule;259 RTLDRMOD hModUxTheme; 259 260 260 261 HRESULT (* pfnEnableTheming)(BOOL fEnable); … … 274 275 gCtx.fSavedThemeEnabled = FALSE; 275 276 276 gCtx.hModule = LoadLibrary("UxTheme"); 277 278 if (gCtx.hModule) 279 { 280 *(uintptr_t *)&gCtx.pfnEnableTheming = (uintptr_t)GetProcAddress(gCtx.hModule, "EnableTheming"); 281 *(uintptr_t *)&gCtx.pfnIsThemeActive = (uintptr_t)GetProcAddress(gCtx.hModule, "IsThemeActive"); 277 int rc = RTLdrLoadSystem("UxTheme.dll", false /*fNoUnload*/, &gCtx.hModUxTheme); 278 if (RT_SUCCESS(rc)) 279 { 280 *(PFNRT *)&gCtx.pfnEnableTheming = RTLdrGetFunction(gCtx.hModUxTheme, "EnableTheming"); 281 *(PFNRT *)&gCtx.pfnIsThemeActive = RTLdrGetFunction(gCtx.hModUxTheme, "IsThemeActive"); 282 282 } 283 283 else 284 284 { 285 gCtx.pfnEnableTheming = 0; 285 gCtx.hModUxTheme = NIL_RTLDRMOD; 286 gCtx.pfnEnableTheming = NULL; 287 gCtx.pfnIsThemeActive = NULL; 286 288 } 287 289 … … 297 299 VBOXVRDPCONTEXT *pCtx = (VBOXVRDPCONTEXT *)pInstance; 298 300 vboxExperienceRestore (pCtx->level); 299 if (gCtx.hModule) 300 FreeLibrary(gCtx.hModule); 301 gCtx.hModule = 0; 301 if (gCtx.hModUxTheme != NIL_RTLDRMOD) 302 { 303 RTLdrClose(gCtx.hModUxTheme); 304 gCtx.hModUxTheme = NIL_RTLDRMOD; 305 } 302 306 return; 303 307 }
Note:
See TracChangeset
for help on using the changeset viewer.