读书人

急关于JNative的有关问题在线求等解

发布时间: 2012-03-08 13:30:13 作者: rapoo

急!关于JNative的问题,在线求等大虾解决!!!!
我用JNative调用dll里面的方法的问题,dll里有3个方法
extern "C" __declspec(dllexport) int __stdcall Calc(int a, int b) //导出函数
{
return a+b;
}
这个方法可以成功调用
调用代码

Java code
public int Max(int a,int b){        JNative n = null;        try {            n = new JNative("Project1.dll", "Calc");            n.setRetVal(Type.INT);            // 设置参数            int i = 0;            n.setParameter(i++, Type.INT, a + "");            n.setParameter(i++, Type.INT, b + "");            n.invoke();            return Integer.parseInt(n.getRetVal());        } catch (NativeException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (IllegalAccessException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }finally{            if(n != null){                try {                    n.dispose();                } catch (NativeException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                } catch (IllegalAccessException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                }            }        }        return 0;    }

但是调用dll里的其他方法时候控制台出现这个

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c92ebd1, pid=4820, tid=4344
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_16-b02 mixed mode, sharing)
# Problematic frame:
# C [ntdll.dll+0xebd1]
#
# An error report file with more information is saved as hs_err_pid4820.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
不知道为什么
这个dll里的方法如下
extern "C" __declspec(dllexport) int __stdcall ToPC(String AppPath) //导出函数
{
//String AppPath = ExtractFilePath(Application->ExeName);
int com = 0;

//String fname = AppPath + "receive";
// readTxt();

ShowMessage(AppPath);

int i = dt900comm(com,AppPath.c_str(),2,0); // 采集器文件传输到电脑
return i;
}
java调用方法如下:
Java code
public int topc(){        JNative n = null;        try {            //设置c++里的对应函数            n = new JNative("Project1.dll", "ToPC");            //设置返回类型            n.setRetVal(Type.INT);            // 设置参数            int i = 0;                        n.setParameter(i++, "c:\\");            n.invoke();            return Integer.parseInt(n.getRetVal());        } catch (NativeException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (IllegalAccessException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }finally{            if(n != null){                try {                    n.dispose();                } catch (NativeException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                } catch (IllegalAccessException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                }            }        }        return 0;    }

调用第二个就抱那个,不知道为什么,请问谁帮帮忙啊,很急啊!今天就得交

[解决办法]
帮顶
[解决办法]
dll 里面的那个参数String类型 改成char* 试试看

读书人网 >J2EE开发

热点推荐