欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

java 调用动态链接库_JAVA技巧:JNative调用动态链接库问题(SOS)

发布时间:2023/12/10 编程问答 50 豆豆
生活随笔 收集整理的这篇文章主要介绍了 java 调用动态链接库_JAVA技巧:JNative调用动态链接库问题(SOS) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

动态链接库的方法如下:__declspec(dllexport) ret __stdcall rLachTran(const char *pc_trancode,

const char *pc_clicode,

const char *pc_orgcode,

const char *pc_ttycode,

const int i_brandid,

const char *pc_reqstamp,

const int i_reqseqno,

const char *pc_svrip,

const unsigned short us_svrport,

const char *pc_reqmsg,

char *pc_resmsg);

我需要发送一条短信随机码出去,而我的JNi类如下:package com.JNative;

package com.JNative;

import java.io.UnsupportedEncodingException;

import org.xvolks.jnative.JNative;

import org.xvolks.jnative.Type;

import org.xvolks.jnative.exceptions.NativeException;

import org.xvolks.jnative.pointers.Pointer;

import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;

public class Dll_Nat {

/**

* @param args

*/

public static void main(String[] args) throws NativeException ,IllegalAccessException{

// TODO Auto-generated method stub

Dll_Nat uc = new Dll_Nat();

String ret = null;

String result = uc.getNate("0023MBL_ZDtech_00001",

"0023MBL_SH_SVR00-01-02-03-04-05","ORGCODE",

"ttycode",0,"2008-08-25 15:51:55.025000", 1,

"218.201.33.11",50002,

"900001;00-01-02-03-04-05;1388*******~123435", ret);

System.out.println("转换成功的字节数为:"+result);

}

static JNative n = null;

static Pointer pointer;

public final int getNate(String trancode,

String clicode,

String orgcode,

String ttycode,

int brandid,

String reqstamp,

int reqseqno,

String svrip,

int svrport,

String reqmsg,

String resmsg) throws NativeException ,IllegalAccessException{

try{

n = new JNative("SwtThinClient.dll","rLachTran");

n.setRetVal(Type.INT);

int i =0 ;

n.setParameter(i++,trancode);

n.setParameter(i++,clicode);

n.setParameter(i++, orgcode);

n.setParameter(i++, ttycode);

n.setParameter(i++, brandid);

n.setParameter(i++, reqstamp);

n.setParameter(i++, reqseqno);

n.setParameter(i++, svrip);

n.setParameter(i++, svrport);

n.setParameter(i++, reqmsg);

n.setParameter(i++, resmsg);

n.invoke();

System.out.println(n.getRetVal());

return Integer.parseInt(n.getRetVal());

}catch(NativeException Ne){

System.out.println("NativeException: "+Ne.getMessage());

return -999;

}catch(IllegalAccessException Nen){

System.out.println("IllegalAccessException: "+Nen.getMessage());

return -888;

}

finally{

if (n != null)

n.dispose();

}

}

}

系统总是提示:不能链接服务器,而且C方法中的编码是ASCII编码,该问题需要如何处理?请大家指教。

具体系统提示如下:

[SwtThinClient.c][76][2008-08-26 13:19:06.118000] -> 提示:rLachTran调用开始

[SwtThinClient.c][138][2008-08-26 13:19:06.128000] -> 错误:连接服务器[218.201.33.11]失败,i_commtimeout_g[59990],WSAERRNO[10049]

[SwtThinClient.c][138][2008-08-26 13:19:06.128000] -> 错误:连接服务器[218.201.33.11]失败,i_commtimeout_g[59990],WSAERRNO[10049]

[SwtThinClient.c][138][2008-08-26 13:19:06.128000] -> 错误:连接服务器[218.201.33.11]失败,i_commtimeout_g[59990],WSAERRNO[10049]

JAVA技巧:JNative调用动态链接库问题(SOS).doc

下载Word文档到电脑,方便收藏和打印[全文共1692字]

编辑推荐:

下载Word文档

总结

以上是生活随笔为你收集整理的java 调用动态链接库_JAVA技巧:JNative调用动态链接库问题(SOS)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。