-
Notifications
You must be signed in to change notification settings - Fork 1
/
NomadMemory.au3
4448 lines (4032 loc) · 181 KB
/
NomadMemory.au3
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
Func _winapi_getlasterror($curerr = @error, $curext = @extended)
Local $aresult = DllCall("kernel32.dll", "dword", "GetLastError")
Return SetError($curerr, $curext, $aresult[0])
EndFunc
Func _winapi_setlasterror($ierrcode, $curerr = @error, $curext = @extended)
DllCall("kernel32.dll", "none", "SetLastError", "dword", $ierrcode)
Return SetError($curerr, $curext)
EndFunc
Func _security__adjusttokenprivileges($htoken, $fdisableall, $pnewstate, $ibufferlen, $pprevstate = 0, $prequired = 0)
Local $aresult = DllCall("advapi32.dll", "bool", "AdjustTokenPrivileges", "handle", $htoken, "bool", $fdisableall, "ptr", $pnewstate, "dword", $ibufferlen, "ptr", $pprevstate, "ptr", $prequired)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _security__getaccountsid($saccount, $ssystem = "")
Local $aacct = _security__lookupaccountname($saccount, $ssystem)
If @error Then Return SetError(@error, 0, 0)
Return _security__stringsidtosid($aacct[0])
EndFunc
Func _security__getlengthsid($psid)
If NOT _security__isvalidsid($psid) Then Return SetError(-1, 0, 0)
Local $aresult = DllCall("advapi32.dll", "dword", "GetLengthSid", "ptr", $psid)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _security__gettokeninformation($htoken, $iclass)
Local $aresult = DllCall("advapi32.dll", "bool", "GetTokenInformation", "handle", $htoken, "int", $iclass, "ptr", 0, "dword", 0, "dword*", 0)
If @error Then Return SetError(@error, @extended, 0)
If NOT $aresult[0] Then Return 0
Local $tbuffer = DllStructCreate("byte[" & $aresult[5] & "]")
Local $pbuffer = DllStructGetPtr($tbuffer)
$aresult = DllCall("advapi32.dll", "bool", "GetTokenInformation", "handle", $htoken, "int", $iclass, "ptr", $pbuffer, "dword", $aresult[5], "dword*", 0)
If @error Then Return SetError(@error, @extended, 0)
If NOT $aresult[0] Then Return 0
Return $tbuffer
EndFunc
Func _security__impersonateself($ilevel = 2)
Local $aresult = DllCall("advapi32.dll", "bool", "ImpersonateSelf", "int", $ilevel)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _security__isvalidsid($psid)
Local $aresult = DllCall("advapi32.dll", "bool", "IsValidSid", "ptr", $psid)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _security__lookupaccountname($saccount, $ssystem = "")
Local $tdata = DllStructCreate("byte SID[256]")
Local $psid = DllStructGetPtr($tdata, "SID")
Local $aresult = DllCall("advapi32.dll", "bool", "LookupAccountNameW", "wstr", $ssystem, "wstr", $saccount, "ptr", $psid, "dword*", 256, "wstr", "", "dword*", 256, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
If NOT $aresult[0] Then Return 0
Local $aacct[3]
$aacct[0] = _security__sidtostringsid($psid)
$aacct[1] = $aresult[5]
$aacct[2] = $aresult[7]
Return $aacct
EndFunc
Func _security__lookupaccountsid($vsid)
Local $psid, $aacct[3]
If IsString($vsid) Then
Local $tsid = _security__stringsidtosid($vsid)
$psid = DllStructGetPtr($tsid)
Else
$psid = $vsid
EndIf
If NOT _security__isvalidsid($psid) Then Return SetError(-1, 0, 0)
Local $aresult = DllCall("advapi32.dll", "bool", "LookupAccountSidW", "ptr", 0, "ptr", $psid, "wstr", "", "dword*", 256, "wstr", "", "dword*", 256, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
If NOT $aresult[0] Then Return 0
Local $aacct[3]
$aacct[0] = $aresult[3]
$aacct[1] = $aresult[5]
$aacct[2] = $aresult[7]
Return $aacct
EndFunc
Func _security__lookupprivilegevalue($ssystem, $sname)
Local $aresult = DllCall("advapi32.dll", "int", "LookupPrivilegeValueW", "wstr", $ssystem, "wstr", $sname, "int64*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return SetError(0, $aresult[0], $aresult[3])
EndFunc
Func _security__openprocesstoken($hprocess, $iaccess)
Local $aresult = DllCall("advapi32.dll", "int", "OpenProcessToken", "handle", $hprocess, "dword", $iaccess, "ptr", 0)
If @error Then Return SetError(@error, @extended, 0)
Return SetError(0, $aresult[0], $aresult[3])
EndFunc
Func _security__openthreadtoken($iaccess, $hthread = 0, $fopenasself = False)
If $hthread = 0 Then $hthread = DllCall("kernel32.dll", "handle", "GetCurrentThread")
If @error Then Return SetError(@error, @extended, 0)
Local $aresult = DllCall("advapi32.dll", "bool", "OpenThreadToken", "handle", $hthread[0], "dword", $iaccess, "int", $fopenasself, "ptr*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return SetError(0, $aresult[0], $aresult[4])
EndFunc
Func _security__openthreadtokenex($iaccess, $hthread = 0, $fopenasself = False)
Local $htoken = _security__openthreadtoken($iaccess, $hthread, $fopenasself)
If $htoken = 0 Then
If _winapi_getlasterror() <> $error_no_token Then Return SetError(-3, _winapi_getlasterror(), 0)
If NOT _security__impersonateself() Then Return SetError(-1, _winapi_getlasterror(), 0)
$htoken = _security__openthreadtoken($iaccess, $hthread, $fopenasself)
If $htoken = 0 Then Return SetError(-2, _winapi_getlasterror(), 0)
EndIf
Return $htoken
EndFunc
Func _security__setprivilege($htoken, $sprivilege, $fenable)
Local $iluid = _security__lookupprivilegevalue("", $sprivilege)
If $iluid = 0 Then Return SetError(-1, 0, False)
Local $tcurrstate = DllStructCreate($tagtoken_privileges)
Local $pcurrstate = DllStructGetPtr($tcurrstate)
Local $icurrstate = DllStructGetSize($tcurrstate)
Local $tprevstate = DllStructCreate($tagtoken_privileges)
Local $pprevstate = DllStructGetPtr($tprevstate)
Local $iprevstate = DllStructGetSize($tprevstate)
Local $trequired = DllStructCreate("int Data")
Local $prequired = DllStructGetPtr($trequired)
DllStructSetData($tcurrstate, "Count", 1)
DllStructSetData($tcurrstate, "LUID", $iluid)
If NOT _security__adjusttokenprivileges($htoken, False, $pcurrstate, $icurrstate, $pprevstate, $prequired) Then Return SetError(-2, @error, False)
DllStructSetData($tprevstate, "Count", 1)
DllStructSetData($tprevstate, "LUID", $iluid)
Local $iattributes = DllStructGetData($tprevstate, "Attributes")
If $fenable Then
$iattributes = BitOR($iattributes, $se_privilege_enabled)
Else
$iattributes = BitAND($iattributes, BitNOT($se_privilege_enabled))
EndIf
DllStructSetData($tprevstate, "Attributes", $iattributes)
If NOT _security__adjusttokenprivileges($htoken, False, $pprevstate, $iprevstate, $pcurrstate, $prequired) Then Return SetError(-3, @error, False)
Return True
EndFunc
Func _security__sidtostringsid($psid)
If NOT _security__isvalidsid($psid) Then Return SetError(-1, 0, "")
Local $aresult = DllCall("advapi32.dll", "int", "ConvertSidToStringSidW", "ptr", $psid, "ptr*", 0)
If @error Then Return SetError(@error, @extended, "")
If NOT $aresult[0] Then Return ""
Local $tbuffer = DllStructCreate("wchar Text[256]", $aresult[2])
Local $ssid = DllStructGetData($tbuffer, "Text")
DllCall("Kernel32.dll", "ptr", "LocalFree", "ptr", $aresult[2])
Return $ssid
EndFunc
Func _security__sidtypestr($itype)
Switch $itype
Case 1
Return "User"
Case 2
Return "Group"
Case 3
Return "Domain"
Case 4
Return "Alias"
Case 5
Return "Well Known Group"
Case 6
Return "Deleted Account"
Case 7
Return "Invalid"
Case 8
Return "Invalid"
Case 9
Return "Computer"
Case Else
Return "Unknown SID Type"
EndSwitch
EndFunc
Func _security__stringsidtosid($ssid)
Local $aresult = DllCall("advapi32.dll", "bool", "ConvertStringSidToSidW", "wstr", $ssid, "ptr*", 0)
If @error Then Return SetError(@error, @extended, 0)
If NOT $aresult[0] Then Return 0
Local $isize = _security__getlengthsid($aresult[2])
Local $tbuffer = DllStructCreate("byte Data[" & $isize & "]", $aresult[2])
Local $tsid = DllStructCreate("byte Data[" & $isize & "]")
DllStructSetData($tsid, "Data", DllStructGetData($tbuffer, "Data"))
DllCall("kernel32.dll", "ptr", "LocalFree", "ptr", $aresult[2])
Return $tsid
EndFunc
Global Const $tagmemmap = "handle hProc;ulong_ptr Size;ptr Mem"
Func _memfree(ByRef $tmemmap)
Local $pmemory = DllStructGetData($tmemmap, "Mem")
Local $hprocess = DllStructGetData($tmemmap, "hProc")
Local $bresult = _memvirtualfreeex($hprocess, $pmemory, 0, $mem_release)
DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hprocess)
If @error Then Return SetError(@error, @extended, False)
Return $bresult
EndFunc
Func _memglobalalloc($ibytes, $iflags = 0)
Local $aresult = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $iflags, "ulong_ptr", $ibytes)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _memglobalfree($hmem)
Local $aresult = DllCall("kernel32.dll", "ptr", "GlobalFree", "handle", $hmem)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _memgloballock($hmem)
Local $aresult = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hmem)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _memglobalsize($hmem)
Local $aresult = DllCall("kernel32.dll", "ulong_ptr", "GlobalSize", "handle", $hmem)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _memglobalunlock($hmem)
Local $aresult = DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hmem)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _meminit($hwnd, $isize, ByRef $tmemmap)
Local $aresult = DllCall("User32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $hwnd, "dword*", 0)
If @error Then Return SetError(@error, @extended, 0)
Local $iprocessid = $aresult[2]
If $iprocessid = 0 Then Return SetError(1, 0, 0)
Local $iaccess = BitOR($process_vm_operation, $process_vm_read, $process_vm_write)
Local $hprocess = __mem_openprocess($iaccess, False, $iprocessid, True)
Local $ialloc = BitOR($mem_reserve, $mem_commit)
Local $pmemory = _memvirtualallocex($hprocess, 0, $isize, $ialloc, $page_readwrite)
If $pmemory = 0 Then Return SetError(2, 0, 0)
$tmemmap = DllStructCreate($tagmemmap)
DllStructSetData($tmemmap, "hProc", $hprocess)
DllStructSetData($tmemmap, "Size", $isize)
DllStructSetData($tmemmap, "Mem", $pmemory)
Return $pmemory
EndFunc
Func _memmovememory($psource, $pdest, $ilength)
DllCall("kernel32.dll", "none", "RtlMoveMemory", "ptr", $pdest, "ptr", $psource, "ulong_ptr", $ilength)
If @error Then Return SetError(@error, @extended)
EndFunc
Func _memread(ByRef $tmemmap, $psrce, $pdest, $isize)
Local $aresult = DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", DllStructGetData($tmemmap, "hProc"), "ptr", $psrce, "ptr", $pdest, "ulong_ptr", $isize, "ulong_ptr*", 0)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _memwrite(ByRef $tmemmap, $psrce, $pdest = 0, $isize = 0, $ssrce = "ptr")
If $pdest = 0 Then $pdest = DllStructGetData($tmemmap, "Mem")
If $isize = 0 Then $isize = DllStructGetData($tmemmap, "Size")
Local $aresult = DllCall("kernel32.dll", "bool", "WriteProcessMemory", "handle", DllStructGetData($tmemmap, "hProc"), "ptr", $pdest, $ssrce, $psrce, "ulong_ptr", $isize, "ulong_ptr*", 0)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _memvirtualalloc($paddress, $isize, $iallocation, $iprotect)
Local $aresult = DllCall("kernel32.dll", "ptr", "VirtualAlloc", "ptr", $paddress, "ulong_ptr", $isize, "dword", $iallocation, "dword", $iprotect)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _memvirtualallocex($hprocess, $paddress, $isize, $iallocation, $iprotect)
Local $aresult = DllCall("kernel32.dll", "ptr", "VirtualAllocEx", "handle", $hprocess, "ptr", $paddress, "ulong_ptr", $isize, "dword", $iallocation, "dword", $iprotect)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _memvirtualfree($paddress, $isize, $ifreetype)
Local $aresult = DllCall("kernel32.dll", "bool", "VirtualFree", "ptr", $paddress, "ulong_ptr", $isize, "dword", $ifreetype)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _memvirtualfreeex($hprocess, $paddress, $isize, $ifreetype)
Local $aresult = DllCall("kernel32.dll", "bool", "VirtualFreeEx", "handle", $hprocess, "ptr", $paddress, "ulong_ptr", $isize, "dword", $ifreetype)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func __mem_openprocess($iaccess, $finherit, $iprocessid, $fdebugpriv = False)
Local $aresult = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", $iaccess, "bool", $finherit, "dword", $iprocessid)
If @error Then Return SetError(@error, @extended, 0)
If $aresult[0] Then Return $aresult[0]
If NOT $fdebugpriv Then Return 0
Local $htoken = _security__openthreadtokenex(BitOR($token_adjust_privileges, $token_query))
If @error Then Return SetError(@error, @extended, 0)
_security__setprivilege($htoken, "SeDebugPrivilege", True)
Local $ierror = @error
Local $ilasterror = @extended
Local $iret = 0
If NOT @error Then
$aresult = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", $iaccess, "bool", $finherit, "dword", $iprocessid)
$ierror = @error
$ilasterror = @extended
If $aresult[0] Then $iret = $aresult[0]
_security__setprivilege($htoken, "SeDebugPrivilege", False)
If @error Then
$ierror = @error
$ilasterror = @extended
EndIf
EndIf
DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $htoken)
Return SetError($ierror, $ilasterror, $iret)
EndFunc
;pt2 ************************************
Func _sendmessage($hwnd, $imsg, $wparam = 0, $lparam = 0, $ireturn = 0, $wparamtype = "wparam", $lparamtype = "lparam", $sreturntype = "lresult")
Local $aresult = DllCall("user32.dll", $sreturntype, "SendMessageW", "hwnd", $hwnd, "uint", $imsg, $wparamtype, $wparam, $lparamtype, $lparam)
If @error Then Return SetError(@error, @extended, "")
If $ireturn >= 0 AND $ireturn <= 4 Then Return $aresult[$ireturn]
Return $aresult
EndFunc
Func _sendmessagea($hwnd, $imsg, $wparam = 0, $lparam = 0, $ireturn = 0, $wparamtype = "wparam", $lparamtype = "lparam", $sreturntype = "lresult")
Local $aresult = DllCall("user32.dll", $sreturntype, "SendMessageA", "hwnd", $hwnd, "uint", $imsg, $wparamtype, $wparam, $lparamtype, $lparam)
If @error Then Return SetError(@error, @extended, "")
If $ireturn >= 0 AND $ireturn <= 4 Then Return $aresult[$ireturn]
Return $aresult
EndFunc
;pt 3 ****************************
Func _winapi_attachconsole($iprocessid = -1)
Local $aresult = DllCall("kernel32.dll", "bool", "AttachConsole", "dword", $iprocessid)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_attachthreadinput($iattach, $iattachto, $fattach)
Local $aresult = DllCall("user32.dll", "bool", "AttachThreadInput", "dword", $iattach, "dword", $iattachto, "bool", $fattach)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_beep($ifreq = 500, $iduration = 1000)
Local $aresult = DllCall("kernel32.dll", "bool", "Beep", "dword", $ifreq, "dword", $iduration)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_bitblt($hdestdc, $ixdest, $iydest, $iwidth, $iheight, $hsrcdc, $ixsrc, $iysrc, $irop)
Local $aresult = DllCall("gdi32.dll", "bool", "BitBlt", "handle", $hdestdc, "int", $ixdest, "int", $iydest, "int", $iwidth, "int", $iheight, "handle", $hsrcdc, "int", $ixsrc, "int", $iysrc, "dword", $irop)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_callnexthookex($hhk, $icode, $wparam, $lparam)
Local $aresult = DllCall("user32.dll", "lresult", "CallNextHookEx", "handle", $hhk, "int", $icode, "wparam", $wparam, "lparam", $lparam)
If @error Then Return SetError(@error, @extended, -1)
Return $aresult[0]
EndFunc
Func _winapi_callwindowproc($lpprevwndfunc, $hwnd, $msg, $wparam, $lparam)
Local $aresult = DllCall("user32.dll", "lresult", "CallWindowProc", "ptr", $lpprevwndfunc, "hwnd", $hwnd, "uint", $msg, "wparam", $wparam, "lparam", $lparam)
If @error Then Return SetError(@error, @extended, -1)
Return $aresult[0]
EndFunc
Func _winapi_clienttoscreen($hwnd, ByRef $tpoint)
Local $ppoint = DllStructGetPtr($tpoint)
DllCall("user32.dll", "bool", "ClientToScreen", "hwnd", $hwnd, "ptr", $ppoint)
Return SetError(@error, @extended, $tpoint)
EndFunc
Func _winapi_closehandle($hobject)
Local $aresult = DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hobject)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_combinergn($hrgndest, $hrgnsrc1, $hrgnsrc2, $icombinemode)
Local $aresult = DllCall("gdi32.dll", "int", "CombineRgn", "handle", $hrgndest, "handle", $hrgnsrc1, "handle", $hrgnsrc2, "int", $icombinemode)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_commdlgextendederror()
Local Const $cderr_dialogfailure = 65535
Local Const $cderr_findresfailure = 6
Local Const $cderr_initialization = 2
Local Const $cderr_loadresfailure = 7
Local Const $cderr_loadstrfailure = 5
Local Const $cderr_lockresfailure = 8
Local Const $cderr_memallocfailure = 9
Local Const $cderr_memlockfailure = 10
Local Const $cderr_nohinstance = 4
Local Const $cderr_nohook = 11
Local Const $cderr_notemplate = 3
Local Const $cderr_registermsgfail = 12
Local Const $cderr_structsize = 1
Local Const $fnerr_buffertoosmall = 12291
Local Const $fnerr_invalidfilename = 12290
Local Const $fnerr_subclassfailure = 12289
Local $aresult = DllCall("comdlg32.dll", "dword", "CommDlgExtendedError")
If @error Then Return SetError(@error, @extended, 0)
Switch $aresult[0]
Case $cderr_dialogfailure
Return SetError($aresult[0], 0, "The dialog box could not be created." & @LF & "The common dialog box function's call to the DialogBox function failed." & @LF & "For example, this error occurs if the common dialog box call specifies an invalid window handle.")
Case $cderr_findresfailure
Return SetError($aresult[0], 0, "The common dialog box function failed to find a specified resource.")
Case $cderr_initialization
Return SetError($aresult[0], 0, "The common dialog box function failed during initialization." & @LF & "This error often occurs when sufficient memory is not available.")
Case $cderr_loadresfailure
Return SetError($aresult[0], 0, "The common dialog box function failed to load a specified resource.")
Case $cderr_loadstrfailure
Return SetError($aresult[0], 0, "The common dialog box function failed to load a specified string.")
Case $cderr_lockresfailure
Return SetError($aresult[0], 0, "The common dialog box function failed to lock a specified resource.")
Case $cderr_memallocfailure
Return SetError($aresult[0], 0, "The common dialog box function was unable to allocate memory for internal structures.")
Case $cderr_memlockfailure
Return SetError($aresult[0], 0, "The common dialog box function was unable to lock the memory associated with a handle.")
Case $cderr_nohinstance
Return SetError($aresult[0], 0, "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & "but you failed to provide a corresponding instance handle.")
Case $cderr_nohook
Return SetError($aresult[0], 0, "The ENABLEHOOK flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & "but you failed to provide a pointer to a corresponding hook procedure.")
Case $cderr_notemplate
Return SetError($aresult[0], 0, "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & "but you failed to provide a corresponding template.")
Case $cderr_registermsgfail
Return SetError($aresult[0], 0, "The RegisterWindowMessage function returned an error code when it was called by the common dialog box function.")
Case $cderr_structsize
Return SetError($aresult[0], 0, "The lStructSize member of the initialization structure for the corresponding common dialog box is invalid")
Case $fnerr_buffertoosmall
Return SetError($aresult[0], 0, "The buffer pointed to by the lpstrFile member of the OPENFILENAME structure is too small for the file name specified by the user." & @LF & "The first two bytes of the lpstrFile buffer contain an integer value specifying the size, in TCHARs, required to receive the full name.")
Case $fnerr_invalidfilename
Return SetError($aresult[0], 0, "A file name is invalid.")
Case $fnerr_subclassfailure
Return SetError($aresult[0], 0, "An attempt to subclass a list box failed because sufficient memory was not available.")
EndSwitch
Return Hex($aresult[0])
EndFunc
Func _winapi_copyicon($hicon)
Local $aresult = DllCall("user32.dll", "handle", "CopyIcon", "handle", $hicon)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createbitmap($iwidth, $iheight, $iplanes = 1, $ibitsperpel = 1, $pbits = 0)
Local $aresult = DllCall("gdi32.dll", "handle", "CreateBitmap", "int", $iwidth, "int", $iheight, "uint", $iplanes, "uint", $ibitsperpel, "ptr", $pbits)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createcompatiblebitmap($hdc, $iwidth, $iheight)
Local $aresult = DllCall("gdi32.dll", "handle", "CreateCompatibleBitmap", "handle", $hdc, "int", $iwidth, "int", $iheight)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createcompatibledc($hdc)
Local $aresult = DllCall("gdi32.dll", "handle", "CreateCompatibleDC", "handle", $hdc)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createevent($pattributes = 0, $fmanualreset = True, $finitialstate = True, $sname = "")
Local $snametype = "wstr"
If $sname = "" Then
$sname = 0
$snametype = "ptr"
EndIf
Local $aresult = DllCall("kernel32.dll", "handle", "CreateEventW", "ptr", $pattributes, "bool", $fmanualreset, "bool", $finitialstate, $snametype, $sname)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createfile($sfilename, $icreation, $iaccess = 4, $ishare = 0, $iattributes = 0, $psecurity = 0)
Local $ida = 0, $ism = 0, $icd = 0, $ifa = 0
If BitAND($iaccess, 1) <> 0 Then $ida = BitOR($ida, $generic_execute)
If BitAND($iaccess, 2) <> 0 Then $ida = BitOR($ida, $generic_read)
If BitAND($iaccess, 4) <> 0 Then $ida = BitOR($ida, $generic_write)
If BitAND($ishare, 1) <> 0 Then $ism = BitOR($ism, $file_share_delete)
If BitAND($ishare, 2) <> 0 Then $ism = BitOR($ism, $file_share_read)
If BitAND($ishare, 4) <> 0 Then $ism = BitOR($ism, $file_share_write)
Switch $icreation
Case 0
$icd = $create_new
Case 1
$icd = $create_always
Case 2
$icd = $open_existing
Case 3
$icd = $open_always
Case 4
$icd = $truncate_existing
EndSwitch
If BitAND($iattributes, 1) <> 0 Then $ifa = BitOR($ifa, $file_attribute_archive)
If BitAND($iattributes, 2) <> 0 Then $ifa = BitOR($ifa, $file_attribute_hidden)
If BitAND($iattributes, 4) <> 0 Then $ifa = BitOR($ifa, $file_attribute_readonly)
If BitAND($iattributes, 8) <> 0 Then $ifa = BitOR($ifa, $file_attribute_system)
Local $aresult = DllCall("kernel32.dll", "handle", "CreateFileW", "wstr", $sfilename, "dword", $ida, "dword", $ism, "ptr", $psecurity, "dword", $icd, "dword", $ifa, "ptr", 0)
If @error OR $aresult[0] = Ptr(-1) Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createfont($nheight, $nwidth, $nescape = 0, $norientn = 0, $fnweight = $__winapiconstant_fw_normal, $bitalic = False, $bunderline = False, $bstrikeout = False, $ncharset = $__winapiconstant_default_charset, $noutputprec = $__winapiconstant_out_default_precis, $nclipprec = $__winapiconstant_clip_default_precis, $nquality = $__winapiconstant_default_quality, $npitch = 0, $szface = "Arial")
Local $aresult = DllCall("gdi32.dll", "handle", "CreateFontW", "int", $nheight, "int", $nwidth, "int", $nescape, "int", $norientn, "int", $fnweight, "dword", $bitalic, "dword", $bunderline, "dword", $bstrikeout, "dword", $ncharset, "dword", $noutputprec, "dword", $nclipprec, "dword", $nquality, "dword", $npitch, "wstr", $szface)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createfontindirect($tlogfont)
Local $aresult = DllCall("gdi32.dll", "handle", "CreateFontIndirectW", "ptr", DllStructGetPtr($tlogfont))
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createpen($ipenstyle, $iwidth, $ncolor)
Local $aresult = DllCall("gdi32.dll", "handle", "CreatePen", "int", $ipenstyle, "int", $iwidth, "dword", $ncolor)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createprocess($sappname, $scommand, $psecurity, $pthread, $finherit, $iflags, $penviron, $sdir, $pstartupinfo, $pprocess)
Local $pcommand = 0
Local $sappnametype = "wstr", $sdirtype = "wstr"
If $sappname = "" Then
$sappnametype = "ptr"
$sappname = 0
EndIf
If $scommand <> "" Then
Local $tcommand = DllStructCreate("wchar Text[" & 260 + 1 & "]")
$pcommand = DllStructGetPtr($tcommand)
DllStructSetData($tcommand, "Text", $scommand)
EndIf
If $sdir = "" Then
$sdirtype = "ptr"
$sdir = 0
EndIf
Local $aresult = DllCall("kernel32.dll", "bool", "CreateProcessW", $sappnametype, $sappname, "ptr", $pcommand, "ptr", $psecurity, "ptr", $pthread, "bool", $finherit, "dword", $iflags, "ptr", $penviron, $sdirtype, $sdir, "ptr", $pstartupinfo, "ptr", $pprocess)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_createrectrgn($ileftrect, $itoprect, $irightrect, $ibottomrect)
Local $aresult = DllCall("gdi32.dll", "handle", "CreateRectRgn", "int", $ileftrect, "int", $itoprect, "int", $irightrect, "int", $ibottomrect)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createroundrectrgn($ileftrect, $itoprect, $irightrect, $ibottomrect, $iwidthellipse, $iheightellipse)
Local $aresult = DllCall("gdi32.dll", "handle", "CreateRoundRectRgn", "int", $ileftrect, "int", $itoprect, "int", $irightrect, "int", $ibottomrect, "int", $iwidthellipse, "int", $iheightellipse)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createsolidbitmap($hwnd, $icolor, $iwidth, $iheight, $brgb = 1)
Local $hdc = _winapi_getdc($hwnd)
Local $hdestdc = _winapi_createcompatibledc($hdc)
Local $hbitmap = _winapi_createcompatiblebitmap($hdc, $iwidth, $iheight)
Local $hold = _winapi_selectobject($hdestdc, $hbitmap)
Local $trect = DllStructCreate($tagrect)
DllStructSetData($trect, 1, 0)
DllStructSetData($trect, 2, 0)
DllStructSetData($trect, 3, $iwidth)
DllStructSetData($trect, 4, $iheight)
If $brgb Then
$icolor = BitOR(BitAND($icolor, 65280), BitShift(BitAND($icolor, 255), -16), BitShift(BitAND($icolor, 16711680), 16))
EndIf
Local $hbrush = _winapi_createsolidbrush($icolor)
_winapi_fillrect($hdestdc, DllStructGetPtr($trect), $hbrush)
If @error Then
_winapi_deleteobject($hbitmap)
$hbitmap = 0
EndIf
_winapi_deleteobject($hbrush)
_winapi_releasedc($hwnd, $hdc)
_winapi_selectobject($hdestdc, $hold)
_winapi_deletedc($hdestdc)
If NOT $hbitmap Then Return SetError(1, 0, 0)
Return $hbitmap
EndFunc
Func _winapi_createsolidbrush($ncolor)
Local $aresult = DllCall("gdi32.dll", "handle", "CreateSolidBrush", "dword", $ncolor)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_createwindowex($iexstyle, $sclass, $sname, $istyle, $ix, $iy, $iwidth, $iheight, $hparent, $hmenu = 0, $hinstance = 0, $pparam = 0)
If $hinstance = 0 Then $hinstance = _winapi_getmodulehandle("")
Local $aresult = DllCall("user32.dll", "hwnd", "CreateWindowExW", "dword", $iexstyle, "wstr", $sclass, "wstr", $sname, "dword", $istyle, "int", $ix, "int", $iy, "int", $iwidth, "int", $iheight, "hwnd", $hparent, "handle", $hmenu, "handle", $hinstance, "ptr", $pparam)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_defwindowproc($hwnd, $imsg, $iwparam, $ilparam)
Local $aresult = DllCall("user32.dll", "lresult", "DefWindowProc", "hwnd", $hwnd, "uint", $imsg, "wparam", $iwparam, "lparam", $ilparam)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_deletedc($hdc)
Local $aresult = DllCall("gdi32.dll", "bool", "DeleteDC", "handle", $hdc)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_deleteobject($hobject)
Local $aresult = DllCall("gdi32.dll", "bool", "DeleteObject", "handle", $hobject)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_destroyicon($hicon)
Local $aresult = DllCall("user32.dll", "bool", "DestroyIcon", "handle", $hicon)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_destroywindow($hwnd)
Local $aresult = DllCall("user32.dll", "bool", "DestroyWindow", "hwnd", $hwnd)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_drawedge($hdc, $ptrrect, $nedgetype, $grfflags)
Local $aresult = DllCall("user32.dll", "bool", "DrawEdge", "handle", $hdc, "ptr", $ptrrect, "uint", $nedgetype, "uint", $grfflags)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_drawframecontrol($hdc, $ptrrect, $ntype, $nstate)
Local $aresult = DllCall("user32.dll", "bool", "DrawFrameControl", "handle", $hdc, "ptr", $ptrrect, "uint", $ntype, "uint", $nstate)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_drawicon($hdc, $ix, $iy, $hicon)
Local $aresult = DllCall("user32.dll", "bool", "DrawIcon", "handle", $hdc, "int", $ix, "int", $iy, "handle", $hicon)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_drawiconex($hdc, $ix, $iy, $hicon, $iwidth = 0, $iheight = 0, $istep = 0, $hbrush = 0, $iflags = 3)
Local $ioptions
Switch $iflags
Case 1
$ioptions = $__winapiconstant_di_mask
Case 2
$ioptions = $__winapiconstant_di_image
Case 3
$ioptions = $__winapiconstant_di_normal
Case 4
$ioptions = $__winapiconstant_di_compat
Case 5
$ioptions = $__winapiconstant_di_defaultsize
Case Else
$ioptions = $__winapiconstant_di_nomirror
EndSwitch
Local $aresult = DllCall("user32.dll", "bool", "DrawIconEx", "handle", $hdc, "int", $ix, "int", $iy, "handle", $hicon, "int", $iwidth, "int", $iheight, "uint", $istep, "handle", $hbrush, "uint", $ioptions)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_drawline($hdc, $ix1, $iy1, $ix2, $iy2)
_winapi_moveto($hdc, $ix1, $iy1)
If @error Then Return SetError(@error, @extended, False)
_winapi_lineto($hdc, $ix2, $iy2)
If @error Then Return SetError(@error, @extended, False)
Return True
EndFunc
Func _winapi_drawtext($hdc, $stext, ByRef $trect, $iflags)
Local $aresult = DllCall("user32.dll", "int", "DrawTextW", "handle", $hdc, "wstr", $stext, "int", -1, "ptr", DllStructGetPtr($trect), "uint", $iflags)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_enablewindow($hwnd, $fenable = True)
Local $aresult = DllCall("user32.dll", "bool", "EnableWindow", "hwnd", $hwnd, "bool", $fenable)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_enumdisplaydevices($sdevice, $idevnum)
Local $pname = 0, $iflags = 0, $adevice[5]
If $sdevice <> "" Then
Local $tname = DllStructCreate("wchar Text[" & StringLen($sdevice) + 1 & "]")
$pname = DllStructGetPtr($tname)
DllStructSetData($tname, "Text", $sdevice)
EndIf
Local $tdevice = DllStructCreate($tagdisplay_device)
Local $pdevice = DllStructGetPtr($tdevice)
Local $idevice = DllStructGetSize($tdevice)
DllStructSetData($tdevice, "Size", $idevice)
DllCall("user32.dll", "bool", "EnumDisplayDevicesW", "ptr", $pname, "dword", $idevnum, "ptr", $pdevice, "dword", 1)
If @error Then Return SetError(@error, @extended, 0)
Local $in = DllStructGetData($tdevice, "Flags")
If BitAND($in, $__winapiconstant_display_device_attached_to_desktop) <> 0 Then $iflags = BitOR($iflags, 1)
If BitAND($in, $__winapiconstant_display_device_primary_device) <> 0 Then $iflags = BitOR($iflags, 2)
If BitAND($in, $__winapiconstant_display_device_mirroring_driver) <> 0 Then $iflags = BitOR($iflags, 4)
If BitAND($in, $__winapiconstant_display_device_vga_compatible) <> 0 Then $iflags = BitOR($iflags, 8)
If BitAND($in, $__winapiconstant_display_device_removable) <> 0 Then $iflags = BitOR($iflags, 16)
If BitAND($in, $__winapiconstant_display_device_modespruned) <> 0 Then $iflags = BitOR($iflags, 32)
$adevice[0] = True
$adevice[1] = DllStructGetData($tdevice, "Name")
$adevice[2] = DllStructGetData($tdevice, "String")
$adevice[3] = $iflags
$adevice[4] = DllStructGetData($tdevice, "ID")
Return $adevice
EndFunc
Func _winapi_enumwindows($fvisible = True, $hwnd = Default)
__winapi_enumwindowsinit()
If $hwnd = Default Then $hwnd = _winapi_getdesktopwindow()
__winapi_enumwindowschild($hwnd, $fvisible)
Return $__gawinlist_winapi
EndFunc
Func __winapi_enumwindowsadd($hwnd, $sclass = "")
If $sclass = "" Then $sclass = _winapi_getclassname($hwnd)
$__gawinlist_winapi[0][0] += 1
Local $icount = $__gawinlist_winapi[0][0]
If $icount >= $__gawinlist_winapi[0][1] Then
ReDim $__gawinlist_winapi[$icount + 64][2]
$__gawinlist_winapi[0][1] += 64
EndIf
$__gawinlist_winapi[$icount][0] = $hwnd
$__gawinlist_winapi[$icount][1] = $sclass
EndFunc
Func __winapi_enumwindowschild($hwnd, $fvisible = True)
$hwnd = _winapi_getwindow($hwnd, $__winapiconstant_gw_child)
While $hwnd <> 0
If (NOT $fvisible) OR _winapi_iswindowvisible($hwnd) Then
__winapi_enumwindowschild($hwnd, $fvisible)
__winapi_enumwindowsadd($hwnd)
EndIf
$hwnd = _winapi_getwindow($hwnd, $__winapiconstant_gw_hwndnext)
WEnd
EndFunc
Func __winapi_enumwindowsinit()
ReDim $__gawinlist_winapi[64][2]
$__gawinlist_winapi[0][0] = 0
$__gawinlist_winapi[0][1] = 64
EndFunc
Func _winapi_enumwindowspopup()
__winapi_enumwindowsinit()
Local $hwnd = _winapi_getwindow(_winapi_getdesktopwindow(), $__winapiconstant_gw_child)
Local $sclass
While $hwnd <> 0
If _winapi_iswindowvisible($hwnd) Then
$sclass = _winapi_getclassname($hwnd)
If $sclass = "#32768" Then
__winapi_enumwindowsadd($hwnd)
ElseIf $sclass = "ToolbarWindow32" Then
__winapi_enumwindowsadd($hwnd)
ElseIf $sclass = "ToolTips_Class32" Then
__winapi_enumwindowsadd($hwnd)
ElseIf $sclass = "BaseBar" Then
__winapi_enumwindowschild($hwnd)
EndIf
EndIf
$hwnd = _winapi_getwindow($hwnd, $__winapiconstant_gw_hwndnext)
WEnd
Return $__gawinlist_winapi
EndFunc
Func _winapi_enumwindowstop()
__winapi_enumwindowsinit()
Local $hwnd = _winapi_getwindow(_winapi_getdesktopwindow(), $__winapiconstant_gw_child)
While $hwnd <> 0
If _winapi_iswindowvisible($hwnd) Then __winapi_enumwindowsadd($hwnd)
$hwnd = _winapi_getwindow($hwnd, $__winapiconstant_gw_hwndnext)
WEnd
Return $__gawinlist_winapi
EndFunc
Func _winapi_expandenvironmentstrings($sstring)
Local $aresult = DllCall("kernel32.dll", "dword", "ExpandEnvironmentStringsW", "wstr", $sstring, "wstr", "", "dword", 4096)
If @error Then Return SetError(@error, @extended, "")
Return $aresult[2]
EndFunc
Func _winapi_extracticonex($sfile, $iindex, $plarge, $psmall, $iicons)
Local $aresult = DllCall("shell32.dll", "uint", "ExtractIconExW", "wstr", $sfile, "int", $iindex, "handle", $plarge, "handle", $psmall, "uint", $iicons)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_fatalappexit($smessage)
DllCall("kernel32.dll", "none", "FatalAppExitW", "uint", 0, "wstr", $smessage)
If @error Then Return SetError(@error, @extended)
EndFunc
Func _winapi_fillrect($hdc, $ptrrect, $hbrush)
Local $aresult
If IsPtr($hbrush) Then
$aresult = DllCall("user32.dll", "int", "FillRect", "handle", $hdc, "ptr", $ptrrect, "handle", $hbrush)
Else
$aresult = DllCall("user32.dll", "int", "FillRect", "handle", $hdc, "ptr", $ptrrect, "dword", $hbrush)
EndIf
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_findexecutable($sfilename, $sdirectory = "")
Local $aresult = DllCall("shell32.dll", "INT", "FindExecutableW", "wstr", $sfilename, "wstr", $sdirectory, "wstr", "")
If @error Then Return SetError(@error, @extended, 0)
Return SetExtended($aresult[0], $aresult[3])
EndFunc
Func _winapi_findwindow($sclassname, $swindowname)
Local $aresult = DllCall("user32.dll", "hwnd", "FindWindowW", "wstr", $sclassname, "wstr", $swindowname)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_flashwindow($hwnd, $finvert = True)
Local $aresult = DllCall("user32.dll", "bool", "FlashWindow", "hwnd", $hwnd, "bool", $finvert)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_flashwindowex($hwnd, $iflags = 3, $icount = 3, $itimeout = 0)
Local $tflash = DllStructCreate($tagflashwinfo)
Local $pflash = DllStructGetPtr($tflash)
Local $iflash = DllStructGetSize($tflash)
Local $imode = 0
If BitAND($iflags, 1) <> 0 Then $imode = BitOR($imode, $__winapiconstant_flashw_caption)
If BitAND($iflags, 2) <> 0 Then $imode = BitOR($imode, $__winapiconstant_flashw_tray)
If BitAND($iflags, 4) <> 0 Then $imode = BitOR($imode, $__winapiconstant_flashw_timer)
If BitAND($iflags, 8) <> 0 Then $imode = BitOR($imode, $__winapiconstant_flashw_timernofg)
DllStructSetData($tflash, "Size", $iflash)
DllStructSetData($tflash, "hWnd", $hwnd)
DllStructSetData($tflash, "Flags", $imode)
DllStructSetData($tflash, "Count", $icount)
DllStructSetData($tflash, "Timeout", $itimeout)
Local $aresult = DllCall("user32.dll", "bool", "FlashWindowEx", "ptr", $pflash)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_floattoint($nfloat)
Local $tfloat = DllStructCreate("float")
Local $tint = DllStructCreate("int", DllStructGetPtr($tfloat))
DllStructSetData($tfloat, 1, $nfloat)
Return DllStructGetData($tint, 1)
EndFunc
Func _winapi_flushfilebuffers($hfile)
Local $aresult = DllCall("kernel32.dll", "bool", "FlushFileBuffers", "handle", $hfile)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_formatmessage($iflags, $psource, $imessageid, $ilanguageid, ByRef $pbuffer, $isize, $varguments)
Local $sbuffertype = "ptr"
If IsString($pbuffer) Then $sbuffertype = "wstr"
Local $aresult = DllCall("Kernel32.dll", "dword", "FormatMessageW", "dword", $iflags, "ptr", $psource, "dword", $imessageid, "dword", $ilanguageid, $sbuffertype, $pbuffer, "dword", $isize, "ptr", $varguments)
If @error Then Return SetError(@error, @extended, 0)
If $sbuffertype = "wstr" Then $pbuffer = $aresult[5]
Return $aresult[0]
EndFunc
Func _winapi_framerect($hdc, $ptrrect, $hbrush)
Local $aresult = DllCall("user32.dll", "int", "FrameRect", "handle", $hdc, "ptr", $ptrrect, "handle", $hbrush)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_freelibrary($hmodule)
Local $aresult = DllCall("kernel32.dll", "bool", "FreeLibrary", "handle", $hmodule)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_getancestor($hwnd, $iflags = 1)
Local $aresult = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $hwnd, "uint", $iflags)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getasynckeystate($ikey)
Local $aresult = DllCall("user32.dll", "short", "GetAsyncKeyState", "int", $ikey)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getbkmode($hdc)
Local $aresult = DllCall("gdi32.dll", "int", "GetBkMode", "handle", $hdc)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getclassname($hwnd)
If NOT IsHWnd($hwnd) Then $hwnd = GUICtrlGetHandle($hwnd)
Local $aresult = DllCall("user32.dll", "int", "GetClassNameW", "hwnd", $hwnd, "wstr", "", "int", 4096)
If @error Then Return SetError(@error, @extended, False)
Return SetExtended($aresult[0], $aresult[2])
EndFunc
Func _winapi_getclientheight($hwnd)
Local $trect = _winapi_getclientrect($hwnd)
If @error Then Return SetError(@error, @extended, 0)
Return DllStructGetData($trect, "Bottom") - DllStructGetData($trect, "Top")
EndFunc
Func _winapi_getclientwidth($hwnd)
Local $trect = _winapi_getclientrect($hwnd)
If @error Then Return SetError(@error, @extended, 0)
Return DllStructGetData($trect, "Right") - DllStructGetData($trect, "Left")
EndFunc
Func _winapi_getclientrect($hwnd)
Local $trect = DllStructCreate($tagrect)
DllCall("user32.dll", "bool", "GetClientRect", "hwnd", $hwnd, "ptr", DllStructGetPtr($trect))
If @error Then Return SetError(@error, @extended, 0)
Return $trect
EndFunc
Func _winapi_getcurrentprocess()
Local $aresult = DllCall("kernel32.dll", "handle", "GetCurrentProcess")
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getcurrentprocessid()
Local $aresult = DllCall("kernel32.dll", "dword", "GetCurrentProcessId")
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getcurrentthread()
Local $aresult = DllCall("kernel32.dll", "handle", "GetCurrentThread")
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getcurrentthreadid()
Local $aresult = DllCall("kernel32.dll", "dword", "GetCurrentThreadId")
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getcursorinfo()
Local $tcursor = DllStructCreate($tagcursorinfo)
Local $icursor = DllStructGetSize($tcursor)
DllStructSetData($tcursor, "Size", $icursor)
DllCall("user32.dll", "bool", "GetCursorInfo", "ptr", DllStructGetPtr($tcursor))
If @error Then Return SetError(@error, @extended, 0)
Local $acursor[5]
$acursor[0] = True
$acursor[1] = DllStructGetData($tcursor, "Flags") <> 0
$acursor[2] = DllStructGetData($tcursor, "hCursor")
$acursor[3] = DllStructGetData($tcursor, "X")
$acursor[4] = DllStructGetData($tcursor, "Y")
Return $acursor
EndFunc
Func _winapi_getdc($hwnd)
Local $aresult = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hwnd)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getdesktopwindow()
Local $aresult = DllCall("user32.dll", "hwnd", "GetDesktopWindow")
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getdevicecaps($hdc, $iindex)
Local $aresult = DllCall("gdi32.dll", "int", "GetDeviceCaps", "handle", $hdc, "int", $iindex)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getdibits($hdc, $hbmp, $istartscan, $iscanlines, $pbits, $pbi, $iusage)
Local $aresult = DllCall("gdi32.dll", "int", "GetDIBits", "handle", $hdc, "handle", $hbmp, "uint", $istartscan, "uint", $iscanlines, "ptr", $pbits, "ptr", $pbi, "uint", $iusage)
If @error Then Return SetError(@error, @extended, False)
Return $aresult[0]
EndFunc
Func _winapi_getdlgctrlid($hwnd)
Local $aresult = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hwnd)
If @error Then Return SetError(@error, @extended, 0)
Return $aresult[0]
EndFunc
Func _winapi_getdlgitem($hwnd, $iitemid)
Local $aresult = DllCall("user32.dll", "hwnd", "GetDlgItem", "hwnd", $hwnd, "int", $iitemid)