FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
TestWtsApiSessionNotification.c
1
2#include <winpr/crt.h>
3#include <winpr/error.h>
4#include <winpr/wtsapi.h>
5#include <winpr/environment.h>
6
7int TestWtsApiSessionNotification(int argc, char* argv[])
8{
9 HWND hWnd = NULL;
10 BOOL bSuccess = 0;
11 DWORD dwFlags = 0;
12
13 WINPR_UNUSED(argc);
14 WINPR_UNUSED(argv);
15
16#ifndef _WIN32
17 if (!GetEnvironmentVariableA("WTSAPI_LIBRARY", NULL, 0))
18 {
19 printf("%s: No RDS environment detected, skipping test\n", __func__);
20 return 0;
21 }
22#else
23 /* We create a message-only window and use the predefined class name "STATIC" for simplicity */
24 hWnd = CreateWindowA("STATIC", "TestWtsApiSessionNotification", 0, 0, 0, 0, 0, HWND_MESSAGE,
25 NULL, NULL, NULL);
26 if (!hWnd)
27 {
28 printf("%s: error creating message-only window: %" PRIu32 "\n", __func__, GetLastError());
29 return -1;
30 }
31#endif
32
33 dwFlags = NOTIFY_FOR_ALL_SESSIONS;
34
35 bSuccess = WTSRegisterSessionNotification(hWnd, dwFlags);
36
37 if (!bSuccess)
38 {
39 printf("%s: WTSRegisterSessionNotification failed: %" PRIu32 "\n", __func__,
40 GetLastError());
41 return -1;
42 }
43
44 bSuccess = WTSUnRegisterSessionNotification(hWnd);
45
46#ifdef _WIN32
47 if (hWnd)
48 {
49 DestroyWindow(hWnd);
50 hWnd = NULL;
51 }
52#endif
53
54 if (!bSuccess)
55 {
56 printf("%s: WTSUnRegisterSessionNotification failed: %" PRIu32 "\n", __func__,
57 GetLastError());
58 return -1;
59 }
60
61 return 0;
62}