修改cpp文件,把#include "stdafx.h"注释掉
XXXXX为类名,该文件用来实现JNI的封装,注意j要小写。加上#include
XXXXX为类名,该文件用来实现对JNI的调用,注意J要大写。
类中增加如下必须的代码:
private long p = -1;
private native long NewInstance();
private native void DelInstance(long p);
private native void SetServer(long p, long serverP);
private native byte[] GetErrorStr(long p);
public XXXXX() { p = NewInstance(); }//XXXXX()为构造函数。
public void setServer(JCSocServer jCSocServer) { SetServer(p, jCSocServer.getPointer()); }
public void delInstance() { DelInstance(p); }
public String getErrorStr() { return StringUtil.getGB18030Str(GetErrorStr(p)); }
如果C++类的公有成员变量较多,则JAVA类中的native函数的参数较多,手工书写比较费时,该工具可以帮助一键生成。
打开codegen软件,点击【生成JNI】按钮,如下图:
把第一步和第二步增加的Cpp文件加入到该文件。