-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNativeMethods.cs
More file actions
1837 lines (1520 loc) · 70.8 KB
/
Copy pathNativeMethods.cs
File metadata and controls
1837 lines (1520 loc) · 70.8 KB
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
/////////////////////////////////////////////////////////////////////////////////
// paint.net //
// Copyright (C) dotPDN LLC, Rick Brewster, and contributors. //
// All Rights Reserved. //
/////////////////////////////////////////////////////////////////////////////////
using Microsoft.Win32.SafeHandles;
using System;
using System.ComponentModel;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
namespace PaintDotNet.SystemLayer
{
[SuppressUnmanagedCodeSecurity]
internal static class NativeMethods
{
public static bool SUCCEEDED(int hr)
{
return hr >= 0;
}
public static bool FAILED(int hr)
{
return hr < 0;
}
public static short LOWORD(IntPtr value)
{
return unchecked((short)((long)value & 0xffff));
}
public static short HIWORD(IntPtr value)
{
return unchecked((short)((long)value >> 16));
}
public static short GET_KEYSTATE_WPARAM(IntPtr wParam)
{
return LOWORD(wParam);
}
public static short GET_WHEEL_DELTA_WPARAM(IntPtr wParam)
{
return HIWORD(wParam);
}
public static IntPtr MAKEINTRESOURCEW(int i)
{
ushort w = unchecked((ushort)i);
IntPtr ip = (IntPtr)w;
return ip;
}
public static int GET_X_LPARAM(IntPtr lParam)
{
return (int)LOWORD(lParam);
}
public static int GET_Y_LPARAM(IntPtr lParam)
{
return (int)HIWORD(lParam);
}
[DllImport("kernel32.dll", SetLastError = false)]
public static extern void SetLastError(uint dwErrCode);
public static void SetLastError(NativeErrors dwErrCode)
{
SetLastError((uint)dwErrCode);
}
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr LoadLibraryW(
[MarshalAs(UnmanagedType.LPWStr)]
string lpFileName);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static extern bool FreeLibrary(
IntPtr hModule);
[DllImport("psapi.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static unsafe extern bool EnumProcessModules(
IntPtr hProcess,
IntPtr* lphModule,
uint cb,
out uint lpcbNeeded);
[DllImport("psapi.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static unsafe extern bool EnumProcessModulesEx(
IntPtr hProcess,
IntPtr* lphModule,
uint cb,
out uint lpcbNeeded,
uint dwFilterFlag);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr GetModuleHandleW(
[MarshalAs(UnmanagedType.LPWStr)]
string lpModuleName);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern uint GetModuleFileNameW(
IntPtr hModule,
IntPtr lpFilename,
uint nSize);
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetGuiResources(
IntPtr hProcess,
uint uiFlags);
[DllImport("gdi32.dll", SetLastError = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GdiFlush();
/*
[DllImport("comctl32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
public static extern void TaskDialog(
IntPtr hWndParent,
IntPtr hInstance,
[In] string pszWindowTitle,
[In] string pszMainInstruction,
[In] string pszContent,
uint dwCommonButtons,
IntPtr pszIcon,
out int pnButton);
*/
[DllImport("comctl32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
public static unsafe extern void TaskDialogIndirect(
ref NativeStructs.TASKDIALOGCONFIG pTaskConfig,
int* pnButton,
int* pnRadioButton,
int* pfVerificationFlagChecked);
[DllImport("user32.dll", SetLastError = false)]
public static extern uint GetMessageTime();
[DllImport("user32.dll", SetLastError = true)]
public static extern unsafe int GetMouseMovePointsEx(
int cbSize,
ref NativeStructs.MOUSEMOVEPOINT lppt,
NativeStructs.MOUSEMOVEPOINT* lpptBuf,
int nBufPoints,
uint resolution);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool LookupPrivilegeValueW(
[In] [MarshalAs(UnmanagedType.LPWStr)] string lpSystemName,
[In] [MarshalAs(UnmanagedType.LPWStr)] string lpName,
out NativeStructs.LUID lpLuid);
[DllImport("advapi32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AdjustTokenPrivileges(
IntPtr tokenHandle,
[MarshalAs(UnmanagedType.Bool)] bool disableAllPrivileges,
ref NativeStructs.TOKEN_PRIVILEGES NewState,
uint BufferLength,
out NativeStructs.TOKEN_PRIVILEGES PreviousState,
out uint ReturnLength);
[DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
public static extern void SHGetFolderPathW(
IntPtr hwndOwner,
int nFolder,
IntPtr hToken,
uint dwFlags,
StringBuilder lpszPath);
[DllImport("shell32.dll", PreserveSig = true)]
public static extern int SHOpenFolderAndSelectItems(
IntPtr pidlFolder,
uint cidl,
IntPtr apidl,
uint dwFlags);
[DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = true)]
public static extern IntPtr ILCreateFromPathW(
[MarshalAs(UnmanagedType.LPWStr)] string pszPath);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteFileW(
[In] [MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool RemoveDirectoryW(
[In] [MarshalAs(UnmanagedType.LPWStr)] string lpPathName);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr DefWindowProc(
IntPtr hWnd,
int Msg,
IntPtr wParam,
IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetWindow(
IntPtr hWnd,
uint uCmd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumThreadWindows(
uint dwThreadId,
[MarshalAs(UnmanagedType.FunctionPtr)] NativeDelegates.EnumThreadWndProc lpEnumFunc,
IntPtr lParam);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr OpenProcess(
uint dwDesiredAccess,
[MarshalAs(UnmanagedType.Bool)] bool bInheritHandle,
uint dwProcessId);
[DllImport("advapi32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool OpenProcessToken(
IntPtr ProcessHandle,
uint DesiredAccess,
out IntPtr TokenHandle);
[DllImport("advapi32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DuplicateTokenEx(
IntPtr hExistingToken,
uint dwDesiredAccess,
IntPtr lpTokenAttributes,
NativeConstants.SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
NativeConstants.TOKEN_TYPE TokenType,
out IntPtr phNewToken);
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CreateProcessWithTokenW(
IntPtr hToken,
uint dwLogonFlags,
IntPtr lpApplicationName,
IntPtr lpCommandLine,
uint dwCreationFlags,
IntPtr lpEnvironment,
IntPtr lpCurrentDirectory,
IntPtr lpStartupInfo,
out NativeStructs.PROCESS_INFORMATION lpProcessInfo);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint RegisterClipboardFormatW(
[In] [MarshalAs(UnmanagedType.LPWStr)] string lpszFormat);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetClipboardData(
uint uFormat,
IntPtr hMem);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EmptyClipboard();
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseClipboard();
[DllImport("user32.dll", SetLastError = true)]
public static extern uint EnumClipboardFormats(uint format);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetClipboardData(uint format);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static unsafe extern int GetClipboardFormatNameW(
uint format,
char* lpszFormatName,
int cchMaxCount);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsClipboardFormatAvailable(uint format);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool VerifyVersionInfo(
ref NativeStructs.OSVERSIONINFOEX lpVersionInfo,
uint dwTypeMask,
ulong dwlConditionMask);
[DllImport("kernel32.dll")]
public static extern ulong VerSetConditionMask(
ulong dwlConditionMask,
uint dwTypeBitMask,
byte dwConditionMask);
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetProductInfo(
uint dwOSMajorVersion,
uint dwOSMinorVersion,
uint dwSpMajorVersion,
uint dwSpMinorVersion,
out uint pdwReturnedProductType);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeviceIoControl(
IntPtr hDevice,
uint dwIoControlCode,
IntPtr lpInBuffer,
uint nInBufferSize,
IntPtr lpOutBuffer,
uint nOutBufferSize,
ref uint lpBytesReturned,
IntPtr lpOverlapped);
[DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ShellExecuteExW(ref NativeStructs.SHELLEXECUTEINFO lpExecInfo);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GlobalMemoryStatusEx(ref NativeStructs.MEMORYSTATUSEX lpBuffer);
[DllImport("shell32.dll", SetLastError = false)]
public static extern void SHAddToRecentDocs(uint uFlags, IntPtr pv);
[DllImport("Wintrust.dll", PreserveSig = true, SetLastError = false)]
public static extern unsafe int WinVerifyTrust(
IntPtr hWnd,
ref Guid pgActionID,
ref NativeStructs.WINTRUST_DATA pWinTrustData);
[DllImport("SetupApi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr SetupDiGetClassDevsW(
ref Guid ClassGuid,
[In] [MarshalAs(UnmanagedType.LPWStr)] string Enumerator,
IntPtr hwndParent,
uint Flags);
[DllImport("SetupApi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetupDiDestroyDeviceInfoList(IntPtr DeviceInfoSet);
[DllImport("SetupApi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetupDiEnumDeviceInfo(
IntPtr DeviceInfoSet,
uint MemberIndex,
ref NativeStructs.SP_DEVINFO_DATA DeviceInfoData);
[DllImport("SetupApi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetupDiGetDeviceInstanceIdW(
IntPtr DeviceInfoSet,
ref NativeStructs.SP_DEVINFO_DATA DeviceInfoData,
IntPtr DeviceInstanceId,
uint DeviceInstanceIdSize,
out uint RequiredSize);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hwnd, ref NativeStructs.RECT lpRect);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(
IntPtr hWnd,
IntPtr hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
uint uFlags);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetComboBoxInfo(
IntPtr hwndCombo,
ref NativeStructs.COMBOBOXINFO pcbi);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr WindowFromPoint(NativeStructs.POINT Point);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr ChildWindowFromPoint(
IntPtr hWndParent,
NativeStructs.POINT Point);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr WindowFromDC(IntPtr hdc);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr GetAncestor(IntPtr hwnd, uint gaFlags);
[DllImport("user32.dll", SetLastError = false)]
public static extern int GetWindowPlacement(
IntPtr hWnd,
ref NativeStructs.WINDOWPLACEMENT lpwndpl);
[DllImport("user32.dll", SetLastError = true)]
public static extern uint TrackPopupMenuEx(
IntPtr hmenu,
uint fuFlags,
int x,
int y,
IntPtr hwnd,
IntPtr lptpm); // TPMPARAMS
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool TrackMouseEvent(
ref NativeStructs.TRACKMOUSEEVENT lpEventTrack);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DrawMenuBar(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DrawCaption(
IntPtr hwnd,
IntPtr hdc,
ref NativeStructs.RECT lprc,
uint uFlags);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr GetSystemMenu(
IntPtr hWnd,
[MarshalAs(UnmanagedType.Bool)] bool bRevert);
[DllImport("user32.dll", SetLastError = false)]
public static extern int EnableMenuItem(
IntPtr hMenu,
uint uIDEnableItem,
uint uEnable);
[DllImport("user32.dll", SetLastError = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnableWindow(
IntPtr hWnd,
[MarshalAs(UnmanagedType.Bool)] bool bEnable);
[DllImport("user32.dll", SetLastError = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FlashWindow(
IntPtr hWnd,
[MarshalAs(UnmanagedType.Bool)] bool bInvert);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr SetCursor(IntPtr hCursor);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DestroyCursor(IntPtr hCursor);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr LoadCursorW(IntPtr hInstance, IntPtr lpCursorName);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr LoadIconW(IntPtr hInstance, IntPtr lpIconName);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr LoadImageW(
IntPtr hinst,
IntPtr lpszName,
uint uType,
int cxDesired,
int cyDestired,
uint fuLoad);
[DllImport("dwmapi.dll")]
public unsafe static extern int DwmGetWindowAttribute(
IntPtr hwnd,
uint dwAttribute,
void* pvAttribute,
uint cbAttribute);
[DllImport("dwmapi.dll")]
public unsafe static extern int DwmSetWindowAttribute(
IntPtr hwnd,
uint dwAttribute,
void* pvAttribute,
uint cbAttribute);
[DllImport("kernel32.dll", SetLastError = false)]
public static extern uint GetCurrentThreadId();
[DllImport("kernel32.dll", SetLastError = false)]
public static extern IntPtr GetCurrentThread();
[DllImport("kernel32.dll", SetLastError = false)]
public static extern uint GetCurrentProcessId();
[DllImport("kernel32.dll", SetLastError = false)]
public static extern IntPtr GetCurrentProcess();
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetThreadPriority(
IntPtr hThread,
int nPriority);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr CreateFileMappingW(
IntPtr hFile,
IntPtr lpFileMappingAttributes,
uint flProtect,
uint dwMaximumSizeHigh,
uint dwMaximumSizeLow,
[MarshalAs(UnmanagedType.LPTStr)] string lpName);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr OpenFileMappingW(
uint dwDesiredAccess,
[MarshalAs(UnmanagedType.Bool)] bool bInheritHandle,
[MarshalAs(UnmanagedType.LPTStr)] string lpName);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr MapViewOfFile(
IntPtr hFileMappingObject,
uint dwDesiredAccess,
uint dwFileOffsetHigh,
uint dwFileOffsetLow,
UIntPtr dwNumberOfBytesToMap);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ShowScrollBar(
IntPtr hWnd,
int wBar,
[MarshalAs(UnmanagedType.Bool)] bool bShow);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetVersionEx(ref NativeStructs.OSVERSIONINFOEX lpVersionInfo);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetLayeredWindowAttributes(
IntPtr hwnd,
out uint pcrKey,
out byte pbAlpha,
out uint pdwFlags);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetLayeredWindowAttributes(
IntPtr hwnd,
uint crKey,
byte bAlpha,
uint dwFlags);
[DllImport("gdi32.dll", SetLastError = false)]
public static extern int SetGraphicsMode(
IntPtr hdc,
int iMode);
[DllImport("gdi32.dll", CharSet = CharSet.Unicode, SetLastError = false)]
public static extern int EnumFontFamiliesExW(
IntPtr hdc,
ref NativeStructs.LOGFONTW lpLogFont,
[MarshalAs(UnmanagedType.FunctionPtr)] NativeDelegates.EnumFontFamExProcW lpEnumFontFamExProc,
IntPtr lParam,
uint dwFlags);
[DllImport("gdi32.dll", CharSet = CharSet.Unicode, SetLastError = false)]
public static extern IntPtr CreateFontIndirectW(
ref NativeStructs.LOGFONTW lplf);
[DllImport("gdi32.dll", SetLastError = false)]
public static extern uint GetFontLanguageInfo(IntPtr hdc);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = false)]
public static extern int DrawTextW(
IntPtr hdc,
string lpString,
int nCount,
ref NativeStructs.RECT lpRect,
uint uFormat);
[DllImport("gdi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetTextMetricsW(
IntPtr hdc,
out NativeStructs.TEXTMETRICW lptm);
[DllImport("gdi32.dll", CharSet = CharSet.Unicode)]
public static extern uint GetOutlineTextMetricsW(
IntPtr hdc,
uint cbData,
IntPtr lpOTM);
[DllImport("gdi32.dll", SetLastError = false)]
public static extern uint SetTextAlign(IntPtr hdc, uint fMode);
[DllImport("gdi32.dll", SetLastError = false)]
public static extern uint SetTextColor(IntPtr hdc, uint crColor);
[DllImport("gdi32.dll", SetLastError = false)]
public static extern uint SetBkColor(IntPtr hdc, uint crColor);
[DllImport("gdi32.dll", SetLastError = false)]
public static extern int SetBkMode(IntPtr hdc, int iBkMode);
[DllImport("user32.dll", SetLastError = true)]
public static extern SafeIconHandle CreateIconIndirect(ref NativeStructs.ICONINFO piconInfo);
[DllImport("user32.dll", EntryPoint = "CreateIconIndirect", SetLastError = true)]
public static extern SafeCursorHandle CreateCursorIndirect(ref NativeStructs.ICONINFO piconInfo);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetIconInfo(
SafeIconHandle hIcon,
out NativeStructs.ICONINFO piconinfo);
[DllImport("gdi32.dll", SetLastError = true)]
public static extern IntPtr CreateDIBSection(
IntPtr hdc,
ref NativeStructs.BITMAPINFO pbmi,
uint iUsage,
out IntPtr ppvBits,
IntPtr hSection,
uint dwOffset);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr CreateFileW(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public unsafe static extern bool WriteFile(
IntPtr hFile,
void* lpBuffer,
uint nNumberOfBytesToWrite,
out uint lpNumberOfBytesWritten,
IntPtr lpOverlapped);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public unsafe static extern bool WriteFile(
SafeFileHandle hFile,
void* lpBuffer,
uint nNumberOfBytesToWrite,
out uint lpNumberOfBytesWritten,
IntPtr lpOverlapped);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public unsafe static extern bool ReadFile(
SafeFileHandle sfhFile,
void* lpBuffer,
uint nNumberOfBytesToRead,
out uint lpNumberOfBytesRead,
IntPtr lpOverlapped);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ReplaceFileW(
[MarshalAs(UnmanagedType.LPWStr)] string lpReplacedFileName,
[MarshalAs(UnmanagedType.LPWStr)] string lpReplacementFileName,
[MarshalAs(UnmanagedType.LPWStr)] string lpBackupFileName,
uint dwReplaceFlags,
IntPtr lpExclude,
IntPtr lpReserved);
[DllImport("kernel32.dll", SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetHandleInformation(
IntPtr hObject,
uint dwMask,
uint dwFlags);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr BeginPaint(
IntPtr hwnd,
ref NativeStructs.PAINTSTRUCT lpPaint);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EndPaint(
IntPtr hwnd,
ref NativeStructs.PAINTSTRUCT lpPaint);
[DllImport("user32.dll", SetLastError = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static unsafe extern bool GetUpdateRect(
IntPtr hWnd,
NativeStructs.RECT* lpRect,
[MarshalAs(UnmanagedType.Bool)] bool bErase);
[DllImport("user32.dll", SetLastError = false)]
public static extern int GetUpdateRgn(
IntPtr hWnd,
IntPtr hRgn,
[MarshalAs(UnmanagedType.Bool)] bool bErase);
[DllImport("user32.dll", SetLastError = false)]
public static extern uint GetWindowThreadProcessId(
IntPtr hWnd,
out uint lpdwProcessId);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr GetShellWindow();
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr FindWindowW(
[In] [MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
[In] [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName);
[DllImport("user32.dll", SetLastError = false)]
public static extern ushort GetAsyncKeyState(int nVirtKey);
[DllImport("user32.dll", SetLastError = false)]
public static extern ushort GetKeyState(int nVirtKey);
[DllImport("user32.dll", SetLastError = false)]
public static extern uint GetInputState();
[DllImport("user32.dll", SetLastError = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PeekMessageW(
out NativeStructs.MSG lpMsg,
IntPtr hWnd,
uint wMsgFilterMin,
uint wMsgFilterMax,
uint wRemoveMsg);
[DllImport("user32.dll", SetLastError = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool TranslateMessage(
ref NativeStructs.MSG lpMsg);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr DispatchMessageW(
ref NativeStructs.MSG lpMsg);
[DllImport("user32.dll", SetLastError = false)]
public static extern void PostQuitMessage(int nExitCode);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr SendMessageW(
IntPtr hWnd,
uint msg,
IntPtr wParam,
IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal extern static bool PostMessageW(
IntPtr handle,
uint msg,
IntPtr wParam,
IntPtr lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "SetWindowLongW")]
public static extern uint SetClassLongW_x86(
IntPtr hWnd,
int nIndex,
uint dwNewLong);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "SetWindowLongPtrW")]
public static extern UIntPtr SetClassLongPtrW_x64(
IntPtr hWnd,
int nIndex,
UIntPtr dwNewLong);
public static UIntPtr SetClassLongPtrW(IntPtr hWnd, int nIndex, UIntPtr dwNewLong)
{
NativeMethods.SetLastError(NativeErrors.ERROR_SUCCESS);
if (Processor.Architecture == ProcessorArchitecture.X64)
{
return SetClassLongPtrW_x64(hWnd, nIndex, dwNewLong);
}
else
{
return (UIntPtr)SetClassLongW_x86(hWnd, nIndex, unchecked((uint)dwNewLong.ToUInt32()));
}
}
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetWindowLongW")]
public static extern uint GetWindowLongW_x86(
IntPtr hWnd,
int nIndex);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetWindowLongPtrW")]
public static extern UIntPtr GetWindowLongPtrW_x64(
IntPtr hWnd,
int nIndex);
public static UIntPtr GetWindowLongPtrW(IntPtr hWnd, int nIndex)
{
if (Processor.Architecture == ProcessorArchitecture.X64)
{
return GetWindowLongPtrW_x64(hWnd, nIndex);
}
else
{
return (UIntPtr)GetWindowLongW_x86(hWnd, nIndex);
}
}
[DllImport("user32.dll", SetLastError = true, EntryPoint = "SetWindowLongW")]
public static extern uint SetWindowLongW_x86(
IntPtr hWnd,
int nIndex,
uint dwNewLong);
[DllImport("user32.dll", SetLastError = true, EntryPoint = "SetWindowLongPtrW")]
public static extern IntPtr SetWindowLongPtrW_x64(
IntPtr hWnd,
int nIndex,
UIntPtr dwNewLong);
public static IntPtr SetWindowLongPtrW(IntPtr hWnd, int nIndex, UIntPtr dwNewLong)
{
NativeMethods.SetLastError(NativeErrors.ERROR_SUCCESS);
if (Processor.Architecture == ProcessorArchitecture.X64)
{
return SetWindowLongPtrW_x64(hWnd, nIndex, dwNewLong);
}
else
{
return (IntPtr)SetWindowLongW_x86(hWnd, nIndex, unchecked((uint)dwNewLong.ToUInt32()));
}
}
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool QueryPerformanceCounter(out ulong lpPerformanceCount);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool QueryPerformanceFrequency(out ulong lpFrequency);
[DllImport("user32.dll", SetLastError = false)]
public static extern int GetSystemMetrics(int nIndex);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern uint WaitForSingleObject(
IntPtr hHandle,
uint dwMilliseconds);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern uint WaitForMultipleObjects(
uint nCount,
IntPtr[] lpHandles,
[MarshalAs(UnmanagedType.Bool)] bool bWaitAll,
uint dwMilliseconds);
public static uint WaitForMultipleObjects(IntPtr[] lpHandles, bool bWaitAll, uint dwMilliseconds)
{
return WaitForMultipleObjects((uint)lpHandles.Length, lpHandles, bWaitAll, dwMilliseconds);
}
[DllImport("gdi32.dll", SetLastError = true)]
internal unsafe static extern uint GetRegionData(
IntPtr hRgn,
uint dwCount,
NativeStructs.RGNDATA* lpRgnData);
[DllImport("gdi32.dll", SetLastError = false)]
public static extern int SelectClipRgn(
IntPtr hdc,
IntPtr hrgn);
[DllImport("gdi32.dll", SetLastError = false)]
public unsafe static extern IntPtr CreateRectRgnIndirect(NativeStructs.RECT* lprc);
[DllImport("gdi32.dll", SetLastError = false)]
internal unsafe static extern IntPtr CreateRectRgn(
int nLeftRect,
int nTopRect,
int nRightRect,
int nBottomRect);
[DllImport("gdi32.dll", SetLastError = false)]
public static extern int IntersectClipRect(
IntPtr hdc,
int nLeftRect,
int nTopRect,
int nRightRect,
int nBottomRect);
[DllImport("user32.dll", SetLastError = true)]
internal extern static int FillRect(
IntPtr hDC,
ref NativeStructs.RECT lprc,
IntPtr hbr);
[DllImport("gdi32.dll", SetLastError = true)]
internal extern static IntPtr CreateSolidBrush(uint crColor);
[DllImport("gdi32.dll", SetLastError = false)]
internal extern static IntPtr SelectObject(
IntPtr hdc,
IntPtr hgdiobj);
[DllImport("gdi32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DeleteObject(IntPtr hObject);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DestroyIcon(IntPtr hIcon);
[DllImport("gdi32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DeleteDC(IntPtr hdc);
[DllImport("user32.dll", SetLastError = false)]
internal static extern int ReleaseDC(
IntPtr hWnd,
IntPtr hDC);
[DllImport("gdi32.dll", SetLastError = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool BeginPath(IntPtr hdc);
[DllImport("gdi32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EndPath(IntPtr hdc);
[DllImport("gdi32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FlattenPath(IntPtr hdc);
[DllImport("gdi32.dll", SetLastError = true)]
public static unsafe extern int GetPath(
IntPtr hdc,
NativeStructs.POINT* lpPoints,
byte* lpTypes,
int nSize);
[DllImport("gdi32.dll", SetLastError = false)]
public static extern int GetClipRgn(IntPtr hdc, IntPtr hrgn);
[DllImport("gdi32.dll", SetLastError = true)]
internal extern static IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll", SetLastError = false)]
public static extern IntPtr CreateCompatibleBitmap(
IntPtr hdc,
int nWidth,
int nHeight);
[DllImport("gdi32.dll", SetLastError = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool OffsetViewportOrgEx(
IntPtr hdc,
int nXOffset,
int nYOffset,
out NativeStructs.POINT lpPoint);
[DllImport("msimg32.dll", SetLastError = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AlphaBlend(
IntPtr hdcDest,
int xoriginDest,
int yoriginDest,
int wDest,
int hDest,
IntPtr hdcSrc,
int xoriginSrc,