JNA - Access Violation, JVM Terminals

I call the DLL by passing it a functio callback object. One feature is simple printing. Then I have a loop of 100 iterations, just printing an index and a few fingerprints 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 the numbers 0..41 (YES 41 !!! not 99), and then "in Start, called from Java", followed by a terrible failure:

#
# 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 read a lot (here too), but I cannot find the problem. I am running Java6 JRE. I have 1.5 GB of memory on my machine. DLL is not used by any other process (no concurrency problems).

Thanks Azriel

+3
source share
2 answers

MyCallback com.sun.jna.Callback com.sun.jna.win32.StdCallLibrary.StdCallCallback:

public interface MyDll extends Library{
  MyDll INSTANCE = (MyDll) Native.loadLibrary("MyDll",MyDll.class);
     public interface MyCallback extends Callback {
            public boolean callback(String msg);
     }
     public int Start(MyCallback callback);
  }

,

+4

win32 dll .

com.sun.jna.Library com.sun.jna.Callback, .

com.sun.jna.win32.StdCallLibrary com.sun.jna.win32.StdCallLibrary.StdCallCallback .

+2

Source: https://habr.com/ru/post/1714070/


All Articles