简体   繁体   English

通过JNA调用方法进行回调

[英]call a method with JNA through to callback

I need to invoke a method using JNA through a callback, the problem is that api not recognize the method, because JNA callback doesn't contain a function where you pass by a method parameter. 我需要通过回调使用JNA来调用方法,问题是api无法识别该方法,因为JNA回调不包含您通过方法参数传递的函数。

the function in C is : C中的函数是:

Result API LS800AutoDocHandle(...
int          (__stdcall *userfunc1)(S_CODELINE_INFO_LS800 *CodelineInfo),
int          (__stdcall *userfunc2)(S_IMAGE_INFO_LS800 *ImageInfo),
int          (__stdcall *userfunc3)(S_IMAGE_INFO_LS800 *ImageInfo),
...);

this function invoke this method 此函数调用此方法

    Reply = LS800AutoDocHandle(...
    (CodelineType == READ_CODELINE_MICR ? OnCodelineRead : 0),
    (CodelineType == NO_READ_CODELINE ? OnImageFrontReady : 0),
    NULL,//OnImageBackReady,
    ...);                  // Reserved3    

then my question is, how I can call the method OnCodelineRead through a callback with JNA? 那么我的问题是,如何通过JNA的回调调用OnCodelineRead方法?

JNA uses Callback objects to represent function pointers, and includes a description of callback usage . JNA使用Callback对象表示函数指针,并包括对回调用法描述

Native code: 本机代码:

int LS800AutoDocHandle(
                       int (__stdcall *userfunc1)(S_CODELINE_INFO_LS800* info),
                       int (__stdcall *userfunc2)(S_CODELINE_INFO_LS800* info),
                       int (__stdcall *userfunc3)(S_CODELINE_INFO_LS800* info)
                      );

JNA mapping (should probably use StdCallLibrary , API is probably __stdcall ): JNA映射(可能应该使用StdCallLibraryAPI可能是__stdcall ):

public interface CodeLineRead extends StdCallCallback {
    int invoke(S_IMAGE_INFO_LS800 info);
}
public interface ImageFrontReady extends StdCallCallback {
    int invoke(S_IMAGE_INFO_LS800 info);
}
public interface ImageBackReady extends StdCallCallback {
    int invoke(S_IMAGE_INFO_LS800 info);
}

int LS800AutoDocHandle(CodeLineRead f1, ImageFrontReady f2, ImageBackReady f3);

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

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