3
3
4
4
using System . Runtime . InteropServices ;
5
5
using Windows . Win32 . Foundation ;
6
+ using Windows . Win32 . UI . WindowsAndMessaging ;
6
7
7
8
namespace Windows . Win32
8
9
{
@@ -17,4 +18,23 @@ namespace UI.WindowsAndMessaging
17
18
[ UnmanagedFunctionPointer ( CallingConvention . Winapi ) ]
18
19
public delegate LRESULT WNDPROC ( HWND hWnd , uint msg , WPARAM wParam , LPARAM lParam ) ;
19
20
}
21
+
22
+ public static partial class PInvoke
23
+ {
24
+ [ DllImport ( "User32" , EntryPoint = "SetWindowLongW" , ExactSpelling = true ) ]
25
+ static extern int _SetWindowLong ( HWND hWnd , int nIndex , int dwNewLong ) ;
26
+
27
+ [ DllImport ( "User32" , EntryPoint = "SetWindowLongPtrW" , ExactSpelling = true ) ]
28
+ static extern nint _SetWindowLongPtr ( HWND hWnd , int nIndex , nint dwNewLong ) ;
29
+
30
+ // NOTE:
31
+ // CsWin32 doesn't generate SetWindowLong on other than x86 and vice versa.
32
+ // For more info, visit https://github.com/microsoft/CsWin32/issues/882
33
+ public static unsafe nint SetWindowLongPtr ( HWND hWnd , WINDOW_LONG_PTR_INDEX nIndex , nint dwNewLong )
34
+ {
35
+ return sizeof ( nint ) is 4
36
+ ? ( nint ) _SetWindowLong ( hWnd , ( int ) nIndex , ( int ) dwNewLong )
37
+ : _SetWindowLongPtr ( hWnd , ( int ) nIndex , dwNewLong ) ;
38
+ }
39
+ }
20
40
}
0 commit comments