Changeset 95965 in vbox
- Timestamp:
- Aug 1, 2022 2:34:03 PM (2 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/VBoxTray
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk
r95960 r95965 41 41 VBoxDispIf.cpp \ 42 42 VBoxSeamless.cpp \ 43 VBoxSessionTracking.cpp \ 43 44 VBoxDisplay.cpp \ 44 45 VBoxVRDP.cpp \ -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp
r95959 r95965 24 24 25 25 #include "VBoxTray.h" 26 #include "VBoxTrayInternal.h" 26 27 #include "VBoxTrayMsg.h" 27 28 #include "VBoxHelpers.h" … … 54 55 #include <VBox/err.h> 55 56 56 /* Default desktop state tracking */ 57 #include <Wtsapi32.h> 58 59 /* 60 * St (session [state] tracking) functionality API 61 * 62 * !!!NOTE: this API is NOT thread-safe!!! 63 * it is supposed to be called & used from within the window message handler thread 64 * of the window passed to vboxStInit */ 65 static int vboxStInit(HWND hWnd); 66 static void vboxStTerm(void); 67 /* @returns true on "IsActiveConsole" state change */ 68 static BOOL vboxStHandleEvent(WPARAM EventID); 69 static BOOL vboxStIsActiveConsole(); 70 static BOOL vboxStCheckTimer(WPARAM wEvent); 57 58 71 59 72 60 /* … … 1390 1378 } 1391 1379 1392 /* St (session [state] tracking) functionality API impl */1393 1394 typedef struct VBOXST1395 {1396 HWND hWTSAPIWnd;1397 RTLDRMOD hLdrModWTSAPI32;1398 BOOL fIsConsole;1399 WTS_CONNECTSTATE_CLASS enmConnectState;1400 UINT_PTR idDelayedInitTimer;1401 BOOL (WINAPI * pfnWTSRegisterSessionNotification)(HWND hWnd, DWORD dwFlags);1402 BOOL (WINAPI * pfnWTSUnRegisterSessionNotification)(HWND hWnd);1403 BOOL (WINAPI * pfnWTSQuerySessionInformationA)(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPTSTR *ppBuffer, DWORD *pBytesReturned);1404 } VBOXST;1405 1406 static VBOXST gVBoxSt;1407 1408 static int vboxStCheckState()1409 {1410 int rc = VINF_SUCCESS;1411 WTS_CONNECTSTATE_CLASS *penmConnectState = NULL;1412 USHORT *pProtocolType = NULL;1413 DWORD cbBuf = 0;1414 if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSConnectState,1415 (LPTSTR *)&penmConnectState, &cbBuf))1416 {1417 if (gVBoxSt.pfnWTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientProtocolType,1418 (LPTSTR *)&pProtocolType, &cbBuf))1419 {1420 gVBoxSt.fIsConsole = (*pProtocolType == 0);1421 gVBoxSt.enmConnectState = *penmConnectState;1422 return VINF_SUCCESS;1423 }1424 1425 DWORD dwErr = GetLastError();1426 LogFlowFunc(("WTSQuerySessionInformationA WTSClientProtocolType failed, error = %08X\n", dwErr));1427 rc = RTErrConvertFromWin32(dwErr);1428 }1429 else1430 {1431 DWORD dwErr = GetLastError();1432 LogFlowFunc(("WTSQuerySessionInformationA WTSConnectState failed, error = %08X\n", dwErr));1433 rc = RTErrConvertFromWin32(dwErr);1434 }1435 1436 /* failure branch, set to "console-active" state */1437 gVBoxSt.fIsConsole = TRUE;1438 gVBoxSt.enmConnectState = WTSActive;1439 1440 return rc;1441 }1442 1443 static int vboxStInit(HWND hWnd)1444 {1445 RT_ZERO(gVBoxSt);1446 int rc = RTLdrLoadSystem("WTSAPI32.DLL", false /*fNoUnload*/, &gVBoxSt.hLdrModWTSAPI32);1447 if (RT_SUCCESS(rc))1448 {1449 rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSRegisterSessionNotification",1450 (void **)&gVBoxSt.pfnWTSRegisterSessionNotification);1451 if (RT_SUCCESS(rc))1452 {1453 rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSUnRegisterSessionNotification",1454 (void **)&gVBoxSt.pfnWTSUnRegisterSessionNotification);1455 if (RT_SUCCESS(rc))1456 {1457 rc = RTLdrGetSymbol(gVBoxSt.hLdrModWTSAPI32, "WTSQuerySessionInformationA",1458 (void **)&gVBoxSt.pfnWTSQuerySessionInformationA);1459 if (RT_FAILURE(rc))1460 LogFlowFunc(("WTSQuerySessionInformationA not found\n"));1461 }1462 else1463 LogFlowFunc(("WTSUnRegisterSessionNotification not found\n"));1464 }1465 else1466 LogFlowFunc(("WTSRegisterSessionNotification not found\n"));1467 if (RT_SUCCESS(rc))1468 {1469 gVBoxSt.hWTSAPIWnd = hWnd;1470 if (gVBoxSt.pfnWTSRegisterSessionNotification(gVBoxSt.hWTSAPIWnd, NOTIFY_FOR_THIS_SESSION))1471 vboxStCheckState();1472 else1473 {1474 DWORD dwErr = GetLastError();1475 LogFlowFunc(("WTSRegisterSessionNotification failed, error = %08X\n", dwErr));1476 if (dwErr == RPC_S_INVALID_BINDING)1477 {1478 gVBoxSt.idDelayedInitTimer = SetTimer(gVBoxSt.hWTSAPIWnd, TIMERID_VBOXTRAY_ST_DELAYED_INIT_TIMER,1479 2000, (TIMERPROC)NULL);1480 gVBoxSt.fIsConsole = TRUE;1481 gVBoxSt.enmConnectState = WTSActive;1482 rc = VINF_SUCCESS;1483 }1484 else1485 rc = RTErrConvertFromWin32(dwErr);1486 }1487 1488 if (RT_SUCCESS(rc))1489 return VINF_SUCCESS;1490 }1491 1492 RTLdrClose(gVBoxSt.hLdrModWTSAPI32);1493 }1494 else1495 LogFlowFunc(("WTSAPI32 load failed, rc = %Rrc\n", rc));1496 1497 RT_ZERO(gVBoxSt);1498 gVBoxSt.fIsConsole = TRUE;1499 gVBoxSt.enmConnectState = WTSActive;1500 return rc;1501 }1502 1503 static void vboxStTerm(void)1504 {1505 if (!gVBoxSt.hWTSAPIWnd)1506 {1507 LogFlowFunc(("vboxStTerm called for non-initialized St\n"));1508 return;1509 }1510 1511 if (gVBoxSt.idDelayedInitTimer)1512 {1513 /* notification is not registered, just kill timer */1514 KillTimer(gVBoxSt.hWTSAPIWnd, gVBoxSt.idDelayedInitTimer);1515 gVBoxSt.idDelayedInitTimer = 0;1516 }1517 else1518 {1519 if (!gVBoxSt.pfnWTSUnRegisterSessionNotification(gVBoxSt.hWTSAPIWnd))1520 {1521 LogFlowFunc(("WTSAPI32 load failed, error = %08X\n", GetLastError()));1522 }1523 }1524 1525 RTLdrClose(gVBoxSt.hLdrModWTSAPI32);1526 RT_ZERO(gVBoxSt);1527 }1528 1529 #define VBOXST_DBG_MAKECASE(_val) case _val: return #_val;1530 1531 static const char* vboxStDbgGetString(DWORD val)1532 {1533 switch (val)1534 {1535 VBOXST_DBG_MAKECASE(WTS_CONSOLE_CONNECT);1536 VBOXST_DBG_MAKECASE(WTS_CONSOLE_DISCONNECT);1537 VBOXST_DBG_MAKECASE(WTS_REMOTE_CONNECT);1538 VBOXST_DBG_MAKECASE(WTS_REMOTE_DISCONNECT);1539 VBOXST_DBG_MAKECASE(WTS_SESSION_LOGON);1540 VBOXST_DBG_MAKECASE(WTS_SESSION_LOGOFF);1541 VBOXST_DBG_MAKECASE(WTS_SESSION_LOCK);1542 VBOXST_DBG_MAKECASE(WTS_SESSION_UNLOCK);1543 VBOXST_DBG_MAKECASE(WTS_SESSION_REMOTE_CONTROL);1544 default:1545 LogFlowFunc(("invalid WTS state %d\n", val));1546 return "Unknown";1547 }1548 }1549 1550 static BOOL vboxStCheckTimer(WPARAM wEvent)1551 {1552 if (wEvent != gVBoxSt.idDelayedInitTimer)1553 return FALSE;1554 1555 if (gVBoxSt.pfnWTSRegisterSessionNotification(gVBoxSt.hWTSAPIWnd, NOTIFY_FOR_THIS_SESSION))1556 {1557 KillTimer(gVBoxSt.hWTSAPIWnd, gVBoxSt.idDelayedInitTimer);1558 gVBoxSt.idDelayedInitTimer = 0;1559 vboxStCheckState();1560 }1561 else1562 {1563 LogFlowFunc(("timer WTSRegisterSessionNotification failed, error = %08X\n", GetLastError()));1564 Assert(gVBoxSt.fIsConsole == TRUE);1565 Assert(gVBoxSt.enmConnectState == WTSActive);1566 }1567 1568 return TRUE;1569 }1570 1571 1572 static BOOL vboxStHandleEvent(WPARAM wEvent)1573 {1574 RT_NOREF(wEvent);1575 LogFlowFunc(("WTS Event: %s\n", vboxStDbgGetString(wEvent)));1576 BOOL fOldIsActiveConsole = vboxStIsActiveConsole();1577 1578 vboxStCheckState();1579 1580 return !vboxStIsActiveConsole() != !fOldIsActiveConsole;1581 }1582 1583 static BOOL vboxStIsActiveConsole(void)1584 {1585 return (gVBoxSt.enmConnectState == WTSActive && gVBoxSt.fIsConsole);1586 }1587 1588 1380 /* 1589 1381 * Dt (desktop [state] tracking) functionality API impl -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTrayInternal.h
r95963 r95965 21 21 # pragma once 22 22 #endif 23 /* 24 * St (session [state] tracking) functionality API 25 * 26 * !!!NOTE: this API is NOT thread-safe!!! 27 * it is supposed to be called & used from within the window message handler thread 28 * of the window passed to vboxStInit */ 29 int vboxStInit(HWND hWnd); 30 void vboxStTerm(void); 31 /* @returns true on "IsActiveConsole" state change */ 32 BOOL vboxStHandleEvent(WPARAM EventID); 33 BOOL vboxStIsActiveConsole(); 34 BOOL vboxStCheckTimer(WPARAM wEvent); 23 35 24 36 DWORD VBoxDisplayGetCount();
Note:
See TracChangeset
for help on using the changeset viewer.