很感谢前几天大家热心帮助我
现在有新的问题再次需要大家的热心指点描述:
需要用java调用c/c++ dll
上网查了资料有
jni,jawin,jacob
3种办法可以解决,觉得jawin用起来很方便就着手解决了研究完demo以后也很快调用要使用的dll成功了,不过参数不正确不能正确的调用
主要卡在了设置【数据指令】上面,网上的资料不多,官方的英文说明看了下但没看到char*之类类型的,用其他的试了下好像不行。
dll接口如下,为了让函数清晰,减少了很多相同类型的参数:Dll名称:VoucherVerify.dll 。函数接口:
BOOL  __stdcall  VoucherVerify(
int  nMode,
const char* szAccount,
cosnt char* szMoney,
char szRet[65],
char szExtData[65]
) ;参数说明: 
Int nMode     【In】模式。传入1、2、3
cosnt char* szMoney   【In】交易金额。15位不包含空格小数点。
例如 :1234.56元,
则为“000000000123456”
char szRet[65];   【Out】返回值, 目前只用第一位,其他保留
szRet[0]  为‘1’ 验票成功。
szRet[0]  为‘2’ 验票失败。
char  szExtData [65]   【In/Out】说明数据。现在我的程序只是测试性质的乱传了几个参数,可以调用到dll,但是调用不正确(看到c/c++写的初始化界面,接着我这里的控制台也提示调用不正确)
因为这个dll程序是要连接服务器数据库的,所以给大家也不能用来调试或参考。jawin调用dll程序片段:
test= new FuncPtr("VoucherVerify.dll", "VoucherVerify");
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);

leos.writeInt(1);//操作模式

leos.writeStringUnicode("123456");//操作员代码
……
leos.writeStringUnicode("From Jawin");//扩展数据test.invoke("IGGGGGGGGI:I:", 16, nbs, null, ReturnFlags.CHECK_FALSE);
//第一个参数是数据指令的,卡在这里,这里是试来试去乱写的,大概意思明白了  (参数类型:返回值:out参数)就是不知道char*用哪个代表好
还有前面的in/out参数也不知道怎么用LittleEndianOutputStream 来给提供参考资料,也供不会的大家一起研究
网上资料真的太少,官方的数据指令doc例子里没我char*这样类型了,试来试去都不行
instructions.h 我拿着金山又看不懂(高手请读之)jawin使用快速入门:
http://jawinproject.sourceforge.net/jawinuserguide_dll.html网上除官方数据指令最清楚的说明(查看jawin部分):
http://hi.baidu.com/evenbill/blog/item/669f6309c0d0c037e82488c7.html官方数据指令解释有例子:
http://jawinproject.sourceforge.net/instruction_docs.html附完整数据指令:
-------------
instructions.h
-------------
/**
 * allocate a four byte buffer and write address to dest
 */
#define ALLOC_WORD_BUFFER        'A'/** read stringified int n from instructions
 * copy n bytes from src to dest
 */
#define BLT_N                    'B'  /** 
 * read unicode wire string from src
 * allocate BSTR with contents of string
 * write address of BSTR to dest
 */
#define WRITE_BSTR               'G'/**
 * read BSTR at src 
 * write unicode wire format at dest
 */
#define READ_BSTR                'g'/**
 * read HRESULT from src.
 * Throw Java exception if FAILED(hr)
 */
#define READ_HR_CHECK            'H'/**
 * BLT 4 octets from src to dest
 */
#define BLT4                     'I'/**
 * BLT 8 octets from src to dest
 */
#define BLT8                     'D'/** 
 * read stringified int n from instructions
 * skip n bytes in dest
 */
#define SKIP_N_DEST              'K'/** 
 * read stringified int n from instructions
 * skip n bytes in source
 */
#define SKIP_N_SOURCE            'L'
 
/** 
 * read stringified int n from instructions
 * alloc size n buffer and write address to dest
 */
#define ALLOC_N_BUFFER           'M'/**
 * read pointer p from src
 * read stringified n from instructions
 * copy n bytes at p into dest
 */
#define INDIRECT_BLT_N           'n'/**
 * read pointer p from src 
 * read delimited instructions i
 * read stringified length from i
 * create newIn(p, length)
 * process (newIn,i,dest)
 */
#define SUBMARSHAL_IN            'N'/**
 * exactly like SUBMARSHAL_IN
 * except do not read length from marshal
 * (length is unknown at compile time)
 */
#define SUBMARSHAL_IN_OPEN       'O'/**
 * read stringified n from instructions
 * write current address of src to dest
 * skip n bytes of input
 */
#define ADDRESS_AND_SKIP         'P'/** 
 * write current src address to dest
 * create new dest pointing to src
 * read stringified instruction token t from src
 * read stringified int size from src
 * submarshal on (src+size, lookup(t), newDest)
 */
#define ADDRESS_SUB_IN_PLACE     'R'/**
 * Handles interface pointers whose thread affinity
 * is controlled by the instruction stream
 * contextLocal == (G == char from instructions)
 * if contextLocal blt directly
 * else register in git and blt cookie
 */
#define BLT_CONTROLLED_UNKNOWN   'U'/** 
 * read native variant at src and write java variant wire format to dest
 */
#define SERIALIZE_VARIANT        'V'/**
 * read java variant wire format from src and write native variant to dest
 */
#define DESERIALIZE_VARIANT      'v'

解决方案 »

  1.   

    JNI觉得用起来有点复杂啊
    而且自己荒废太久c/c++了,忘得差不多了
    要重拾,时间上不允许。我查查JNA吧,不知道有没人用其他比较容易的解决方案呢?
    麻烦给介绍下,指点下,谢谢
      

  2.   

    查了下资料,好像jNA不错的
    不过资料不是很多
    麻烦有有好资料共享一下
    手头找到两个不错的
    http://blog.csdn.net/shendl/archive/2008/12/23/3589676.aspx
    http://www.infoxa.com/asp/tech_file/xxnr_tech_793.htm
    官方地址在第一篇里
      

  3.   

    咦?发现官方的东东只有src和jar没有demo耶……
      

  4.   

    网络不方便
    要去其他地方工作了了
    粗略的看了下资料确实不错
    提前问一下两个问题
    用JNA 
    char[]类型和函数返回值怎么解决我拿好资料去研究了,晚上回来
    麻烦大家指导一下