我正在尝试使用GetWindowLongPtrA
但我一直得到“无法在DLL'user32.dll'中找到名为'GetWindowLongPtrA'的入口点”。 (也SetWindowLongPtrA
得到同样的错误)。我已尝试在Google上找到许多解决方案,但他们没有解决它。
这是我写的函数的声明:
[DllImport("user32.dll")]
public static extern IntPtr GetWindowLongPtrA(IntPtr hWnd, int nIndex);
试图把EntryPoint = "GetWindowLongPtrA"
,改变GetWindowLongPtrA
到GetWindowLongPtr
,把CharSet = CharSet.Ansi
,切换到与GetWindowLongPtrW
等CharSet = CharSet.Unicode
,他们都没有工作。
我的计算机完全是“64位”(但不能调用那个64位的WinAPI函数?)。操作系统是Windows 10。
这个问题的解决方案是什么?
在32位版本的GetWindowLongPtr
中没有名为GetWindowLongPtrA
,GetWindowLongPtrW
或user32.dll
的函数:
无论目标位数如何使用GetWindowLongPtr
工作C和C ++ WinAPI代码的原因是在32位代码中它是一个调用GetWindowLong(A|W)
的宏。它只存在于64位版本的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);
}