R
Robert Birn
Hello,
I'm using a third-party DLL to control an I/O-Interface via USB.
My Java-program uses JNI to call a native DLL which calls the
functions in the third-party DLL.
Everything works fine when I'm calling the native methods in the
main() function.
But if I invoke the native methods in a Java-Thread, everything also
works but I get the following Windows-Message when the application
_exits_:
JAVAW caused an error in module KERNEL32.DLL...
Here are some Code-Snipplets:
/** the "fine" solution **/
public class Test01 {
public static void main(String[] args) {
JNIinterface jniIF = new JNIinterface();
jniIF.openDevice(0);
jniIF.setAllDigital();
jniIF.closeDevice();
}
}
/** the "bad" solution **/
public class Test02 {
public static void main(String[] args) {
Test02Thread t = new Test02Thread();
t.start();
}
}
public class Test01Thread extends Thread {
public void run() {
JNIinterface jniIF = new JNIinterface();
jniIF.openDevice(0);
jniIF.setAllDigital();
jniIF.closeDevice();
}
}
/** the JNI interface **/
class JNIinterface {
static {
System.loadLibrary("JNIinterface");
}
private native int callOpenDevice(int _cardAddress);
private native void callCloseDevice();
private native void callSetAllDigital();
public int openDevice(int _cardAdress) {
return callOpenDevice(_cardAdress);
}
public void closeDevice() {
callCloseDevice();
}
public void setAllDigital() {
callSetAllDigital();
}
}
Where is my fault?
Regards
Robert
I'm using a third-party DLL to control an I/O-Interface via USB.
My Java-program uses JNI to call a native DLL which calls the
functions in the third-party DLL.
Everything works fine when I'm calling the native methods in the
main() function.
But if I invoke the native methods in a Java-Thread, everything also
works but I get the following Windows-Message when the application
_exits_:
JAVAW caused an error in module KERNEL32.DLL...
Here are some Code-Snipplets:
/** the "fine" solution **/
public class Test01 {
public static void main(String[] args) {
JNIinterface jniIF = new JNIinterface();
jniIF.openDevice(0);
jniIF.setAllDigital();
jniIF.closeDevice();
}
}
/** the "bad" solution **/
public class Test02 {
public static void main(String[] args) {
Test02Thread t = new Test02Thread();
t.start();
}
}
public class Test01Thread extends Thread {
public void run() {
JNIinterface jniIF = new JNIinterface();
jniIF.openDevice(0);
jniIF.setAllDigital();
jniIF.closeDevice();
}
}
/** the JNI interface **/
class JNIinterface {
static {
System.loadLibrary("JNIinterface");
}
private native int callOpenDevice(int _cardAddress);
private native void callCloseDevice();
private native void callSetAllDigital();
public int openDevice(int _cardAdress) {
return callOpenDevice(_cardAdress);
}
public void closeDevice() {
callCloseDevice();
}
public void setAllDigital() {
callSetAllDigital();
}
}
Where is my fault?
Regards
Robert