我不断收到 "Unable to find an entry point named 'GetWindowLongPtrA' in DLL 'user32.dll'"

I keep getting "Unable to find an entry point named 'GetWindowLongPtrA' in DLL 'user32.dll'"

我正在尝试使用 GetWindowLongPtrA,但我一直收到 "Unable to find an entry point named 'GetWindowLongPtrA' in DLL 'user32.dll'"。 (也 SetWindowLongPtrA 得到同样的错误)。我尝试了很多在 Google 上找到的解决方案,但他们没有解决。

这是我写的函数的声明:

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

尝试将 EntryPoint = "GetWindowLongPtrA"、将 GetWindowLongPtrA 更改为 GetWindowLongPtr、将 CharSet = CharSet.Ansi、切换为 GetWindowLongPtrWCharSet = CharSet.Unicode 等,他们都没有用。

我的电脑正好是“64 位”(但不能调用那个 64 位 WinAPI 函数?)。 OS 是 Windows 10.

但是我的系统驱动器 运行 已用完 space。这是一个可能的原因吗?

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

user32.dll 的 32 位版本中没有名为 GetWindowLongPtrGetWindowLongPtrAGetWindowLongPtrW 的函数:

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

pinvoke.net 上关于导入 GetWindowLongPtr 的文档包含一个代码示例,说明如何使此导入对目标位数透明(请记住,当您实际尝试调用导入函数时会抛出错误不存在,不在 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);
}