JNA-具有typedef struct **参数的回调方法

时间:2019-02-22 09:12:55

标签: java callback jna

我正在使用带有以下代码的C dll:

1)

Error using sym/ezplot (line 45)
Plotting requires not more than 2 variables.

Error in lab1 (line 5)
ezplot(ynt); 

2)

AIC_BRIDGE_API AIC_ERROR_CODE aic2_set_cb_function (
    void (*cb2_start_dsts) (AIC2_DSTS_START_STOP),
    void (*cb2_stop_dsts) (AIC2_DSTS_START_STOP),
    void (*cb2_dsts_rcvd_ex) (unsigned int, unsigned long *, char *, AIC2_DSTS_STO),
    void (*cb2_log) (const char *, int, const char *, int)
);

该dll在具有C / C ++和.Net代码的许多应用程序中运行。 我在Java中的代码是这样的:

1)

aic2_set_cb_function (NULL, NULL, cb2_dsts_rcvd_ex, NULL);

2)

public interface ReadCallbackInt extends Callback {
    void invoke(int iNumDv, Pointer pMicDv, String pcARName, AIC2_DSTS_STO.ByValue sto);
}

3)

public void aic2_set_cb_function(StartDSCallbackInt fn1, 
                           StopDSCallbackInt fn2, 
                           ReadCallbackInt fnReadCB,
                           LogCallbackInt fn4);

..................... ......

4)

TestLib.ReadCallbackInt fnReadCB = new TestLib.ReadCallbackInt() {
    long[] IntArray;

    @Override
    public void invoke(int iNumDv, Pointer pMicDv, String pcARName, AIC2_DSTS_STO.ByValue sto) {
        if (sto.bTsNamePres > 0) {
            System.out.println("iNumDv: " + iNumDv);
            System.out.println("pMicDv: " + pMicDv);
            System.out.println("pcARName: " + pcARName);
            System.out.println("sto: " + sto.TsName);
            if (pMicDv!=null) {
                IntArray = new long[iNumDv]; 
                IntArray = pMicDv.getLongArray(0, iNumDv);
                if (IntArray != null) {
                    System.out.println("IntArray: " + IntArray +" First El. " + IntArray[0]);
                }
            }
        }
    }
}      

问题是在IntArray中,我将所有元素都设为零。你能帮我吗?

5)原始C代码:

TestLib.INSTANCE.aic2_set_cb_function(null, null, fnReadCB, null);

0 个答案:

没有答案