日期:2014-05-20  浏览次数:20780 次

java调用delphi dll的 [out param: WideString]参数问题
最近需要调用delphi的dll,定义为:
function xxxx(const sParam: WideString; out sResult: WideString;): Integer;  stdcall;

使用JNative调用现在就是两个问题:
1、参数sParam:使用obj.setParameter(0, Type.STRING,"test");值传入dll后就不是test了。
2、参数sResult就完全不知道怎么写了,感觉只能写Pointer了,写上也不知道怎么获取结果。

考虑到C#有out方式就用C#试了下,发现这样可以调成功。
[DllImport("xxxx.dll", EntryPoint = "xxxx", CharSet = CharSet.Unicode)]
static extern int xxxx(byte[] sParam, out string sResult);

//sParam这里用string dll中只能得到一半
Console.WriteLine(xxxx(new UnicodeEncoding(false, false).GetBytes("test"), out sResult));
Console.WriteLine(sResult);


有没有人弄过这种类型的dll呀,不管用JNative还是其他方式都行,有人指点下没。



 

------解决方案--------------------
没用过jnative,以前做过这种类似的,但是是自己用c封装jni调用的。
------解决方案--------------------
参考:https://github.com/twall/jna/blob/master/www/Mappings.md