-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
4755 lines (4361 loc) · 165 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2020-2021 Griefer@Work *
* *
* This software is provided 'as-is', without any express or implied *
* warranty. In no event will the authors be held liable for any damages *
* arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must not *
* claim that you wrote the original software. If you use this software *
* in a product, an acknowledgement (see the following) in the product *
* documentation is required: *
* Portions Copyright (c) 2020-2021 Griefer@Work *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* 3. This notice may not be removed or altered from any source distribution. *
*/
#ifndef GUARD_WINTOUCHG_MAIN_C
#define GUARD_WINTOUCHG_MAIN_C 1
#define WINVER 0x0602
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_SECURE_NO_WARNINGS 1
#define CINTERFACE 1
#include <Windows.h>
#include <Windowsx.h>
#include <dwmapi.h>
#include <endpointvolume.h>
#include <math.h>
#include <mmdeviceapi.h>
#include <psapi.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#if 0
#define CONFIG_WITHOUT_CP 1 /* CONFIG: Disable the control panel. */
#define CONFIG_WITHOUT_AS 1 /* CONFIG: Disable the application switches. */
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
;
#undef LONG_MIN
#undef LONG_MAX
#define LONG_MIN (-2147483647L - 1)
#define LONG_MAX 2147483647L
#define RC_WIDTH(rc) ((rc).right - (rc).left)
#define RC_HEIGHT(rc) ((rc).bottom - (rc).top)
#undef THIS_
#undef THIS
#define THIS_ INTERFACE *This,
#define THIS INTERFACE *This
#undef DECLARE_INTERFACE
#define DECLARE_INTERFACE(iface) \
typedef struct iface iface; \
typedef struct iface##Vtbl iface##Vtbl; \
struct iface { \
struct iface##Vtbl const *lpVtbl; \
}; \
struct iface##Vtbl
#undef STDMETHOD
#undef STDMETHOD_
#undef STDMETHODV
#undef STDMETHODV_
#define STDMETHOD(method) HRESULT (STDMETHODCALLTYPE * method)
#define STDMETHOD_(type,method) type (STDMETHODCALLTYPE * method)
#define STDMETHODV(method) HRESULT (STDMETHODVCALLTYPE * method)
#define STDMETHODV_(type,method) type (STDMETHODVCALLTYPE * method)
/************************************************************************/
/* Error handling and logging */
/************************************************************************/
#if 0
#define HAVE_DEBUG_PRINTF
#define debug_printf(...) printf(__VA_ARGS__)
#else
#define debug_printf(...) (void)0
#endif
#define err(code, ...) \
do { \
fprintf(stderr, "wintouchg: "); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
/* Sleep, because wintouchg is \
* always launched in a separate, \
* so if we crash, any error info \
* would only blink for a second */ \
for (;;) \
Sleep(1000); \
exit(code); \
} while (0)
#undef assert
#define assert(expr) \
do { \
if (!(expr)) \
err(1, "%s:%d: Assertion failed ('%s')", \
__FILE__, __LINE__, #expr); \
} while (0)
#define LOGERROR_PTR(function, ptr) \
Wtg_LogErrorPtr(__func__, __LINE__, function, (void *)(uintptr_t)(ptr))
static void Wtg_LogErrorPtr(char const *caller, int line,
char const *function, void *ptr) {
fprintf(stderr, "[error] In '%s:%d': Function '%s' returned error: %p\n",
caller, line, function, ptr);
}
#define LOGERROR_GLE(function) \
Wtg_LogErrorGetLastError(__func__, __LINE__, function)
static void Wtg_LogErrorGetLastError(char const *caller, int line,
char const *function) {
fprintf(stderr, "[error] In '%s:%d': Function '%s' returned error: %lu\n",
caller, line, function, (unsigned long)GetLastError());
}
#define LOGERROR(...) \
Wtg_LogError(__func__, __LINE__, __VA_ARGS__)
#define LOGERROR_CONTINUE(...) \
fprintf(stderr, __VA_ARGS__)
static void Wtg_LogError(char const *caller, int line,
char const *format, ...) {
va_list args;
va_start(args, format);
fprintf(stderr, "[error] In '%s:%d': ", caller, line);
vfprintf(stderr, format, args);
va_end(args);
}
static void Wtg_WarnMissingShLibFunction(HMODULE hModule, LPCSTR lpProcName) {
#ifndef MAX_PATH
#define MAX_PATH 260
#endif /* !MAX_PATH */
char modName[MAX_PATH];
DWORD dwError = GetLastError();
if (!GetModuleFileNameA(hModule, modName, sizeof(modName)))
strcpy(modName, "?");
fprintf(stderr, "[warn] Shlib '%s': function '%s' not found (%lu)\n",
lpProcName, modName, (unsigned long)dwError);
}
/************************************************************************/
/* Max # of touch points to support */
#ifndef WTG_MAX_TOUCH_INPUTS
#define WTG_MAX_TOUCH_INPUTS 256
#endif /* !WTG_MAX_TOUCH_INPUTS */
/* Pixel distance threshold for gestures. */
#ifndef WTG_GESTURE_SWIPE_THRESHOLD
#define WTG_GESTURE_SWIPE_THRESHOLD 50.0 /* Average distance traveled */
#endif /* !WTG_GESTURE_SWIPE_THRESHOLD */
#ifndef WTG_GESTURE_SWIPE_COMMIT_THRESHOLD
#define WTG_GESTURE_SWIPE_COMMIT_THRESHOLD 200.0 /* Min. distance for commit */
#endif /* !WTG_GESTURE_SWIPE_COMMIT_THRESHOLD */
#ifndef WTG_GESTURE_ZOOM_THRESHOLD
#define WTG_GESTURE_ZOOM_THRESHOLD 150.0 /* Average distance traveled */
#endif /* !WTG_GESTURE_ZOOM_THRESHOLD */
#ifndef WTG_GESTURE_ZOOM_COMMIT_THRESHOLD
#define WTG_GESTURE_ZOOM_COMMIT_THRESHOLD 200.0 /* Min. distance for commit */
#endif /* !WTG_GESTURE_ZOOM_COMMIT_THRESHOLD */
/* Multi-touch gesture recognition bounds. */
#ifndef WTG_GESTURE_STRT_TOUCH_COUNT
#define WTG_GESTURE_STRT_TOUCH_COUNT 4 /* Begin a multi-touch gesture if >= this # of touch inputs are present */
#endif /* !WTG_GESTURE_STRT_TOUCH_COUNT */
#ifndef WTG_GESTURE_STOP_TOUCH_COUNT
#define WTG_GESTURE_STOP_TOUCH_COUNT 1 /* Stop a multi-touch gesture if <= this # of touch inputs remain */
#endif /* !WTG_GESTURE_STOP_TOUCH_COUNT */
static HINSTANCE hApplicationInstance;
/************************************************************************/
/* Dynamic system library hooks */
/************************************************************************/
#define DEFINE_DYNAMIC_FUNCTION(return, cc, name, args) \
typedef return (cc * LP##name) args; \
static LP##name pdyn_##name = NULL
#ifndef CONFIG_WITHOUT_CP
/* PowrProf.dll API. */
DEFINE_DYNAMIC_FUNCTION(NTSTATUS, WINAPI, CallNtPowerInformation, (/*POWER_INFORMATION_LEVEL*/ int InformationLevel, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength));
#define CallNtPowerInformation (*pdyn_CallNtPowerInformation)
/* Ole32 API. */
#undef CO_MTA_USAGE_COOKIE
#define CO_MTA_USAGE_COOKIE real_CO_MTA_USAGE_COOKIE
DECLARE_HANDLE(CO_MTA_USAGE_COOKIE);
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, CoInitialize, (LPVOID pvReserved));
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, CoCreateInstance, (GUID const *rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, GUID const *riid, LPVOID *ppv));
DEFINE_DYNAMIC_FUNCTION(void, STDAPICALLTYPE, CoUninitialize, (void));
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, CoIncrementMTAUsage, (CO_MTA_USAGE_COOKIE * pCookie));
#define CoInitialize (*pdyn_CoInitialize)
#define CoCreateInstance (*pdyn_CoCreateInstance)
#define CoUninitialize (*pdyn_CoUninitialize)
#define CoIncrementMTAUsage (*pdyn_CoIncrementMTAUsage)
#endif /* !CONFIG_WITHOUT_CP */
/* User32 API. */
typedef struct {
DWORD dwAttr;
PVOID pData;
ULONG dataSize;
} WINCOMPATTRDATA;
DEFINE_DYNAMIC_FUNCTION(BOOL, WINAPI, RegisterPointerInputTarget, (HWND hwnd, POINTER_INPUT_TYPE pointerType));
DEFINE_DYNAMIC_FUNCTION(BOOL, WINAPI, RegisterTouchWindow, (HWND hwnd, ULONG ulFlags));
DEFINE_DYNAMIC_FUNCTION(BOOL, WINAPI, InjectTouchInput, (UINT32 count, POINTER_TOUCH_INFO const *contacts));
DEFINE_DYNAMIC_FUNCTION(BOOL, WINAPI, InitializeTouchInjection, (UINT32 maxCount, DWORD dwMode));
DEFINE_DYNAMIC_FUNCTION(BOOL, WINAPI, GetPointerTouchInfo, (UINT32 pointerId, POINTER_TOUCH_INFO *touchInfo));
DEFINE_DYNAMIC_FUNCTION(BOOL, WINAPI, SetWindowCompositionAttribute, (HWND hwnd, WINCOMPATTRDATA *pAttrData));
#undef AR_ENABLED
#define AR_ENABLED 0x0
DEFINE_DYNAMIC_FUNCTION(BOOL, WINAPI, GetAutoRotationState, (int *pState));
DEFINE_DYNAMIC_FUNCTION(BOOL, WINAPI, SetAutoRotationState, (BOOL bEnabled));
#define RegisterPointerInputTarget (*pdyn_RegisterPointerInputTarget)
#define RegisterTouchWindow (*pdyn_RegisterTouchWindow)
#define InjectTouchInput (*pdyn_InjectTouchInput)
#define InitializeTouchInjection (*pdyn_InitializeTouchInjection)
#define GetPointerTouchInfo (*pdyn_GetPointerTouchInfo)
#define SetWindowCompositionAttribute (*pdyn_SetWindowCompositionAttribute)
#define GetAutoRotationState (*pdyn_GetAutoRotationState)
#define SetAutoRotationState (*pdyn_SetAutoRotationState)
/* DWM API. */
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, DwmRegisterThumbnail, (HWND hwndDestination, HWND hwndSource, PHTHUMBNAIL phThumbnailId));
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, DwmUnregisterThumbnail, (HTHUMBNAIL hThumbnailId));
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, DwmUpdateThumbnailProperties, (HTHUMBNAIL hThumbnailId, DWM_THUMBNAIL_PROPERTIES const *ptnProperties));
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, DwmQueryThumbnailSourceSize, (HTHUMBNAIL hThumbnailId, PSIZE pSize));
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, DwmGetWindowAttribute, (HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute));
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, DwmEnableBlurBehindWindow, (HWND hWnd, DWM_BLURBEHIND const *pBlurBehind));
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, DwmExtendFrameIntoClientArea, (HWND hWnd, MARGINS const *pMarInset));
#define DwmRegisterThumbnail (*pdyn_DwmRegisterThumbnail)
#define DwmUnregisterThumbnail (*pdyn_DwmUnregisterThumbnail)
#define DwmUpdateThumbnailProperties (*pdyn_DwmUpdateThumbnailProperties)
#define DwmQueryThumbnailSourceSize (*pdyn_DwmQueryThumbnailSourceSize)
#define DwmGetWindowAttribute (*pdyn_DwmGetWindowAttribute)
#define DwmEnableBlurBehindWindow (*pdyn_DwmEnableBlurBehindWindow)
#define DwmExtendFrameIntoClientArea (*pdyn_DwmExtendFrameIntoClientArea)
#define DEFINE_LAZY_LIBRARY_LOADER(pdyn_LibraryAPI, GetLibraryHandle, LIBNAME, LibDllName) \
static HMODULE pdyn_LibraryAPI = NULL; \
static HMODULE GetLibraryHandle(void) { \
HMODULE hResult = pdyn_LibraryAPI; \
if (hResult) { \
if (hResult == (HMODULE)-1) \
hResult = NULL; \
} else { \
hResult = GetModuleHandleW(LIBNAME); \
if (!hResult) { \
hResult = LoadLibraryW(LibDllName); \
if (!hResult) \
hResult = (HMODULE)-1; \
} \
pdyn_LibraryAPI = hResult; \
} \
return hResult; \
}
#ifndef CONFIG_WITHOUT_CP
DEFINE_LAZY_LIBRARY_LOADER(pdyn_PowrProf, DynApi_GetPowrProfHandle, L"POWRPROF", L"PowrProf.dll");
DEFINE_LAZY_LIBRARY_LOADER(pdyn_Ole32, DynApi_GetOld32Handle, L"OLE32", L"Ole32.dll");
#endif /* !CONFIG_WITHOUT_CP */
DEFINE_LAZY_LIBRARY_LOADER(pdyn_User32, DynApi_GetUser32Handle, L"USER32", L"User32.dll");
DEFINE_LAZY_LIBRARY_LOADER(pdyn_DwmAPI, DynApi_GetDwmApiHandle, L"DWMAPI", L"dwmapi.dll");
#undef DEFINE_LAZY_LIBRARY_LOADER
static FARPROC DynApi_GetProcAddress(HMODULE hModule, LPCSTR lpProcName) {
FARPROC result = GetProcAddress(hModule, lpProcName);
if (!result)
Wtg_WarnMissingShLibFunction(hModule, lpProcName);
return result;
}
#define DynApi_TryLoadFunction(hLibrary, Name) \
(pdyn_##Name = (LP##Name)DynApi_GetProcAddress(hLibrary, #Name))
#define DynApi_LoadFunction(hLibrary, Name) \
do { \
pdyn_##Name = (LP##Name)DynApi_GetProcAddress(hLibrary, #Name); \
if (!pdyn_##Name) \
goto fail; \
} while (0)
/* Ensure that the given API is available (returning `true' if it is, and `false' otherwise) */
#ifndef CONFIG_WITHOUT_CP
static bool DynApi_InitializePowrProf(void) {
HMODULE hPowrProf = DynApi_GetPowrProfHandle();
if (!hPowrProf)
goto fail;
DynApi_LoadFunction(hPowrProf, CallNtPowerInformation);
return true;
fail:
return false;
}
static bool DynApi_InitializeOld32(void) {
HMODULE hOle32 = DynApi_GetOld32Handle();
if (!hOle32)
goto fail;
DynApi_LoadFunction(hOle32, CoInitialize);
DynApi_LoadFunction(hOle32, CoCreateInstance);
DynApi_LoadFunction(hOle32, CoUninitialize);
DynApi_TryLoadFunction(hOle32, CoIncrementMTAUsage);
return true;
fail:
return false;
}
#endif /* !CONFIG_WITHOUT_CP */
static bool DynApi_InitializeUser32(void) {
HMODULE hUser32 = DynApi_GetUser32Handle();
if (!hUser32)
goto fail;
DynApi_LoadFunction(hUser32, RegisterPointerInputTarget);
DynApi_LoadFunction(hUser32, RegisterTouchWindow);
DynApi_LoadFunction(hUser32, InjectTouchInput);
DynApi_LoadFunction(hUser32, InitializeTouchInjection);
DynApi_LoadFunction(hUser32, GetPointerTouchInfo);
DynApi_TryLoadFunction(hUser32, SetWindowCompositionAttribute);
DynApi_TryLoadFunction(hUser32, GetAutoRotationState);
/* https://social.msdn.microsoft.com/Forums/en-US/f9cd061b-ce33-4376-9114-f4f783a3bde3/how-do-i-turn-onoff-autorotation-by-code */
pdyn_SetAutoRotationState = (LPSetAutoRotationState)GetProcAddress(hUser32, (LPCSTR)2507);
if (!pdyn_SetAutoRotationState)
Wtg_WarnMissingShLibFunction(hUser32, "SetAutoRotationState#2507");
return true;
fail:
return false;
}
static bool DynApi_InitializeDwm(void) {
HMODULE hDwmApi = DynApi_GetDwmApiHandle();
if (!hDwmApi)
goto fail;
/* Load API hooks. */
DynApi_LoadFunction(hDwmApi, DwmRegisterThumbnail);
DynApi_LoadFunction(hDwmApi, DwmUnregisterThumbnail);
DynApi_LoadFunction(hDwmApi, DwmUpdateThumbnailProperties);
DynApi_LoadFunction(hDwmApi, DwmQueryThumbnailSourceSize);
/* Optional functions. */
DynApi_TryLoadFunction(hDwmApi, DwmGetWindowAttribute);
DynApi_TryLoadFunction(hDwmApi, DwmEnableBlurBehindWindow);
DynApi_TryLoadFunction(hDwmApi, DwmExtendFrameIntoClientArea);
return true;
fail:
return false;
}
/************************************************************************/
/************************************************************************/
/* System settings helper functions */
/************************************************************************/
#ifndef CONFIG_WITHOUT_CP
#define _DISPLAY_BRIGHTNESS _real__DISPLAY_BRIGHTNESS
#define DISPLAY_BRIGHTNESS _real_DISPLAY_BRIGHTNESS
#define PDISPLAY_BRIGHTNESS _real_PDISPLAY_BRIGHTNESS
typedef struct _DISPLAY_BRIGHTNESS {
UCHAR ucDisplayPolicy;
UCHAR ucACBrightness;
UCHAR ucDCBrightness;
} DISPLAY_BRIGHTNESS, *PDISPLAY_BRIGHTNESS;
/* XXX: Microsoft says that this API is deprecated, but the replacement
* uses yet another one of those really weird APIs, and somehow even
* seems related to powershell... */
#ifndef IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS
#define IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS \
CTL_CODE(FILE_DEVICE_VIDEO, 0x126, METHOD_BUFFERED, FILE_ANY_ACCESS)
#endif /* !IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS */
#ifndef IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS
#define IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS \
CTL_CODE(FILE_DEVICE_VIDEO, 0x127, METHOD_BUFFERED, FILE_ANY_ACCESS)
#endif /* !IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS */
#ifndef DISPLAYPOLICY_AC
#define DISPLAYPOLICY_AC 0x00000001
#endif /* !DISPLAYPOLICY_AC */
#ifndef DISPLAYPOLICY_DC
#define DISPLAYPOLICY_DC 0x00000002
#endif /* !DISPLAYPOLICY_DC */
#ifndef DISPLAYPOLICY_BOTH
#define DISPLAYPOLICY_BOTH 0x00000003
#endif /* !DISPLAYPOLICY_BOTH */
static HANDLE SysIntern_OpenLCD(void) {
HANDLE hResult;
hResult = CreateFileW(L"\\\\.\\LCD", GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);
if (hResult == NULL || hResult == INVALID_HANDLE_VALUE)
LOGERROR_GLE("CreateFileW(\"\\\\.\\LCD\")");
return hResult;
}
static BOOL SysIntern_GetDisplayBrightness(DISPLAY_BRIGHTNESS *__restrict pDb) {
BOOL bResult;
DWORD ret = 0;
HANDLE hLCD = SysIntern_OpenLCD();
if (hLCD == NULL || hLCD == INVALID_HANDLE_VALUE)
return FALSE;
memset(pDb, 0, sizeof(*pDb));
bResult = DeviceIoControl(hLCD, IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS,
NULL, 0, (LPVOID)pDb, sizeof(*pDb), &ret, NULL);
if (!bResult)
LOGERROR_GLE("DeviceIoControl()");
CloseHandle(hLCD);
return bResult;
}
static BOOL SysIntern_SetDisplayBrightness(DISPLAY_BRIGHTNESS const *__restrict pDb) {
BOOL bResult;
DWORD ret = 0;
HANDLE hLCD = SysIntern_OpenLCD();
if (hLCD == NULL || hLCD == INVALID_HANDLE_VALUE)
return FALSE;
bResult = DeviceIoControl(hLCD, IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS,
(LPVOID)pDb, sizeof(*pDb), NULL, 0, &ret, NULL);
if (!bResult)
LOGERROR_GLE("DeviceIoControl()");
CloseHandle(hLCD);
return bResult;
}
static LONG SysIntern_GetBrightnessPercent(void) {
DISPLAY_BRIGHTNESS db;
if (!SysIntern_GetDisplayBrightness(&db))
return -1;
if (db.ucDisplayPolicy & DISPLAYPOLICY_AC)
return db.ucACBrightness;
if (db.ucDisplayPolicy & DISPLAYPOLICY_DC)
return db.ucDCBrightness;
LOGERROR("Unsupported db.ucDisplayPolicy: %#lx\n", db.ucDisplayPolicy);
return -1;
}
static bool SysIntern_SetBrightnessPercent(LONG newval) {
DISPLAY_BRIGHTNESS db;
if (!SysIntern_GetDisplayBrightness(&db))
return false;
if (newval < 0)
newval = 0;
if (newval > 100)
newval = 100;
if (db.ucDisplayPolicy & DISPLAYPOLICY_AC)
db.ucACBrightness = newval;
else if (db.ucDisplayPolicy & DISPLAYPOLICY_DC)
db.ucDCBrightness = newval;
else {
LOGERROR("Unsupported db.ucDisplayPolicy: %#lx\n", db.ucDisplayPolicy);
return false;
}
return SysIntern_SetDisplayBrightness(&db);
}
/* Get/Set the current brightness as a float-value between 0.0 and 1.0 */
static double last_system_brightness = -1.0;
static double Sys_GetBrightness(void) {
if (last_system_brightness < 0.0)
last_system_brightness = (double)SysIntern_GetBrightnessPercent() / 100.0;
return last_system_brightness;
}
static void Sys_SetBrightness(double value) {
if (value < 0.0)
value = 0.0;
if (value > 1.0)
value = 1.0;
if (value != last_system_brightness) {
SysIntern_SetBrightnessPercent((DWORD)(value * 100.0));
last_system_brightness = value;
}
}
#undef _INIT_GUID
#define _INIT_GUID(a, b, c, d, e) \
{ \
0x##a##u, 0x##b##u, 0x##c##u, \
{ \
(0x##d##u & 0xff00u) >> 8, \
(0x##d##u & 0xffu), \
(0x##e##ull & 0xff0000000000ull) >> 40, \
(0x##e##ull & 0xff00000000ull) >> 32, \
(0x##e##ull & 0xff000000ull) >> 24, \
(0x##e##ull & 0xff0000ull) >> 16, \
(0x##e##ull & 0xff00ull) >> 8, \
(0x##e##ull & 0xffull) \
} \
}
#undef DEFINE_GUID
#define DEFINE_GUID(name, data) \
static GUID const name = _INIT_GUID data
#undef CLSID_MMDeviceEnumerator
#undef IID_IMMDeviceEnumerator
#undef IID_IAudioEndpointVolume
#define CLSID_MMDeviceEnumerator real_CLSID_MMDeviceEnumerator
#define IID_IMMDeviceEnumerator real_IID_IMMDeviceEnumerator
#define IID_IAudioEndpointVolume real_IID_IAudioEndpointVolume
DEFINE_GUID(CLSID_MMDeviceEnumerator, (BCDE0395,E52F,467C,8E3D,C4579291692E));
DEFINE_GUID(IID_IMMDeviceEnumerator, (A95664D2,9614,4F35,A746,DE8DB63617E6));
DEFINE_GUID(IID_IAudioEndpointVolume, (5CDF2C82,841E,4546,9722,0CF74078229A));
static IAudioEndpointVolume *SysIntern_VolumeControllerAcquire(void) {
HRESULT hr;
IMMDevice *defaultDevice;
IMMDeviceEnumerator *deviceEnumerator;
IAudioEndpointVolume *endpointVolume;
if (!pdyn_CoInitialize || !pdyn_CoCreateInstance) {
if (!DynApi_InitializeOld32()) {
LOGERROR_GLE("DynApi_InitializeOld32()");
goto err;
}
}
deviceEnumerator = NULL;
defaultDevice = NULL;
endpointVolume = NULL;
hr = CoInitialize(NULL);
if (FAILED(hr)) {
LOGERROR_PTR("CoInitialize()", hr);
goto err;
}
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER,
&IID_IMMDeviceEnumerator, (LPVOID *)&deviceEnumerator);
if (FAILED(hr) || !deviceEnumerator) {
LOGERROR_PTR("CoCreateInstance(CLSID_MMDeviceEnumerator, IID_IMMDeviceEnumerator)", hr);
goto err2;
}
hr = deviceEnumerator->lpVtbl->GetDefaultAudioEndpoint(deviceEnumerator, eRender,
eConsole, &defaultDevice);
deviceEnumerator->lpVtbl->Release(deviceEnumerator);
if (FAILED(hr) || !defaultDevice) {
LOGERROR_PTR("IMMDeviceEnumerator::GetDefaultAudioEndpoint()", hr);
goto err2;
}
hr = defaultDevice->lpVtbl->Activate(defaultDevice,
#ifdef __cplusplus
IID_IAudioEndpointVolume,
#else /* __cplusplus */
&IID_IAudioEndpointVolume,
#endif /* !__cplusplus */
CLSCTX_INPROC_SERVER, NULL,
(LPVOID *)&endpointVolume);
defaultDevice->lpVtbl->Release(defaultDevice);
if (FAILED(hr) || !endpointVolume) {
LOGERROR_PTR("IMMDevice::Activate()", hr);
goto err2;
}
return endpointVolume;
err2:
if (pdyn_CoUninitialize)
CoUninitialize();
err:
return NULL;
}
static void SysIntern_VolumeControllerRelease(IAudioEndpointVolume *self) {
if (!self)
return;
self->lpVtbl->Release(self);
if (pdyn_CoUninitialize)
CoUninitialize();
}
static float last_system_volume = -1.0;
static float Sys_GetVolume(void) {
if (last_system_volume < 0.0f) {
IAudioEndpointVolume *endpointVolume;
endpointVolume = SysIntern_VolumeControllerAcquire();
if (endpointVolume) {
HRESULT hr;
hr = endpointVolume->lpVtbl->GetMasterVolumeLevelScalar(endpointVolume, &last_system_volume);
SysIntern_VolumeControllerRelease(endpointVolume);
if (FAILED(hr))
LOGERROR_PTR("IAudioEndpointVolume::GetMasterVolumeLevelScalar()", hr);
}
}
return last_system_volume;
}
static void Sys_SetVolume(float value) {
IAudioEndpointVolume *endpointVolume;
if (value < 0.0f)
value = 0.0f;
if (value > 1.0f)
value = 1.0f;
if (value == last_system_volume)
return;
endpointVolume = SysIntern_VolumeControllerAcquire();
if (endpointVolume) {
HRESULT hr;
hr = endpointVolume->lpVtbl->SetMasterVolumeLevelScalar(endpointVolume, value, NULL);
SysIntern_VolumeControllerRelease(endpointVolume);
if (FAILED(hr))
LOGERROR_PTR("IAudioEndpointVolume::SetMasterVolumeLevelScalar()", hr);
}
last_system_volume = value;
}
static int last_system_airplane = -1;
static int last_system_bluetooth = -1;
static int last_system_wifi = -1;
/* Airplane mode */
DEFINE_GUID(CLSID_RadioManagementAPI, (581333f6,28db,41be,bc7a,ff201f12f3f6));
DEFINE_GUID(CID_IRadioManager, (db3afbfb,08e6,46c6,aa70,bf9a34c30ab7));
typedef IUnknown IUIRadioInstanceCollection; /* Didn't bother rev-engineering this one... */
typedef DWORD _RADIO_CHANGE_REASON;
/* Undocumented interface exported from "RMApi.dll" (running as "RMsvc")
* Found by reverse engineering the interface using IDA and ghidra.
*
* NOTE: Now that I know the answer, I was also able to find the question:
* https://social.msdn.microsoft.com/Forums/en-US/e790991c-d093-49b0-a0cc-d30755d45ce0/about-the-way-to-turn-onoff-the-airplane-on-windows8
* Apparently, Microsoft doesn't ~want you to use this API~, even though it's
* the very API that their Settings app is using. And even more interestingly,
* despite the following (quote):
* """
* The interfaces you found are not published nor supported for application use,
* and there is no guarantee that the final shipping version of Windows 8 or future
* versions of Windows will have these interfaces. You must not use them. We do not
* have a public API that changes wireless radios directly.
* """
* It has been close to 8 years since then, and the latest, stable version of
* windows 10 still has that very same API (and I doubt that's going to change
* anytime soon).
*
* I'm really interested in whether or not this API can be used directly from
* inside of a uwp application (this is a COM interface after all, just like
* all of the stuff from the public (winrt) API). Only that this one seems to
* bypass all of those pretty little Privacy settings switches from your settings
* app. - Because after all: Why should Microsoft's private, internal APIs have
* to go through all of the troubles of asking the user for permission, when one
* can just bypass everything and talk to the relevant service directly ¯\_(ツ)_/¯
* Because if it can be accessed directly from uwp, then mere knowledge about this
* API means that the toggle under SystemSettings/Privacy/RF is literally just
* for show... */
#undef INTERFACE
#define INTERFACE IRadioManager
DECLARE_INTERFACE(IRadioManager) {
/* IUnknown */
STDMETHOD(QueryInterface)(THIS_ GUID const *riid, LPVOID *ppvObj);
STDMETHOD_(ULONG, AddRef)(THIS);
STDMETHOD_(ULONG, Release)(THIS);
/* IRadioManager (aka. `CUIRadioManager') */
/* Unconditionally writes `1' to `pdwState' (literally; that's all the assembly for
* this function ever does (on my machine)). But this function is called by the system
* settings app, and if it were to return `0', I'm guessing the flight-mode toggle
* would disappear or be greyed out in system settings... */
STDMETHOD(IsRMSupported)(THIS_ DWORD *pdwState);
/* ??? */
STDMETHOD(GetUIRadioInstances)(THIS_ IUIRadioInstanceCollection **param_1);
/* These are what you came here for: The getter/setting for the flight-mode switch!
* NOTE: param_2 and param_3 I don't really understand, but they must be non-NULL,
* and the current flight-mode-disabled state is written to `pbEnabled' */
STDMETHOD(GetSystemRadioState)(THIS_ int *pbEnabled, int *param_2, _RADIO_CHANGE_REASON *param_3);
STDMETHOD(SetSystemRadioState)(THIS_ int bEnabled);
/* Calls the internal function `_NotifySysRadioChanged()'. Not really sure when this one
* would have to be called. But this one might be related to `OnHardwareSliderChange()'?
* NOTE: `_NotifySysRadioChanged()' already gets called internally by `SetSystemRadioState()',
* so there is no need to call this manually! */
STDMETHOD(Refresh)(THIS);
/* From what I can guess, this function is called by the HID driver when an
* actual hardware slider (for the purpose of toggling flight-mode) is changed.
* The 2 arguments seem to control exactly how the switch was altered... */
STDMETHOD(OnHardwareSliderChange)(THIS_ int param_1, int param_2);
};
static IRadioManager *SysIntern_AcquireRadioManager(void) {
IRadioManager *irm = NULL;
HRESULT hr;
if (!pdyn_CoInitialize || !pdyn_CoCreateInstance) {
if (!DynApi_InitializeOld32()) {
LOGERROR_GLE("DynApi_InitializeOld32()");
goto done;
}
}
hr = CoInitialize(NULL);
if (FAILED(hr)) {
LOGERROR_PTR("CoInitialize()", hr);
goto done;
}
hr = CoCreateInstance(&CLSID_RadioManagementAPI, NULL, CLSCTX_LOCAL_SERVER,
&CID_IRadioManager, (void **)&irm);
if (FAILED(hr) || !irm) {
LOGERROR_PTR("CoCreateInstance()", hr);
irm = NULL;
goto done;
}
done:
return irm;
}
static void SysIntern_ReleaseRadioManager(IRadioManager *self) {
if (!self)
return;
self->lpVtbl->Release(self);
if (pdyn_CoUninitialize)
CoUninitialize();
}
static bool SysIntern_GetFlightModeEnabled(void) {
bool result = false;
IRadioManager *irm;
irm = SysIntern_AcquireRadioManager();
if (irm) {
int a, b;
HRESULT hr;
_RADIO_CHANGE_REASON c;
hr = irm->lpVtbl->GetSystemRadioState(irm, &a, &b, &c);
(void)b;
(void)c;
if (FAILED(hr)) {
LOGERROR_PTR("GetSystemRadioState()", hr);
} else {
result = a == 0;
}
SysIntern_ReleaseRadioManager(irm);
}
/* TODO: On error, the flight-mode-enabled state can be read from the registry:
* HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\RadioManagement\SystemRadioState
* Source: https://stackoverflow.com/questions/42273812/how-to-detect-airplane-mode-programmatically-in-laptop-with-windows-10-using-uwp */
return result;
}
static void SysIntern_SetFlightModeEnabled(bool enabled) {
IRadioManager *irm;
irm = SysIntern_AcquireRadioManager();
if (irm) {
HRESULT hr;
hr = irm->lpVtbl->SetSystemRadioState(irm, enabled ? 0 : 1);
if (FAILED(hr)) {
LOGERROR_PTR("SetSystemRadioState()", hr);
} else {
if (enabled) {
/* Disabling flight mode means that these become disabled! */
last_system_bluetooth = 0;
last_system_wifi = 0;
} else {
/* Disabling flight mode means that these are once again undefined! */
last_system_bluetooth = -1;
last_system_wifi = -1;
}
}
SysIntern_ReleaseRadioManager(irm);
}
}
static bool Sys_GetFlightModeEnabled(void) {
if (last_system_airplane < 0)
last_system_airplane = SysIntern_GetFlightModeEnabled();
return last_system_airplane != 0;
}
static void Sys_SetFlightModeEnabled(bool enabled) {
if (last_system_airplane == enabled)
return;
SysIntern_SetFlightModeEnabled(enabled);
last_system_airplane = enabled;
}
/* RADIO Access (Bluetooth / Wifi) */
typedef DWORD RADIOACCESSSTATUS;
#define RADIOACCESSSTATUS_UNSPECIFIED 0
#define RADIOACCESSSTATUS_ALLOWED 1
#define RADIOACCESSSTATUS_DENIED_BY_USER 2
#define RADIOACCESSSTATUS_DENIED_BY_SYSTEM 3
typedef DWORD RADIOKIND;
#define RADIOKIND_OTHER 0
#define RADIOKIND_WIFI 1
#define RADIOKIND_MOBILE_BROADBAND 2
#define RADIOKIND_BLUETOOTH 3
#define RADIOKIND_FM 4
typedef DWORD RADIOSTATE;
#define RADIOSTATE_UNKNOWN 0
#define RADIOSTATE_ON 1
#define RADIOSTATE_OFF 2
#define RADIOSTATE_DISABLED 3
#undef IInspectable
#undef IID_IUnknown
#undef IID_IAgileObject
#undef IID_IRadioStatics
#undef HSTRING
#undef HSTRING_HEADER
#define IInspectable real_IInspectable
#define IID_IUnknown real_IID_IUnknown
#define IID_IAgileObject real_IID_IAgileObject
#define IID_IRadioStatics real_IID_IRadioStatics
#define HSTRING real_HSTRING
#define HSTRING_HEADER real_HSTRING_HEADER
DECLARE_HANDLE(HSTRING);
typedef struct {
union {
PVOID Reserved1;
#ifdef _WIN64
char Reserved2[24];
#else /* _WIN64 */
char Reserved2[20];
#endif /* !_WIN64 */
} Reserved;
} HSTRING_HEADER;
DEFINE_GUID(IID_IUnknown, (00000000,0000,0000,c000,000000000046));
DEFINE_GUID(IID_IAgileObject, (94ea2b94,e9cc,49e0,c0ff,ee64ca8f5b90));
DEFINE_GUID(IID_IRadioStatics, (5fb6a12e,67cb,46ae,aae9,65919f86eff4));
DEFINE_GUID(IID_AsyncOperationCompletedHandler_IVectorView_Radio, (d30691e6,60a0,59c9,8965,5bbe282e8208));
DEFINE_GUID(IID_AsyncOperationCompletedHandler_RadioAccessStatus, (bd248e73,f05f,574c,ae3d,9b95c4bf282a));
/* From "api-ms-win-core-winrt-string-l1-1-0.dll": */
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, WindowsCreateStringReference, (PCWSTR sourceString, UINT32 length, HSTRING_HEADER *hstringHeader, HSTRING *string));
DEFINE_DYNAMIC_FUNCTION(HRESULT, STDAPICALLTYPE, WindowsDeleteString, (HSTRING string));
#define WindowsDeleteString (*pdyn_WindowsDeleteString)
#define WindowsCreateStringReference (*pdyn_WindowsCreateStringReference)
/* From "api-ms-win-core-winrt-l1-1-0.dll": */
DEFINE_DYNAMIC_FUNCTION(HRESULT, WINAPI, RoGetActivationFactory, (HSTRING activatableClassId, GUID const *iid, void** factory));
#define RoGetActivationFactory (*pdyn_RoGetActivationFactory)
static HMODULE hModule_api_ms_win_core_winrt_string_l1_1_0; /* "api-ms-win-core-winrt-string-l1-1-0.dll" */
static HMODULE hModule_api_ms_win_core_winrt_l1_1_0; /* "api-ms-win-core-winrt-l1-1-0.dll" */
static void SysIntern_FreeMsWinCoreWinRtAPIS(void) {
#define X_FreeLibrary(x) ((x) && (FreeLibrary(x), (x) = NULL, 1))
X_FreeLibrary(hModule_api_ms_win_core_winrt_string_l1_1_0);
X_FreeLibrary(hModule_api_ms_win_core_winrt_l1_1_0);
#undef X_FreeLibrary
}
static bool SysIntern_LoadMsWinCoreWinRtAPIS(void) {
hModule_api_ms_win_core_winrt_string_l1_1_0 = LoadLibraryW(L"api-ms-win-core-winrt-string-l1-1-0.dll");
if (!hModule_api_ms_win_core_winrt_string_l1_1_0) {
LOGERROR_GLE("LoadLibraryW(L\"api-ms-win-core-winrt-string-l1-1-0.dll\")");
goto fail;
}
hModule_api_ms_win_core_winrt_l1_1_0 = LoadLibraryW(L"api-ms-win-core-winrt-l1-1-0.dll");
if (!hModule_api_ms_win_core_winrt_l1_1_0) {
LOGERROR_GLE("LoadLibraryW(L\"api-ms-win-core-winrt-l1-1-0.dll\")");
goto fail;
}
DynApi_LoadFunction(hModule_api_ms_win_core_winrt_string_l1_1_0, WindowsDeleteString);
DynApi_LoadFunction(hModule_api_ms_win_core_winrt_string_l1_1_0, WindowsCreateStringReference);
DynApi_LoadFunction(hModule_api_ms_win_core_winrt_l1_1_0, RoGetActivationFactory);
return true;
fail:
SysIntern_FreeMsWinCoreWinRtAPIS();
return false;
}
#undef INTERFACE
#define INTERFACE IInspectable
DECLARE_INTERFACE(IInspectable) {
/* IUnknown */
STDMETHOD(QueryInterface)(THIS_ GUID const *riid, LPVOID FAR * ppvObj);
STDMETHOD_(ULONG, AddRef)(THIS);
STDMETHOD_(ULONG, Release)(THIS);
/* IInspectable */
STDMETHOD(GetIids)(THIS_ DWORD *count, GUID **ids);
STDMETHOD(GetRuntimeClassName)(THIS_ void **name);
STDMETHOD(GetTrustLevel)(THIS_ /*Windows::Foundation::TrustLevel*/ int *level);
};
#undef INTERFACE
#define INTERFACE IRadioStatics
DECLARE_INTERFACE(IRadioStatics) {
/* IUnknown */
STDMETHOD(QueryInterface)(THIS_ GUID const *riid, LPVOID FAR * ppvObj);
STDMETHOD_(ULONG, AddRef)(THIS);
STDMETHOD_(ULONG, Release)(THIS);
/* IInspectable */
STDMETHOD(GetIids)(THIS_ DWORD *count, GUID **ids);
STDMETHOD(GetRuntimeClassName)(THIS_ void **name);
STDMETHOD(GetTrustLevel)(THIS_ /*Windows::Foundation::TrustLevel*/ int *level);
/* IRadioStatics */
STDMETHOD(GetRadiosAsync)(THIS_ void **value);
STDMETHOD(GetDeviceSelector)(THIS_ void **deviceSelector);
STDMETHOD(FromIdAsync)(THIS_ void *deviceId, void **value);
STDMETHOD(RequestAccessAsync)(THIS_ void **value);
};
#undef INTERFACE
#define INTERFACE IAsyncOperation
DECLARE_INTERFACE(IAsyncOperation) {
/* IUnknown */
STDMETHOD(QueryInterface)(THIS_ GUID const *riid, LPVOID FAR * ppvObj);
STDMETHOD_(ULONG, AddRef)(THIS);
STDMETHOD_(ULONG, Release)(THIS);
/* IInspectable */
STDMETHOD(GetIids)(THIS_ DWORD *count, GUID **ids);
STDMETHOD(GetRuntimeClassName)(THIS_ void **name);
STDMETHOD(GetTrustLevel)(THIS_ /*Windows::Foundation::TrustLevel*/ int *level);
/* IAsyncOperation */
STDMETHOD(put_Completed)(THIS_ void *handler);
STDMETHOD(get_Completed)(THIS_ void **handler);
STDMETHOD(GetResults)(THIS_ void **results);
};
#undef INTERFACE
#define INTERFACE IAsyncCompletionHandler
DECLARE_INTERFACE(IAsyncCompletionHandler) {
/* IUnknown */
STDMETHOD(QueryInterface)(THIS_ GUID const *riid, LPVOID FAR * ppvObj);
STDMETHOD_(ULONG, AddRef)(THIS);
STDMETHOD_(ULONG, Release)(THIS);
/* IAsyncCompletionHandler */
STDMETHOD(Invoke)(THIS_ void *asyncInfo, /*winrt::Windows::Foundation::AsyncStatus*/ int status);
};
#undef INTERFACE
#define INTERFACE IVectorView
DECLARE_INTERFACE(IVectorView) {
/* IUnknown */
STDMETHOD(QueryInterface)(THIS_ GUID const *riid, LPVOID FAR * ppvObj);
STDMETHOD_(ULONG, AddRef)(THIS);
STDMETHOD_(ULONG, Release)(THIS);
/* IInspectable */
STDMETHOD(GetIids)(THIS_ DWORD *count, GUID **ids);
STDMETHOD(GetRuntimeClassName)(THIS_ void **name);
STDMETHOD(GetTrustLevel)(THIS_ /*Windows::Foundation::TrustLevel*/ int *level);
/* IVectorView */
STDMETHOD(GetAt)(THIS_ DWORD index, void **item);
STDMETHOD(get_Size)(THIS_ DWORD * size);
STDMETHOD(IndexOf)(THIS_ void *value, DWORD *index, bool *found);
STDMETHOD(GetMany)(THIS_ DWORD startIndex, DWORD capacity, void **value, DWORD *actual);
};
#undef INTERFACE
#define INTERFACE IRadio
DECLARE_INTERFACE(IRadio) {
/* IUnknown */
STDMETHOD(QueryInterface)(THIS_ GUID const *riid, LPVOID FAR * ppvObj);
STDMETHOD_(ULONG, AddRef)(THIS);
STDMETHOD_(ULONG, Release)(THIS);
/* IInspectable */
STDMETHOD(GetIids)(THIS_ DWORD *count, GUID **ids);
STDMETHOD(GetRuntimeClassName)(THIS_ void **name);
STDMETHOD(GetTrustLevel)(THIS_ /*Windows::Foundation::TrustLevel*/ int *level);
/* IRadio */
STDMETHOD(SetStateAsync)(THIS_ RADIOSTATE value, void **retval);
STDMETHOD(add_StateChanged)(THIS_ void *handler, INT64 *eventCookie);
STDMETHOD(remove_StateChanged)(THIS_ INT64 eventCookie);
STDMETHOD(get_State)(THIS_ RADIOSTATE *value);
STDMETHOD(get_Name)(THIS_ void **value);
STDMETHOD(get_Kind)(THIS_ RADIOKIND *value);
};
static IRadioStatics *SysIntern_GetRadioStaticsActivationFactory(void) {
IRadioStatics *result = NULL;
HSTRING_HEADER hsHdr;
HSTRING hstr;
HRESULT hr;
hr = pdyn_WindowsCreateStringReference(L"Windows.Devices.Radios.Radio",
28, &hsHdr, &hstr);
if (FAILED(hr)) {
LOGERROR_PTR("WindowsCreateStringReference()", hr);
goto done;
}
hr = pdyn_RoGetActivationFactory(hstr, &IID_IRadioStatics, (void **)&result);
if (hr == CO_E_NOTINITIALIZED) {
if (!pdyn_CoIncrementMTAUsage)
DynApi_InitializeOld32();
if (pdyn_CoIncrementMTAUsage) {
CO_MTA_USAGE_COOKIE cookie;
CoIncrementMTAUsage(&cookie);
hr = pdyn_RoGetActivationFactory(hstr, &IID_IRadioStatics, (void **)&result);
}
}
pdyn_WindowsDeleteString(hstr);