1
- // Licensed to the .NET Foundation under one or more agreements.
1
+ // Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System . Runtime . InteropServices ;
@@ -13,9 +13,23 @@ public struct GlfwNativeWindow : INativeWindow
13
13
[ DllImport ( "user32" , EntryPoint = "GetDC" ) ]
14
14
private static extern nint Win32GetDC ( nint hwnd ) ;
15
15
16
- [ DllImport ( "user32" , EntryPoint = "GetWindowLongPtrA" ) ]
17
- private static extern nint Win32GetWindowLongPtr ( nint hwnd , int index ) ;
18
-
16
+
17
+ [ DllImport ( "user32.dll" , EntryPoint = "GetWindowLong" ) ]
18
+ private static extern nint GetWindowLongPtr32 ( nint hWnd , int nIndex ) ;
19
+
20
+ [ DllImport ( "user32.dll" , EntryPoint = "GetWindowLongPtr" ) ]
21
+ private static extern nint GetWindowLongPtr64 ( nint hWnd , int nIndex ) ;
22
+
23
+ // This static method is required because Win32 does not support
24
+ // GetWindowLongPtr directly
25
+ private static unsafe nint GetWindowLongPtr ( nint hWnd , int nIndex )
26
+ {
27
+ if ( sizeof ( nint ) == 8 )
28
+ return GetWindowLongPtr64 ( hWnd , nIndex ) ;
29
+ else
30
+ return GetWindowLongPtr32 ( hWnd , nIndex ) ;
31
+ }
32
+
19
33
public unsafe GlfwNativeWindow ( Glfw api , WindowHandle * window ) : this ( )
20
34
{
21
35
Kind |= NativeWindowFlags . Glfw ;
@@ -24,7 +38,7 @@ public unsafe GlfwNativeWindow(Glfw api, WindowHandle* window) : this()
24
38
{
25
39
var hwnd = ( ( delegate * unmanaged[ Cdecl] < WindowHandle * , nint > ) getHwnd ) ( window ) ;
26
40
Kind |= NativeWindowFlags . Win32 ;
27
- Win32 = ( hwnd , Win32GetDC ( hwnd ) , Win32GetWindowLongPtr ( hwnd , GwlpHInstance ) ) ;
41
+ Win32 = ( hwnd , Win32GetDC ( hwnd ) , GetWindowLongPtr ( hwnd , GwlpHInstance ) ) ;
28
42
return ;
29
43
}
30
44
0 commit comments