JNA 使用宏

发布于 2024-12-05 19:39:01 字数 1640 浏览 0 评论 0原文

是否可以将以下宏函数与JNA映射?

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

我尝试使用 StdCallLibraryb 映射此函数,但这似乎不起作用 (抛出函数未找到异常)。

基本上我正在尝试在桌面列表视图中查找特定项目的索引。 我有我想要找到的物品的名称。

编辑: 我尝试使用发送消息功能,但出现以下异常

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

这是我使用的代码

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));
}

}

Is it possible to map The following Macro function with JNA?

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).

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));
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

够钟 2024-12-12 19:39:01

由于宏纯粹存在于编译时,因此无法使用 JNA 调用它。

您需要查看该宏实际执行的操作并执行该操作。根据文档,它发送< a href="http://msdn.microsoft.com/en-us/library/bb774903%28v=VS.85%29.aspx" rel="nofollow"> LVM_FINDITEM 消息。您需要了解如何使用 JNA 发送该消息。

Since a macro exists purely at compile-time, there's no way to call it using 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. You need to find out how to send that message using JNA.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文