有两个问题
一 你的FirmClient.dll是原来已有的dll吗,还是通过jni出来的?
如果是以前的DLL,要调用它需要通过jni重新写一个dll来调用
具体的用法可以参考java native interface文档
二 如果你的DLL是jni出来的,那么应该放在path路径或者当前路径
System.loadLibrary("FirmClient.dll");
应该为System.loadLibrary("FirmClient");
不需要后缀名
一 你的FirmClient.dll是原来已有的dll吗,还是通过jni出来的?
如果是以前的DLL,要调用它需要通过jni重新写一个dll来调用
具体的用法可以参考java native interface文档
二 如果你的DLL是jni出来的,那么应该放在path路径或者当前路径
System.loadLibrary("FirmClient.dll");
应该为System.loadLibrary("FirmClient");
不需要后缀名
-Djava.library.path=d://xxx/xxxx.dll(是不是-D记不太清了)
也可以在程序中动态设置:
System.seyptoperty("java.library.path","c://xxsad");但必须在调用loadLibrary("")之前,你可以试试
{
static
{
System.loadLibrary("FirmClient");
}
public native static int Logout();
public static void main(String[] args)
{
FirmClient test = new FirmClient();
System.out.println(Integer.toString(test.Logout()));
}
}改了一下,错误提示:(这是怎么回事呢???)
java.lang.UnsatisfiedLinkError: Logout
at dll.FirmClient.Logout(Native Method)
at dll.FirmClient.main(FirmClient.java:19)
Exception in thread "main"
{
static
{
System.loadLibrary("Connect");
}
public native static String Sms(String Param);
public static void main(String[] args)
{
Connect conn = new Connect();
System.out.println(conn.Sms("ok"));
}
}
错误:java.lang.UnsatisfiedLinkError: Sms
at Connect.Sms(Native Method)
at Connect.main(Connect.java:22)
Exception in thread "main"
DLL文件源程序:unit send;{$WARN SYMBOL_PLATFORM OFF}interfaceuses
ComObj, ActiveX, Connect_TLB, StdVcl;type
TSend = class(TAutoObject, ISend)
protected
function Sms(const Param: WideString): WideString; safecall;
{ Protected declarations }
end;implementationuses ComServ;function TSend.Sms(const Param: WideString): WideString;
begin
Sms:=Param;
end;initialization
TAutoObjectFactory.Create(ComServer, TSend, Class_Send,
ciMultiInstance, tmApartment);
end.生成:Connect.dll
先谢过.
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Connect */#ifndef _Included_Connect
#define _Included_Connect
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Connect
* Method: Sms
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_Connect_Sms
(JNIEnv *, jclass, jstring);#ifdef __cplusplus
}
#endif
#endif
那么只能通过JNI来重新写一个动态库对原有的动态库进行包装。
最后的调用方式是Java class -> JNI dll -> your dll
2.如果你没有动态库,但有些事情需要用到C++来实现的话。
只需要用JNI写个动态库就好了。
至于JNI动态库的建立步骤如下:
先写好Java class(声明方法为Native)
编译Java class
用Javah -jni yourclass来生成C++头文件,yourclass.h
用VC或者CB创建一个普通DLL,把yourclass.h加入工程
并实现那些方法。
最后在你的Java程序中调用
然后用javah生成一个javaclass.h文件,通过delphi来实现javavclass.h中的方法.最后通过java来引用动态库中的方法.
编译,再用Javah生成*.h
新建一个VC或CB的dll工程,
在这个工程中将*.h中的方法实现。
至于怎样实现就是你的事情了。
因为不可以直接使用delphi,你如果已经有了一个delphi的dll
最后还是要写一个C实现的dll,来对原有的dll进行包装。
简单点就是在c实现中直接调用delphi dll中的同名函数