![](/img/trans.png)
[英]JNA: Pass Pointer to Structure to SendMessage function of User32.dll as the LPARAM
[英]using SendMessage from user32.dll with jna in java - error
我尝试使用:
LRESULT WINAPI SendMessage(_In_ HWND hWnd, _In_ UINT Msg,
_In_ WPARAM wParam, _In_ LPARAM lParam);
在带有 jna 的 Java 中,我不断收到错误消息:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Error looking up function 'SendMessage'
这是我的界面:
public interface User32 extends StdCallLibrary {
Pointer GetForegroundWindow();
int SendMessage(Pointer hWnd, int msg, int num1, int num2);
我这样称呼它:
Pointer hW = user32.GetForegroundWindow();
user32.SendMessage(hW, 0x0201, 0, 0);
user32.SendMessage(hW, 0x0202, 0, 0);
hWnd 是对的。 我的错误在哪里?
JNA 在 user32.dll 中找不到函数“SendMessage”,因为没有导出该名称的函数。
这是因为 SendMessage 是一个旧名称,由其他编译器自动映射到函数的匹配 ANSI 或 UNICODE 版本 - SendMessageA
和SendMessageW
。
使用显示诸如 DependencyWalker 之类的 DLL 导出函数的工具,您可以看到 Windows 7 的 user32.dll 仅知道两个函数SendMessageA
和SendMessageW
但不知道SendMessage
。
您使用的函数定义看起来像 ANSI 版本,因此您应该改用SendMessageA
。
顺便提一句。 如果您使用 32 位或 64 位 Java 和 user32.dll,这没有任何区别。 我写的对于两个版本都是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.