当前位置: 代码迷 >> J2SE >> 求jna调用so可以返回struct的实例。不甚感激!小弟我的老是报jvm crash,请
  详细解决方案

求jna调用so可以返回struct的实例。不甚感激!小弟我的老是报jvm crash,请

热度:10321   发布时间:2013-02-25 00:00:00.0
求jna调用so可以返回struct的实例。不甚感激!我的老是报jvm crash,请高手指点!
我的老是报jvm crash,请高手指点!

1、mymd5.c
#include "mymd5.h"
//struct stmymd5 getMyMd5(struct starg srg)
struct stmymd5 getMyMd5()

struct stmymd5 st;
st.retcode = 88;
st.mymd5 = "hello yyyyyy";

return st;


2、mymd5.h

#include <stdio.h>
#include <stdlib.h>

struct stmymd5
{
    int retcode; 
};

struct stmymd5 getMyMd5();


3、TestSo.java

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Structure;


public class TestSo{
    public interface LgetLib extends Library {
        
        LgetLib INSTANCE = (LgetLib) Native.loadLibrary("mystruct", LgetLib.class);
 
        public  MyMd5Struct getMyMd5();
    }

    public static class MyMd5Struct extends Structure
    {
       public int retcode; 
       public static class ByValue extends MyMd5Struct implements Structure.ByValue { }
       public static class ByReference extends MyMd5Struct implements Structure.ByReference { }
    }  


    public  MyMd5Struct getMyMd5(){       
        return LgetLib.INSTANCE.getMyMd5();
    }


public static void main(String[] args) {

    MyMd5Struct myMd5Struct = LgetLib.INSTANCE.getMyMd5();
System.out.println("get retcode = " + myMd5Struct.retcode);


    }
}
看不懂啊,怎么看啊,指点一下呗:

#
# An unexpected error has been detected by HotSpot Virtual Machine:围观帮顶报错如下:
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  SIGSEGV (0xb) at pc=0x6df764b1, pid=27654, tid=3086923456
#
# Java VM: Java HotSpot(TM) Server VM (1.5.0_16-b02 mixed mode)
# Problematic frame:
# C  [jna58332.tmp+0xe4b1]  ffi_call+0x75
#
# An error report file with more information is saved as hs_err_pid27654.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#
Aborted An error report file with more information is saved as hs_err_pid27654.log

lz看看这个日志文件
  相关解决方案