Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在windows下传递回调(无效内存访问)时JNA崩溃_Java_C++_Windows_Jna_Calling Convention - Fatal编程技术网

Java 在windows下传递回调(无效内存访问)时JNA崩溃

Java 在windows下传递回调(无效内存访问)时JNA崩溃,java,c++,windows,jna,calling-convention,Java,C++,Windows,Jna,Calling Convention,我获得了以下代码,通过JNA将自定义dll嵌入到我们的Java代码中: public interface MyLibrary extends Library { MyLibrary INSTANCE = (MyLibrary) Native.loadLibrary("my_helper", MyLibrary.class); interface render_t extends Callback { void callback(int id, int type

我获得了以下代码,通过JNA将自定义dll嵌入到我们的Java代码中:

public interface MyLibrary extends Library {
    MyLibrary INSTANCE = (MyLibrary) Native.loadLibrary("my_helper",  MyLibrary.class);

    interface render_t extends Callback {
        void callback(int id, int type, int dirty_rects_lenght, Pointer dirty_rects, Pointer buffer, int width, int height);
    }

    int init();
    int createApp(String param, render_t callback);
}
和此头文件:

extern __declspec(dllexport) int __cdecl init(void);

struct rect_t {
    int x;
    int y;
    int width;
    int height;
};

typedef void (__cdecl *render_t) (int id, int type, int dirty_rects_lenght, void* dirty_rects, const void *buffer, int width, int height);
extern __declspec(dllexport) int __cdecl createApp(char *param, render_t render_callback);
该代码在linux和osx下运行良好。DLL使用msvc正确构建,dumpbin也显示所有导出。对于JNA,init调用正在工作,但一旦我们调用回调函数“createApp”,它就会崩溃,内存访问无效。我假设这是因为JNA传递的回调的调用约定,但我不知道如何更改这种调用约定。我已经尝试将所有的cdecl转换为stdcall,以使用Windows调用约定,并且还将JNA的库和回调接口分别更改为stdcalllibrary和stdcallcallback,但它会产生相同的错误

操作系统:Windows 8.1 x64, 爪哇:8 x64,, JNA:4.1.0

堆栈跟踪:

Exception in thread "main": java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:383)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212) <1 internal calls>
at mp.app.MyApp.<init>(MyApp.java:34)
线程“main”中出现异常:java.lang.Error:内存访问无效 位于com.sun.jna.Native.invokeInt(本机方法) 位于com.sun.jna.Function.invoke(Function.java:383) 位于com.sun.jna.Function.invoke(Function.java:315) 位于com.sun.jna.Library$Handler.invoke(Library.java:212) 在mp.app.MyApp.(MyApp.java:34)
能否包含jvm堆栈转储?尝试向
init
函数添加一个伪参数。这会让它失败吗?谢谢你的帮助!将伪参数应用于init时,它仍然有效。此外,即使返回void,createApp也失败了。正在处理jvm堆栈转储。。