Java + JNA:找不到指定的过程 [英] Java + JNA : The specified procedure could not be found

查看:412
本文介绍了Java + JNA:找不到指定的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Visual Studio创建一个dll文件,并在Java项目中使用/访问它.该库似乎已加载,但始终会引发相同的异常: 线程主"中的异常java.lang.UnsatisfiedLinkError:查找函数'function'时出错:找不到指定的过程. 我的C/C ++技能不是最好的,所以问题可能就在那里.我试图使用类,名称空间,静态方法和其他在Web上找到的人员来编辑h和cpp文件,但无所事事. 我也看到过其他有关Depency Walker Tool的文章,但是它无法打开我的dll,我还看到编译器在函数名称中添加了一些奇怪的后缀,因为我知道可以通过使用"estern"来避免它h或cpp文件中的"C"",但我无法.

I'm trying to create a dll file using visual studio and use/access it in a java project. The library seems to get loaded, but always the same exception is thrown: Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'function': The specified procedure could not be found. My C/C++ skills ar not the best so the problem could be there. I tried to edit h and cpp files, using classes, namespaces, static methods and other staff found on the web, but nothing to do. I have also seen other post talking about Depency Walker Tool, but it isn't able to open my dll, i also saw that the compiler add some strange suffixes to the function name, as i understood it's possible to avoid it by using "estern 'C'" in the h or cpp file, but i wasn't able.

我的界面:

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

public interface SimpleDll extends Library {

    SimpleDll instance = (SimpleDll) Native.loadLibrary("SimpleDll", SimpleDll.class);

    void function();


}

我的主班:

public class Test_Dll {

    public static void main(String[] args) {
        SimpleDll simpleDll = SimpleDll.instance;

        simpleDll.function();
    }
}

我的h文件:

#ifndef SIMPLEDLL
#define SIMPLEDLL

namespace simpeDll{


    static void function();


}
#endif

我的cpp文件:

#include "stdafx.h"
#include "simpleDll.h"
#include <stdexcept>

using namespace simpeDll;

static void function(){

}

推荐答案

  1. 确保在simpleDll命名空间之外声明函数.
  2. 确保使用extern "C"
  3. 装饰它
  4. 确保公开您的函数__declspec(dllexport) void __cdecl function();或使用模块定义文件
  1. Make sure declaring your function outside the simpleDll namespace.
  2. Make sure to decorate it w/ extern "C"
  3. Make sure exposing your function __declspec(dllexport) void __cdecl function(); or use module definition file

这篇关于Java + JNA:找不到指定的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆