VirtualBox

Changeset 4461 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 31, 2007 8:41:54 AM (17 years ago)
Author:
vboxsync
Message:

Rewrote seamless notification handling.

Location:
trunk/src/VBox/Additions/WINNT
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxHook/VBoxHook.cpp

    r4457 r4461  
    1919#pragma data_seg("SHARED")
    2020static HWINEVENTHOOK    hEventHook[2]    = {0};
    21 static HWND             hwndNotification = 0;
    2221#pragma data_seg()
    2322#pragma comment(linker, "/section:SHARED,RWS")
     23
     24static HANDLE   hNotifyEvent = 0;
    2425
    2526#ifdef DEBUG
     
    7475        }
    7576#endif
    76         BOOL ret = PostMessage(hwndNotification, WM_VBOX_SEAMLESS_UPDATE, 0, 0);
    77         dprintf(("PostMessage %x returned %d (last error %x)\n", hwndNotification, ret, GetLastError()));
     77        if (!hNotifyEvent)
     78        {
     79            hNotifyEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, VBOXHOOK_GLOBAL_EVENT_NAME);
     80            dprintf(("OpenEvent returned %x (last err=%x)\n", hNotifyEvent, GetLastError()));
     81        }
     82        BOOL ret = SetEvent(hNotifyEvent);
     83        dprintf(("SetEvent %x returned %d (last error %x)\n", hNotifyEvent, ret, GetLastError()));
    7884        break;
    7985    }
     
    8288
    8389/* Install the global message hook */
    84 BOOL VBoxInstallHook(HMODULE hDll, HWND hwndPostWindow)
     90BOOL VBoxInstallHook(HMODULE hDll)
    8591{
    8692    if (hEventHook[0] || hEventHook[1])
    8793        return TRUE;
    8894
    89     hwndNotification = hwndPostWindow;
    90 
    91     dprintf(("VBoxInstallHook hwnd=%x\n", hwndPostWindow));
    9295    CoInitialize(NULL);
    9396    hEventHook[0] = SetWinEventHook(EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE,
     
    115118    }
    116119    hEventHook[0]  = hEventHook[1] = 0;
    117     hwndNotification = 0;
    118120    return true;
    119121}
  • trunk/src/VBox/Additions/WINNT/VBoxHook/testcase/tstHook.cpp

    r4071 r4461  
    2121{
    2222    printf("Enabling global hook\n");
    23     VBoxInstallHook(GetModuleHandle("VBoxHook.dll"), 0);
     23
     24    HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, VBOXHOOK_GLOBAL_EVENT_NAME);
     25
     26    VBoxInstallHook(GetModuleHandle("VBoxHook.dll"));
    2427    getchar();
    2528
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxSeamless.cpp

    r4071 r4461  
    3232    HMODULE    hModule;
    3333
    34     BOOL    (* pfnVBoxInstallHook)(HMODULE hDll, HWND hwndPostWindow);
     34    BOOL    (* pfnVBoxInstallHook)(HMODULE hDll);
    3535    BOOL    (* pfnVBoxRemoveHook)();
    3636
     
    120120        VBoxSeamlessCheckWindows();
    121121
    122         gCtx.pfnVBoxInstallHook(gCtx.hModule, gToolWindow);
     122        gCtx.pfnVBoxInstallHook(gCtx.hModule);
    123123    }
    124124}
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxService.cpp

    r4453 r4461  
    3030HANDLE                gVBoxDriver;
    3131HANDLE                gStopSem;
     32HANDLE                ghSeamlessNotifyEvent = 0;
    3233SERVICE_STATUS        gVBoxServiceStatus;
    3334SERVICE_STATUS_HANDLE gVBoxServiceStatusHandle;
     
    291292            return;
    292293        }
     294        ghSeamlessNotifyEvent = CreateEvent(NULL, FALSE, FALSE, VBOXHOOK_GLOBAL_EVENT_NAME);
     295        if (ghSeamlessNotifyEvent == NULL)
     296        {
     297            dprintf(("VBoxService: CreateEvent failed: rc = %d\n", GetLastError()));
     298            return;
     299        }
    293300    }
    294301
     
    335342     * Wait for the stop semaphore to be posted or a window event to arrive
    336343     */
     344    HANDLE hWaitEvent[2] = {gStopSem, ghSeamlessNotifyEvent};
    337345    while(true)
    338346    {
    339         DWORD waitResult = MsgWaitForMultipleObjectsEx(1, &gStopSem, 250, QS_ALLINPUT, 0);
     347        DWORD waitResult = MsgWaitForMultipleObjectsEx(2, hWaitEvent, 500, QS_ALLINPUT, 0);
    340348        if (waitResult == WAIT_OBJECT_0)
    341349        {
     
    344352            break;
    345353        }
    346         /* timeout or a window message, handle it */
    347         MSG msg;
    348         while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    349         {
    350             dprintf(("VBoxService: msg %p\n", msg.message));
    351             if (msg.message == WM_QUIT)
    352             {
    353                 dprintf(("VBoxService: WM_QUIT!\n"));
    354                 SetEvent(gStopSem);
    355                 continue;
    356             }
    357             TranslateMessage(&msg);
    358             DispatchMessage(&msg);
    359         }
    360         /* we might have to repeat this operation because the shell might not be loaded yet */
    361         if (!fTrayIconCreated)
    362         {
    363             fTrayIconCreated = Shell_NotifyIcon(NIM_ADD, &ndata);
    364             dprintf(("VBoxService: fTrayIconCreated = %d, err %08X\n", fTrayIconCreated, GetLastError ()));
     354        else
     355        if (waitResult == WAIT_OBJECT_0+1)
     356        {
     357            /* seamless window notification */
     358            VBoxSeamlessCheckWindows();
     359        }
     360        else
     361        {
     362            /* timeout or a window message, handle it */
     363            MSG msg;
     364            while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
     365            {
     366                dprintf(("VBoxService: msg %p\n", msg.message));
     367                if (msg.message == WM_QUIT)
     368                {
     369                    dprintf(("VBoxService: WM_QUIT!\n"));
     370                    SetEvent(gStopSem);
     371                    continue;
     372                }
     373                TranslateMessage(&msg);
     374                DispatchMessage(&msg);
     375            }
     376            /* we might have to repeat this operation because the shell might not be loaded yet */
     377            if (!fTrayIconCreated)
     378            {
     379                fTrayIconCreated = Shell_NotifyIcon(NIM_ADD, &ndata);
     380                dprintf(("VBoxService: fTrayIconCreated = %d, err %08X\n", fTrayIconCreated, GetLastError ()));
     381            }
    365382        }
    366383    }
  • trunk/src/VBox/Additions/WINNT/include/VBoxGuestInternal.h

    r4301 r4461  
    1212
    1313/** Uncomment to enable VRDP status checks */
    14 //#define VBOX_WITH_VRDP_SESSION_HANDLING
     14#define VBOX_WITH_VRDP_SESSION_HANDLING
    1515
    1616/** IOCTL for VBoxGuest to enable a VRDP session */
  • trunk/src/VBox/Additions/WINNT/include/VBoxHook.h

    r4278 r4461  
    1818
    1919#define VBOXHOOK_DLL_NAME           "VBoxHook.dll"
     20#define VBOXHOOK_GLOBAL_EVENT_NAME  "Local\\VBoxHookNotifyEvent"
    2021
    2122/* Install the global message hook */
    22 BOOL VBoxInstallHook(HMODULE hDll, HWND hwndPostWindow);
     23BOOL VBoxInstallHook(HMODULE hDll);
    2324
    2425/* Remove the global message hook */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette