Java + JNA : The specified procedure could not be found

时光怂恿深爱的人放手 提交于 2021-01-27 15:51:16

问题


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.

My interface:

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();


}

My Main class:

public class Test_Dll {

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

        simpleDll.function();
    }
}

My h file:

#ifndef SIMPLEDLL
#define SIMPLEDLL

namespace simpeDll{


    static void function();


}
#endif

My cpp file:

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

using namespace simpeDll;

static void function(){

}

回答1:


  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


来源:https://stackoverflow.com/questions/15398422/java-jna-the-specified-procedure-could-not-be-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!