我一直得到“无法在DLL'user32.dll'中找到名为'GetWindowLongPtrA'的入口点”[复制]

问题描述 投票:2回答:1

我正在尝试使用GetWindowLongPtrA但我一直得到“无法在DLL'user32.dll'中找到名为'GetWindowLongPtrA'的入口点”。 (也SetWindowLongPtrA得到同样的错误)。我已尝试在Google上找到许多解决方案,但他们没有解决它。

这是我写的函数的声明:

[DllImport("user32.dll")]
public static extern IntPtr GetWindowLongPtrA(IntPtr hWnd, int nIndex);

试图把EntryPoint = "GetWindowLongPtrA",改变GetWindowLongPtrAGetWindowLongPtr,把CharSet = CharSet.Ansi,切换到与GetWindowLongPtrWCharSet = CharSet.Unicode,他们都没有工作。

我的计算机完全是“64位”(但不能调用那个64位的WinAPI函数?)。操作系统是Windows 10。

[1]: https://i.stack.imgur.com/3JrGw.png

但是我的系统驱动器的可用空间不足。这是可能的原因吗? enter image description here

这个问题的解决方案是什么?

c# .net winapi pinvoke getwindowlong
1个回答
5
投票

在32位版本的GetWindowLongPtr中没有名为GetWindowLongPtrAGetWindowLongPtrWuser32.dll的函数:

32-bit user32.dll

无论目标位数如何使用GetWindowLongPtr工作C和C ++ WinAPI代码的原因是在32位代码中它是一个调用GetWindowLong(A|W)的宏。它只存在于64位版本的user32.dll中:

64-bit user32.dll

GetWindowLongPtr上导入pinvoke.net的文档包含一个代码示例,用于说明如何使此导入对目标位数透明(请记住,当您实际尝试调用不存在的导入函数时,不会在DllImport行上调用错误):

[DllImport("user32.dll", EntryPoint="GetWindowLong")]
private static extern IntPtr GetWindowLongPtr32(IntPtr hWnd, int nIndex);

[DllImport("user32.dll", EntryPoint="GetWindowLongPtr")]
private static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);

// This static method is required because Win32 does not support
// GetWindowLongPtr directly
public static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex)
{
     if (IntPtr.Size == 8)
     return GetWindowLongPtr64(hWnd, nIndex);
     else
     return GetWindowLongPtr32(hWnd, nIndex);
}
© www.soinside.com 2019 - 2024. All rights reserved.