Changeset 47960 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Aug 21, 2013 10:32:05 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxIPC.cpp
r47296 r47960 27 27 #include <iprt/critsect.h> 28 28 #include <iprt/err.h> 29 #include <iprt/ldr.h> 29 30 #include <iprt/list.h> 30 31 #include <iprt/localipc.h> … … 68 69 /** The thread handle. */ 69 70 RTTHREAD hThread; 71 /** Pointer to GetLastInputInfo() function. */ 72 BOOL (WINAPI * pfnGetLastInputInfo)(PLASTINPUTINFO); 70 73 71 74 } VBOXIPCSESSION, *PVBOXIPCSESSION; … … 73 76 int vboxIPCSessionDestroyLocked(PVBOXIPCSESSION pSession); 74 77 75 static int vboxIPCHandleVBoxTrayRestart(RTLOCALIPCSESSION hSession, PVBOXTRAYIPCHEADER pHdr) 76 { 78 static int vboxIPCHandleVBoxTrayRestart(PVBOXIPCSESSION pSession, PVBOXTRAYIPCHEADER pHdr) 79 { 80 AssertPtrReturn(pSession, VERR_INVALID_POINTER); 77 81 AssertPtrReturn(pHdr, VERR_INVALID_POINTER); 78 82 … … 81 85 } 82 86 83 static int vboxIPCHandleShowBalloonMsg(RTLOCALIPCSESSION hSession, PVBOXTRAYIPCHEADER pHdr) 84 { 87 static int vboxIPCHandleShowBalloonMsg(PVBOXIPCSESSION pSession, PVBOXTRAYIPCHEADER pHdr) 88 { 89 AssertPtrReturn(pSession, VERR_INVALID_POINTER); 85 90 AssertPtrReturn(pHdr, VERR_INVALID_POINTER); 86 91 AssertReturn(pHdr->uMsgLen > 0, VERR_INVALID_PARAMETER); 87 92 88 93 VBOXTRAYIPCMSG_SHOWBALLOONMSG ipcMsg; 89 int rc = RTLocalIpcSessionRead( hSession, &ipcMsg, pHdr->uMsgLen,94 int rc = RTLocalIpcSessionRead(pSession->hSession, &ipcMsg, pHdr->uMsgLen, 90 95 NULL /* Exact read, blocking */); 91 96 if (RT_SUCCESS(rc)) … … 103 108 } 104 109 105 static int vboxIPCHandleUserLastInput(RTLOCALIPCSESSION hSession, PVBOXTRAYIPCHEADER pHdr) 106 { 110 static int vboxIPCHandleUserLastInput(PVBOXIPCSESSION pSession, PVBOXTRAYIPCHEADER pHdr) 111 { 112 AssertPtrReturn(pSession, VERR_INVALID_POINTER); 107 113 AssertPtrReturn(pHdr, VERR_INVALID_POINTER); 108 114 /* No actual message from client. */ … … 110 116 int rc = VINF_SUCCESS; 111 117 112 /* Note: This only works up to 49.7 days (= 2^32, 32-bit counter) 113 since Windows was started. */ 114 LASTINPUTINFO lastInput; 115 lastInput.cbSize = sizeof(LASTINPUTINFO); 116 BOOL fRc = GetLastInputInfo(&lastInput); 117 if (fRc) 118 { 119 VBOXTRAYIPCRES_USERLASTINPUT ipcRes; 120 ipcRes.uLastInputMs = GetTickCount() - lastInput.dwTime; 121 rc = RTLocalIpcSessionWrite(hSession, &ipcRes, sizeof(ipcRes)); 122 } 123 else 124 rc = RTErrConvertFromWin32(GetLastError()); 118 bool fLastInputAvailable = false; 119 VBOXTRAYIPCRES_USERLASTINPUT ipcRes; 120 if (pSession->pfnGetLastInputInfo) 121 { 122 /* Note: This only works up to 49.7 days (= 2^32, 32-bit counter) 123 since Windows was started. */ 124 LASTINPUTINFO lastInput; 125 lastInput.cbSize = sizeof(LASTINPUTINFO); 126 BOOL fRc = pSession->pfnGetLastInputInfo(&lastInput); 127 if (fRc) 128 { 129 VBOXTRAYIPCRES_USERLASTINPUT ipcRes; 130 ipcRes.uLastInputMs = GetTickCount() - lastInput.dwTime; 131 fLastInputAvailable = true; 132 } 133 else 134 rc = RTErrConvertFromWin32(GetLastError()); 135 } 136 137 if (!fLastInputAvailable) 138 { 139 /* No last input available. */ 140 ipcRes.uLastInputMs = UINT32_MAX; 141 } 142 143 int rc2 = RTLocalIpcSessionWrite(pSession->hSession, &ipcRes, sizeof(ipcRes)); 144 if (RT_SUCCESS(rc)) 145 rc = rc2; 125 146 126 147 return rc; … … 306 327 { 307 328 case VBOXTRAYIPCMSGTYPE_RESTART: 308 rc = vboxIPCHandleVBoxTrayRestart( hSession, &ipcHdr);329 rc = vboxIPCHandleVBoxTrayRestart(pThis, &ipcHdr); 309 330 break; 310 331 311 332 case VBOXTRAYIPCMSGTYPE_SHOWBALLOONMSG: 312 rc = vboxIPCHandleShowBalloonMsg( hSession, &ipcHdr);333 rc = vboxIPCHandleShowBalloonMsg(pThis, &ipcHdr); 313 334 break; 314 335 315 336 case VBOXTRAYIPCMSGTYPE_USERLASTINPUT: 316 rc = vboxIPCHandleUserLastInput( hSession, &ipcHdr);337 rc = vboxIPCHandleUserLastInput(pThis, &ipcHdr); 317 338 break; 318 339 … … 417 438 rc = VERR_NO_MEMORY; 418 439 440 if (RT_SUCCESS(rc)) 441 { 442 *(void **)&pSession->pfnGetLastInputInfo = 443 RTLdrGetSystemSymbol("User32.dll", "GetLastInputInfo"); 444 /* GetLastInputInfo only is available starting at Windows 2000. */ 445 } 446 419 447 int rc2 = RTCritSectLeave(&pCtx->CritSect); 420 448 AssertRC(rc2); … … 427 455 { 428 456 AssertPtrReturn(pSession, VERR_INVALID_POINTER); 457 429 458 pSession->hThread = NIL_RTTHREAD; 459 pSession->pfnGetLastInputInfo = NULL; 430 460 431 461 RTLOCALIPCSESSION hSession;
Note:
See TracChangeset
for help on using the changeset viewer.