3

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

这是我编写的函数的声明:

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

尝试了 put EntryPoint = "GetWindowLongPtrA", change GetWindowLongPtrAto GetWindowLongPtr, put CharSet = CharSet.Ansi,switch to GetWindowLongPtrWwithCharSet = CharSet.Unicode等等,都没有用。

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

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

但是我的系统驱动器的可用空间不足。这是一个可能的原因吗? 在此处输入图像描述

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

4

1 回答 1

6

没有名为 的函数GetWindowLongPtrGetWindowLongPtrA或者GetWindowLongPtrW在 32 位版本中user32.dll

32 位 user32.dll

使用不GetWindowLongPtr考虑目标位数的 C 和 C++ WinAPI 代码的原因是,在 32 位代码中,它是一个调用GetWindowLong(A|W). 它仅存在于 64 位版本中user32.dll

64 位 user32.dll

pinvoke.netGetWindowLongPtr上的导入文档包含一个代码示例,说明如何使此导入对目标位数透明(请记住,当您实际尝试调用不存在的导入函数时会引发错误,而不是在线):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);
}
于 2019-02-22T20:23:01.387 回答