通过 JNA 从 Java 调用 C varargs 函数

问题描述

these past issuesthis documentation 的外观来看,它似乎可行,但如何?

我的试验:

C

extern "C" GATEWAY_API void callIntoNative(LPCSTR evt_name,...);


void callIntoNative(LPCSTR evt_name,...)
//void callIntoNative(char* evt_name)
{
    std::cout << evt_name << std::endl;
    va_list vargs;
    va_start(vargs,evt_name);
    std::cout << va_arg(vargs,int) << "   " << va_arg(vargs,double) << std::endl;
    va_end(vargs);
}

Java

  // public static native void callIntoNative(String evtName,Object[] varargs);
  //  public static native void callIntoNative(String evtName,Object... varargs);
//GateWay.callIntoNative("give me love",new Object[] {24,new String()});

Function callIntoNative = Function.getFunction("gateway.dll","callIntoNative");
callIntoNative.invoke(new Object[]{new String("give me love"),new Integer(24),new Double(3.14)});

Java 程序的输出

give me love
1374389535   1.18576e-322

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)