Hi
I am calling a DLL with passing a callback functio object to it. One of the functions is simple print. I have then, a loop of 100 iterations, just printing the index and a few prints after the loop.
Here is the C code
extern "C" int Start(void* callback(CString))
{
for(int j=0; j<100; j++)
callback(AConvertToString(j));
callback("in Start called from Java");
callback("another line");
}
Here is the Java code
public interface MyDll extends Library{
MyDll INSTANCE = (MyDll) Native.loadLibrary("MyDll",MyDll.class);
public interface MyCallback extends StdCallCallback {
public boolean callback(String msg);
}
public int Start(MyCallback callback);
}
//in main:
...
MyDll myDll = (MyDll)MyDll.INSTANCE;
myDll.Start(new MyDll.MyCallback() {
public boolean callback(String msg) {
System.out.println(msg);
return true;
}
});
The output is numbers 0..41 (YES 41!!! not 99) and then "in Start called from Java" followed by a horrible crash:
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c809823, pid=468, tid=2636
#
# Java VM: Java HotSpot(TM) Client VM (10.0-b23 mixed mode, sharing windows-x86)
# Problematic frame:
# C [kernel32.dll+0x9823]
I've read alot (here as well) yet I cannot find the problem. I am running JRE of Java6. I have 1.5GB of memory on my machine. The DLL is not used by any other process (no concurrency issues).
Thanks, Azriel