简体   繁体   English

使用来自 user32.dll 的 SendMessage 和 java 中的 jna - 错误

[英]using SendMessage from user32.dll with jna in java - error

I try to use the:我尝试使用:

LRESULT WINAPI SendMessage(_In_  HWND hWnd, _In_  UINT Msg,
                           _In_  WPARAM wParam, _In_  LPARAM lParam);

in Java with jna and i keep getting a error:在带有 jna 的 Java 中,我不断收到错误消息:

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Error looking up function 'SendMessage'

this is my interface:这是我的界面:

public interface User32 extends StdCallLibrary {
Pointer GetForegroundWindow();
int SendMessage(Pointer hWnd, int msg, int num1, int num2);

and i call it like that:我这样称呼它:

Pointer hW = user32.GetForegroundWindow();
user32.SendMessage(hW, 0x0201, 0, 0);
user32.SendMessage(hW, 0x0202, 0, 0);

the hWnd is right. hWnd 是对的。 where is my mistake?我的错误在哪里?

JNA can not find the function "SendMessage" in user32.dll because there no function of that name exported. JNA 在 user32.dll 中找不到函数“SendMessage”,因为没有导出该名称的函数。

This is because SendMessage is an old name that is automatically mapped by the other compilers to the matching ANSI or UNICODE version of the function - SendMessageA and SendMessageW .这是因为 SendMessage 是一个旧名称,由其他编译器自动映射到函数的匹配 ANSI 或 UNICODE 版本 - SendMessageASendMessageW

Using tools that show the exported functions of a DLL like DependencyWalker you can see that user32.dll of Windows 7 for example only knows both functions SendMessageA and SendMessageW but no SendMessage .使用显示诸如 DependencyWalker 之类的 DLL 导出函数的工具,您可以看到 Windows 7 的 user32.dll 仅知道两个函数SendMessageASendMessageW但不知道SendMessage

The function definition you use looks like the ANSI version, hence you should use SendMessageA instead.您使用的函数定义看起来像 ANSI 版本,因此您应该改用SendMessageA

BTW.顺便提一句。 It doesn't make any difference if you are using 32bit or 64bit Java and user32.dll.如果您使用 32 位或 64 位 Java 和 user32.dll,这没有任何区别。 What I wrote is true for both versions.我写的对于两个版本都是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM