简体   繁体   English

JNA使用宏

[英]JNA Using macros

Is it possible to map The following Macro function with JNA? 是否可以通过JNA映射以下Macro函数?

int ListView_FindItem(
 HWND hwnd,
int iStart,
const LPLVFINDINFO plvfi
);

I've tried to map this function with StdCallLibraryb, but that does not seem to work (Function not found exception is thrown). 我尝试使用StdCallLibraryb映射此函数,但这似乎不起作用(抛出“找不到函数”异常)。

Basically i am trying find the index of a particular item in List view of desktop. 基本上我正在尝试在桌面的列表视图中找到特定项目的索引。 I have the name of the item i intend to find. 我有我要查找的商品的名称。

EDIT: i have tried using the send message feature, i get the following exception 编辑:我尝试使用发送消息功能,我得到以下异常

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function   
'GetMessage': The specified procedure could not be found.

at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:347)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:327)
at com.sun.jna.Library$Handler.invoke(Library.java:203)
at $Proxy0.GetMessage(Unknown Source)
at javaapplication4.Main.main(Main.java:43)
Java Result: 1

This is the code i used 这是我使用的代码

public class Main {


  public static class LVFINDINFO extends Structure {
     public int    flags =1002;
     public String psz = "new folder3";
     public LPARAM  lParam ;
     public POINT   pt;
     public int    vkDirection;
}
  public static class MSG extends Structure {
    public HWND hWnd;
    public int message;
    public int  wParam =-1;
    public LVFINDINFO lParam1;
    public int time;
    public POINT pt;

    public MSG(LVFINDINFO lParam) {
        lParam1 = lParam;
    }
}

public static void main(String[] args) {
    User32 user32 = (User32) Native.loadLibrary("User32", User32.class);

    LVFINDINFO i = new LVFINDINFO();
    MSG m = new MSG(i);
    user32.GetMessage(m, user32.GetDesktopWindow(), 0, 0);

    System.out.println(user32.GetMessage(m, user32.GetDesktopWindow(), 0, 0));
}

}

Since a macro exists purely at compile-time, there's no way to call it using JNA. 由于宏仅在编译时存在,因此无法使用JNA对其进行调用。

You'll need to see what the macro actually does and do that instead. 您需要查看宏实际执行的操作,然后执行该操作。 According to the documentation it sends the LVM_FINDITEM message . 根据文档,它发送LVM_FINDITEM消息 You need to find out how to send that message using JNA. 您需要了解如何使用JNA发送该消息。

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

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