Hello, I am trying to link a Java application to some Modula-2 DLLs and I am using a wrapper I have written in Delphi. I have downloaded the Delphi unit JNI.pas from http://home.pacifier.com/~mmead/jni/delphi/JEDI/DOCS/delphi-jni-1.html -> this contains methods to connect Delphi and Java.
I have Java code that I have looks like this:
Java Code:
public class DLLTest{
public DLLTest(){
}
public native String getName();
static{
System.loadLibrary("c:\\saphire8\\HelloWorldImpl.dll");
}
public static void main(String args[]){
DLLTest t = new DLLTest();
System.out.println(t.getName());//Just gets a name from some database
}
}
Delphi code (dll)
library HelloWorldImpl
uses
ShareMem,Dialogs,JNI,Classes,API_Risk,SageRiskUtil;
//Just some libaries I use, JNI is the one mentioned above
var
JVM: TJNIEnv;
procedure Ext_Get_Name(var name : API_Risk.NameType); stdcall;
external 'sagerisk.dll' name 'Project_Get_Name';
//The type API_Risk.NameType is just a character array of size 25
function Java_DLLTest_getName(PEnv: PJNIEnv; Obj: JObject):JString;
var
name : API_Risk.NameType;
name1: String;
name2: JString;
begin
JVM:=TJNIEnv.Create(PEnv);
Ext_Get_Name(name);
CharArraytoString(name,name1);//This is defined in one of those libaries
name2:=JVM.StringToJString(name); //Defined in JNI.pas
Result:= name2;
end;
exports
Java_DLLTest_getName;
end.
I place these things in the proper directories and I run...I get the following error:
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x02ca2bde, pid=5400, tid=5160
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_08-b03 mixed mode, sharing)
# Problematic frame:
# C [HelloWorldImpl.dll+0x52bde]
#
# An error report file with more information is saved as hs_err_pid5400.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
The Java connects to the .dll just fine, I have verified that.
That variable JVM is an instance of the Java Native Interface in Delphi. If I leave that out and don't try and convert that string, just print out what I get from the Ext_get_Name name function with Delphi's ShowMessage(string), I do not get that error. If I even call up an instance of JVM with
TJNIEnv.Create(PEnv) and don't do anything with it, it gives me the same error. I have no idea what is causing this problem. If anyone has any familiarity with Delphi and Java I would love some input. Thanks in advance.