简体   繁体   中英

Java + JNA : The specified procedure could not be found

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM