读书人

java调用C中的方法采用jna,本人不太

发布时间: 2012-01-30 21:15:58 作者: rapoo

java调用C中的方法,采用jna,本人不太清楚怎么将c中的方法在java中如何定义
下面是二个c 的中dll文件接口中提供的二个方法

int GenerateKeyA(unsigned long AuthenticationCode, unsigned long CardNo, unsigned long SerialNo, unsigned char *KeyBuffer);

int GenerateAuthenticationCode(unsigned short sicCode, unsigned long CardNo, unsigned long SerialNo unsigned long *AuthenticationCode);

想在java中声明, 然后通过 CLibrary.INSTANCE进行调用
请问我该如何转化方法,不太清楚java与c数据类型应该如何对应

[解决办法]
线在java中写好native方法, 编译后, 在用 javah -jni 编译这个类, 把生成的.h文件拿去实现, 编译成dll
在对应类中加入 System.loadLibrary() 就可以调用了,
[解决办法]
NativeLong long 平台依赖(32 或64 位整数)

JNA有这个类型
java的String对应c的char*

读书人网 >J2SE开发

热点推荐