我有一个 DLL,但没有它的源代码。我想在这个 DLL 中调用一个方法。
现在在这张图片中。可以看到我要访问的是Test2.DLL
which have fb1_CheckSensor
Method。但它位于 Test1.DLL 中
所以可以说我只有一个选择,那就是加载 1 个 DLL。仅适用于 JAVA 的 Test1.DLL
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
public interface FB4API3Lib extends Library{
FB4API3Lib INSTANCE = (FB4API3Lib)Native.loadLibrary("Interop.FB4API3Lib.dll", FB4API3Lib.class);
int fb1_Open(int nUnit);
void fb1_Close(int nUnit);
void fb1_SetCommunicationMode(int nMode);
int fb1_GetNumberOfUnits();
NativeLong fb1_Stop(int nUnit);
int fb1_Reset(int nUnit);
int fb1_CheckSensor(int nUnit,StringByReference strWrk);
int fb1_SetImageFileFolder(int nUnit,String strPath);
int fb1_SetImageFileName(int nUnit,String strFileName);
int fb1_SetImageRegulation(int nUnit,tagImageInfo pImageInto);
NativeLong fb1_SetEndorseData(int nUnit,String strEds);
NativeLong fb1_SetEndorseMultiLine (int nUnitNo, tagEdsMulti pInfo);
int fb1_Run(int nUnit, IntByReference strWrk3, StringByReference strWrk, IntByReference strWrk2);
int fb1_Run1(int nUnit,StringByReference strWrk,IntByReference strWrk2);
int fb1_Run1Ex(int nUnit,StringByReference strWrk,IntByReference strWrk2);
int fb1_Eject(int nUnit,int nPocket,int nNext);
int fb1_WaitEjecting(int nUnit);
int fb1_WaitCompleted(int nUnit);
void fb1_GetDetailErrorInfo(String strErr);
int fb1_Initialize(int nUnit);
int fb1_SetBinaryMode(int nUnit, int nSide, int nMode);
int fb1_SetRunMode(int nUnit, int nMOde, int nOpt, int nPkt);
int fb1_GetImageData(int nUnit, PointerByReference hBmap);
int fb1_GetEndorseStatus(int nUnit, IntByReference pType, int nFunc, tagMtrIjpSts pStutus);
int fb1_SetDeviceInfo(int nUnit, int nDeviceInfoID, String pszIn);
int fb1_SetBinaryInfo(int nUnit, int nSide, tagFb1BiInfo pBiInfo);
}
现在对于实现上述接口的类
import com.sun.jna.NativeLong;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
public class CallDLL implements FB4API3Lib {
public int fb1_Open(int nUnit) {
return INSTANCE.fb1_Open(nUnit);
}
public Object CreateTheClass() {
return INSTANCE;
}
public void fb1_Close(int nUnit) {
INSTANCE.fb1_Close(nUnit);
}
public void fb1_SetCommunicationMode(int nMode) {
INSTANCE.fb1_SetCommunicationMode(nMode);
}
public int fb1_GetNumberOfUnits() {
return INSTANCE.fb1_GetNumberOfUnits();
}
public NativeLong fb1_Stop(int nUnit) {
return INSTANCE.fb1_Stop(nUnit);
}
public int fb1_Reset(int nUnit) {
return INSTANCE.fb1_Reset(nUnit);
}
public int fb1_CheckSensor(int nUnit,StringByReference strWrk) {
return INSTANCE.fb1_CheckSensor(nUnit,strWrk);
}
public int fb1_SetImageFileFolder(int nUnit,String strPath) {
return INSTANCE.fb1_SetImageFileFolder(nUnit,strPath);
}
public int fb1_SetImageFileName(int nUnit,String strFileName) {
return INSTANCE.fb1_SetImageFileName(nUnit,strFileName);
}
public int fb1_SetImageRegulation(int nUnit,tagImageInfo pImageInto) {
return INSTANCE.fb1_SetImageRegulation(nUnit,pImageInto);
}
public NativeLong fb1_SetEndorseMultiLine(int nUnit,tagEdsMulti pInfo) {
return INSTANCE.fb1_SetEndorseMultiLine(nUnit,pInfo);
}
public NativeLong fb1_SetEndorseData(int nUnit,String strEds) {
return INSTANCE.fb1_SetEndorseData(nUnit,strEds);
}
public int fb1_Run(int uUnit, IntByReference strWrk3, StringByReference strWrk, IntByReference len) {
return INSTANCE.fb1_Run(uUnit, strWrk3, strWrk, len);
}
public int fb1_Run1(int nUnit,StringByReference strWrk,IntByReference len) {
return INSTANCE.fb1_Run1(nUnit,strWrk, len);
}
public int fb1_Run1Ex(int nUnit,StringByReference strWrk,IntByReference len) {
return INSTANCE.fb1_Run1Ex(nUnit,strWrk, len);
}
public int fb1_Eject(int nUnit,int nPocket, int nNext) {
return INSTANCE.fb1_Eject(nUnit,nPocket, nNext);
}
public int fb1_WaitEjecting(int nUnit) {
return INSTANCE.fb1_WaitEjecting(nUnit);
}
public int fb1_WaitCompleted(int nUnit) {
return INSTANCE.fb1_WaitCompleted(nUnit);
}
public void fb1_GetDetailErrorInfo(String strWrk) {
INSTANCE.fb1_GetDetailErrorInfo(strWrk);
}
public int fb1_Initialize(int nUnit){
return INSTANCE.fb1_Initialize(nUnit);
}
public int fb1_SetBinaryMode(int nUnit, int nSide, int nMode){
return INSTANCE.fb1_SetBinaryMode(nUnit, nSide, nMode);
}
public int fb1_SetRunMode(int nUnit, int nMode, int nOpt, int nPkt){
return INSTANCE.fb1_SetRunMode(nUnit, nMode, nOpt, nPkt);
}
public int fb1_GetImageData(int nUnit, PointerByReference pBmap){
return INSTANCE.fb1_GetImageData(nUnit, pBmap);
}
public int fb1_GetEndorseStatus(int nUnit, IntByReference pType, int nFunc, tagMtrIjpSts pStutus){
return INSTANCE.fb1_GetEndorseStatus(nUnit, pType, nFunc, pStutus);
}
public int fb1_SetDeviceInfo(int nUnit, int nDeviceInfoID, String pszIn){
return INSTANCE.fb1_SetDeviceInfo(nUnit, nDeviceInfoID, pszIn);
}
public int fb1_SetBinaryInfo(int nUnit, int nSide, tagFb1BiInfo pBiInfo){
return INSTANCE.fb1_SetBinaryInfo(nUnit, nSide, pBiInfo);
}
}
所以这里的问题是。我不会到达 Test2.DLL 因为我实际上试图调用接口的地方是来自 Test1.DLL
我只能加载 Test1.DLL,我无法将 Test2.DLL 作为另一个实例加载。我怎样才能通过加载 Test1.DLL 作为父级来访问 Test2.DLL。