33
44using System . Runtime . InteropServices ;
55using Windows . Win32 . Foundation ;
6+ using Windows . Win32 . UI . WindowsAndMessaging ;
67
78namespace Windows . Win32
89{
@@ -17,4 +18,23 @@ namespace UI.WindowsAndMessaging
1718 [ UnmanagedFunctionPointer ( CallingConvention . Winapi ) ]
1819 public delegate LRESULT WNDPROC ( HWND hWnd , uint msg , WPARAM wParam , LPARAM lParam ) ;
1920 }
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+ }
2040}
0 commit comments