我不断收到“无法在'user32.dll'动态链接库中找到名为'GetWindowLongPtrA'的入口点”错误提示。

3

我尝试使用GetWindowLongPtrA,但我一直收到“在DLL'user32.dll'中无法找到名为'GetWindowLongPtrA'的入口点”的错误消息。(同样的SetWindowLongPtrA也出现了同样的错误)。我已经尝试了很多在Google上找到的解决方案,但它们没有解决问题。

下面是我编写的函数声明:

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

尝试将EntryPoint = "GetWindowLongPtrA"更改为GetWindowLongPtr,使用CharSet = CharSet.Ansi,切换到GetWindowLongPtrW并使用CharSet = CharSet.Unicode等方法,但都没有奏效。我的电脑确实是“64位”(但无法调用该64位WinAPI函数?),操作系统是Windows 10。

[1]: https://istack.dev59.com/3JrGw.webp

但是我的系统驱动器可用空间不足,这是可能的原因吗? 在此输入图片描述 这个问题的解决方案是什么?

2
函数不是叫做GetWindowLongPtr吗?我认为如果你的目标是32位进程,那么应该调用GetWindowLong。 - David Heffernan
2
我的电脑是“64位”的 - 但我猜你的处理器是32位的。只有进程的位数在这里起作用。 - RbMm
好的,我只是将构建目标更改为64位,然后就可以了。真的非常感谢 :) - armamoyl
1
空间不足可能导致各种问题。您需要首先解决这个问题。空间回收:**1)** 快速选项,**2)** 详细选项。只需将下载和媒体文件夹转储到低调的USB驱动器或SD磁盘上?之后运行cleanmgr.exe,并进行压缩(适用于快速SSD驱动器)。 - Stein Åsmul
3
不是问题的根源,而是P-Invoke编组程序知道如何处理A/W业务,而您正在妨碍它。当您将函数声明为“GetWindowLongPtr”并分配“CharSet = CharSet.Auto”时,它将正确选择“W”或“A”版本并处理字符串转换。 - GSerg
显示剩余2条评论
1个回答

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

32-bit user32.dll

在C和C++ WinAPI代码中使用GetWindowLongPtr(不管是32位还是64位),原因是在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);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接