c# - 我不断在 DLL "Unable to find an entry point named ' 中收到 'user32.dll' GetWindowLongPtrA' ”

标签 c# .net winapi pinvoke getwindowlong

我正在尝试使用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]: /image/3JrGw.png

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

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

最佳答案

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

32-bit user32.dll

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

64-bit 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/

相关文章:

c# - 具有重复键和值的 .NET 集合?

c# - 同一应用程序中的多个静态变量范围?

c# - 在透明 WPF 窗口后面模糊

c# - 负向后视的小数或整数

c# - 161803398 是一个 'Special' 的数字吗? Math.Random() 内部

c# - 为什么 Fluent 的 NHibernate 的 AutoMapping 会忽略枚举类型?

.net - 将选项卡控件向右对齐

c# - 从另一个 Action 返回一个 Action 不起作用?

c++ - 为什么我在递归删除目录时遇到问题?

delphi - 使用 WinAPI 将击键发送到另一个应用程序