我正在尝试使用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位版本的user32.dll
中没有名为GetWindowLongPtr
、GetWindowLongPtrA
或GetWindowLongPtrW
的函数>:
无论目标位数如何,使用 GetWindowLongPtr
都适用于 C 和 C++ WinAPI 代码的原因是,在 32 位代码中,它是一个调用 GetWindowLong(A|W)
的宏。它仅存在于64位版本的user32.dll
中:
在 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);
}
关于c# - 我不断在 DLL "Unable to find an entry point named ' 中收到 'user32.dll' GetWindowLongPtrA' ”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54833997/