Changeset 63094 in vbox for trunk/src/VBox
- Timestamp:
- Aug 6, 2016 3:19:54 PM (8 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/VBoxHook
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxHook/VBoxHook.cpp
r62679 r63094 16 16 */ 17 17 18 19 /********************************************************************************************************************************* 20 * Header Files * 21 *********************************************************************************************************************************/ 18 22 #include <iprt/win/windows.h> 19 23 #include <VBoxHook.h> … … 21 25 #include <stdio.h> 22 26 27 28 /********************************************************************************************************************************* 29 * Global Variables * 30 *********************************************************************************************************************************/ 23 31 #pragma data_seg("SHARED") 24 static HWINEVENTHOOK hWinEventHook[2] = {0};25 static HWINEVENTHOOK hDesktopEventHook = NULL;32 static HWINEVENTHOOK g_ahWinEventHook[2] = { NULL, NULL }; 33 static HWINEVENTHOOK g_hDesktopEventHook = NULL; 26 34 #pragma data_seg() 27 35 #pragma comment(linker, "/section:SHARED,RWS") 28 36 29 static HANDLE hWinNotifyEvent = 0; 30 static HANDLE hDesktopNotifyEvent = 0; 31 37 static HANDLE g_hWinNotifyEvent = NULL; 38 static HANDLE g_hDesktopNotifyEvent = NULL; 39 40 41 /********************************************************************************************************************************* 42 * Internal Functions * 43 *********************************************************************************************************************************/ 32 44 #ifdef DEBUG 33 45 static void WriteLog(const char *pszFormat, ...); … … 81 93 } 82 94 #endif 83 if (! hWinNotifyEvent)95 if (!g_hWinNotifyEvent) 84 96 { 85 hWinNotifyEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, VBOXHOOK_GLOBAL_WT_EVENT_NAME);86 dprintf(("OpenEvent returned %x (last err=%x)\n", hWinNotifyEvent, GetLastError()));97 g_hWinNotifyEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, VBOXHOOK_GLOBAL_WT_EVENT_NAME); 98 dprintf(("OpenEvent returned %x (last err=%x)\n", g_hWinNotifyEvent, GetLastError())); 87 99 } 88 BOOL ret = SetEvent( hWinNotifyEvent);89 dprintf(("SetEvent %x returned %d (last error %x)\n", hWinNotifyEvent, ret, GetLastError()));100 BOOL ret = SetEvent(g_hWinNotifyEvent); 101 dprintf(("SetEvent %x returned %d (last error %x)\n", g_hWinNotifyEvent, ret, GetLastError())); 90 102 break; 91 103 } … … 96 108 DWORD dwEventThread, DWORD dwmsEventTime) 97 109 { 98 if (! hDesktopNotifyEvent)99 { 100 hDesktopNotifyEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, VBOXHOOK_GLOBAL_DT_EVENT_NAME);101 dprintf(("OpenEvent returned %x (last err=%x)\n", hDesktopNotifyEvent, GetLastError()));102 } 103 BOOL ret = SetEvent( hDesktopNotifyEvent);104 dprintf(("SetEvent %x returned %d (last error %x)\n", hDesktopNotifyEvent, ret, GetLastError()));110 if (!g_hDesktopNotifyEvent) 111 { 112 g_hDesktopNotifyEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, VBOXHOOK_GLOBAL_DT_EVENT_NAME); 113 dprintf(("OpenEvent returned %x (last err=%x)\n", g_hDesktopNotifyEvent, GetLastError())); 114 } 115 BOOL ret = SetEvent(g_hDesktopNotifyEvent); 116 dprintf(("SetEvent %x returned %d (last error %x)\n", g_hDesktopNotifyEvent, ret, GetLastError())); 105 117 } 106 118 107 119 BOOL VBoxHookInstallActiveDesktopTracker(HMODULE hDll) 108 120 { 109 if ( hDesktopEventHook)121 if (g_hDesktopEventHook) 110 122 return TRUE; 111 123 112 124 CoInitialize(NULL); 113 hDesktopEventHook = SetWinEventHook(EVENT_SYSTEM_DESKTOPSWITCH, EVENT_SYSTEM_DESKTOPSWITCH,114 hDll,115 VBoxHandleDesktopEvent,116 0, 0,117 0);118 119 return !! hDesktopEventHook;125 g_hDesktopEventHook = SetWinEventHook(EVENT_SYSTEM_DESKTOPSWITCH, EVENT_SYSTEM_DESKTOPSWITCH, 126 hDll, 127 VBoxHandleDesktopEvent, 128 0, 0, 129 0); 130 131 return !!g_hDesktopEventHook; 120 132 121 133 } … … 123 135 BOOL VBoxHookRemoveActiveDesktopTracker() 124 136 { 125 if ( hDesktopEventHook)126 { 127 UnhookWinEvent( hDesktopEventHook);137 if (g_hDesktopEventHook) 138 { 139 UnhookWinEvent(g_hDesktopEventHook); 128 140 CoUninitialize(); 129 141 } 130 hDesktopEventHook = 0;142 g_hDesktopEventHook = 0; 131 143 return TRUE; 132 144 } … … 135 147 BOOL VBoxHookInstallWindowTracker(HMODULE hDll) 136 148 { 137 if ( hWinEventHook[0] ||hWinEventHook[1])149 if (g_ahWinEventHook[0] || g_ahWinEventHook[1]) 138 150 return TRUE; 139 151 140 152 CoInitialize(NULL); 141 hWinEventHook[0] = SetWinEventHook(EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE,142 hDll,143 VBoxHandleWinEvent,144 0, 0,145 WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS);146 147 hWinEventHook[1] = SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_HIDE,148 hDll,149 VBoxHandleWinEvent,150 0, 0,151 WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS);152 return !! hWinEventHook[0];153 g_ahWinEventHook[0] = SetWinEventHook(EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE, 154 hDll, 155 VBoxHandleWinEvent, 156 0, 0, 157 WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS); 158 159 g_ahWinEventHook[1] = SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_HIDE, 160 hDll, 161 VBoxHandleWinEvent, 162 0, 0, 163 WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS); 164 return !!g_ahWinEventHook[0]; 153 165 } 154 166 … … 156 168 BOOL VBoxHookRemoveWindowTracker() 157 169 { 158 if ( hWinEventHook[0] &&hWinEventHook[1])159 { 160 UnhookWinEvent( hWinEventHook[0]);161 UnhookWinEvent( hWinEventHook[1]);170 if (g_ahWinEventHook[0] && g_ahWinEventHook[1]) 171 { 172 UnhookWinEvent(g_ahWinEventHook[0]); 173 UnhookWinEvent(g_ahWinEventHook[1]); 162 174 CoUninitialize(); 163 175 } 164 hWinEventHook[0] =hWinEventHook[1] = 0;176 g_ahWinEventHook[0] = g_ahWinEventHook[1] = 0; 165 177 return TRUE; 166 178 } -
trunk/src/VBox/Additions/WINNT/VBoxHook/dllmain.cpp
r62679 r63094 26 26 * @param hDLLInst Dll instance handle 27 27 * @param fdwReason Callback reason 28 * @param lpvReservedReserved28 * @param pvReserved Reserved 29 29 */ 30 BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)30 BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID pvReserved) 31 31 { 32 RT_NOREF(hDLLInst, pvReserved) 32 33 switch (fdwReason) 33 34 { -
trunk/src/VBox/Additions/WINNT/VBoxHook/testcase/tstHook.cpp
r62679 r63094 1 /* $Id$ */ 2 /** @file 3 * VBoxHook testcase. 4 */ 5 1 6 /* 2 7 * Copyright (C) 2006-2016 Oracle Corporation … … 19 24 #include <stdio.h> 20 25 21 int main(int argc, char **argv) 26 27 int main() 22 28 { 23 29 printf("Enabling global hook\n"); … … 34 40 return 0; 35 41 } 42
Note:
See TracChangeset
for help on using the changeset viewer.