English 中文(简体)
JNA: 无法找到具体程序
原标题:JNA: The specified procedure could not be found
  • 时间:2011-03-01 14:48:07
  •  标签:
  • java
  • api
  • jna

我正试图了解日本国家航空航天局是如何运作的,因此,我决定使用该示意图(使0.0.7)。 我设法正确地装载了我的炮弹,但与我的法典一样,我并不认为APIC中定义的任何方法。

我的守则是:

My main file:

public class Test{
    private static final int SPOTIFY_API_VERSION = 7;
private static final char[] APP_KEY = { /* MY APP KEY HERE */ };

    static{
        System.loadLibrary("libspotify");
    }

    public static void main(String[] args){
    JLibspotify libs = JLibspotify.INSTANCE;

    sp_session mySession = new sp_session();
    sp_session_config cfg = new sp_session_config();
    cfg.api_version = SPOTIFY_API_VERSION;
    cfg.cache_location = "tmp";
    cfg.settings_location = "tmp";
    cfg.application_key = APP_KEY;
    cfg.application_key_size = APP_KEY.length;
    cfg.user_agent = "spshell";
    cfg.callbacks = null;

    libs.sp_session_create(cfg, mySession);
}
}

public interface JLibspotify extends Library {  
    JLibspotify INSTANCE = (JLibspotify)Native.loadLibrary("libspotify", JLibspotify.class);

    // Methods definitions
    sp_error sp_session_create(sp_session_config config, sp_session sess);
}

www.un.org/Depts/DGACM/index_spanish.htm 我的间谍活动(opaque C sruct)

public class sp_session extends PointerType{
    public sp_session(Pointer address) {
        super(address);
    }
    public sp_session() {
        super();
    }
}

My sp_session_config object

public class sp_session_config extends Structure{
    public int api_version; // The version of the Spotify API your application is compiled with.
    public String cache_location;
    public String settings_location;
    public char[] application_key}; // Your application key.
    public int application_key_size; // The size of the application key in bytes
    public String user_agent;
    public sp_session_callbacks callbacks; // Delivery callbacks for session events. NULL if not interested in any callbacks
    public Pointer userdata; // User supplied data for your application
    public boolean compress_playlists;
    public boolean dont_save_metadata_for_playlists;
    public boolean initially_unload_playlists;
}

www.un.org/Depts/DGACM/index_spanish.htm 我的间谍活动

public enum sp_error {
    SP_ERROR_OK, 
    SP_ERROR_BAD_API_VERSION, 
    SP_ERROR_API_INITIALIZATION_FAILED, 
    SP_ERROR_TRACK_NOT_PLAYABLE, 
    SP_ERROR_RESOURCE_NOT_LOADED, 
    SP_ERROR_BAD_APPLICATION_KEY, 
    SP_ERROR_BAD_USERNAME_OR_PASSWORD, 
    SP_ERROR_USER_BANNED, 
    SP_ERROR_UNABLE_TO_CONTACT_SERVER, 
    SP_ERROR_CLIENT_TOO_OLD, 
    SP_ERROR_OTHER_PERMANENT, 
    SP_ERROR_BAD_USER_AGENT, 
    SP_ERROR_MISSING_CALLBACK, 
    SP_ERROR_INVALID_INDATA, 
    SP_ERROR_INDEX_OUT_OF_RANGE, 
    SP_ERROR_USER_NEEDS_PREMIUM, 
    SP_ERROR_OTHER_TRANSIENT, 
    SP_ERROR_IS_LOADING, 
    SP_ERROR_NO_STREAM_AVAILABLE, 
    SP_ERROR_PERMISSION_DENIED, 
    SP_ERROR_INBOX_IS_FULL, 
    SP_ERROR_NO_CACHE, 
    SP_ERROR_NO_SUCH_USER
}

www.un.org/Depts/DGACM/index_spanish.htm

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function  sp_session_create : The specified procedure could not be found.

at com.sun.jna.Function.<init>(Function.java:129)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:250)
at com.sun.jna.Library$Handler.invoke(Library.java:191)
at $Proxy0.sp_session_create(Unknown Source)
at com.nbarraille.jspotify.main.Test.main(Test.java:49)

www.un.org/Depts/DGACM/index_spanish.htm C++ 选择使用的方法

/**
 * Initialize a session. The session returned will be initialized, but you will need
 * to log in before you can perform any other operation
 *
 * Here is a snippet from c spshell.c:
 * @dontinclude spshell.c
 * @skip config.api_version
 * @until }
 *
 * @param[in]   config    The configuration to use for the session
 * @param[out]  sess      If successful, a new session - otherwise NULL
 *
 * @return                One of the following errors, from ::sp_error
 *                        SP_ERROR_OK
 *                        SP_ERROR_BAD_API_VERSION
 *                        SP_ERROR_BAD_USER_AGENT
 *                        SP_ERROR_BAD_APPLICATION_KEY
 *                        SP_ERROR_API_INITIALIZATION_FAILED
 */
SP_LIBEXPORT(sp_error) sp_session_create(const sp_session_config *config, sp_session **sess);
最佳回答

I finally found the solution by opening the libspotify.dll with Dependency Walker: The compiler added some extra information to the method name (a underscore prefix and a @4 or @8 suffix).

我不得不:

  • Create an implementation of FunctionMapper that renamed all my methods according to the real names (available in Dependency Walker)
  • Instantiate my Library with an instance of this mapper in the options map.
问题回答
    By the way, I don t have access to the definition of the sp_artist structure in C, I just reconstructed it based on the methods offered by the API, could it be the problem?

如果你不能够查阅,日本国家也不存在。 如果它属于不透明类别,则寻求设立、修改和删除它的职能。

另外,您在前面的发言中是否出现错误, Java变“艺术家”的五线定义?

/users/17175/technomage>@technomage /questions/5156055/jna-the-specised-procedure-could-not-be-found/5162171#comment9938104_5162171>>。 非常有益。 详情如下:

对于所有平台而言,接口可以保持不变:

Foo extends Library {
    void foo();
}

仅添加<代码> StdCallLibrary。 履历:

Map<String, ?> options = Collections.singletonMap(
    Library.OPTION_FUNCTION_MAPPER,
    StdCallLibrary.FUNCTION_MAPPER
);
Foo proxy = Native.loadLibrary("foo", Foo.class, options);

我在Windows 7 32-bit上与JNA 4.5.1合著,MacOS 10.13.2, Unbuntulav 16.04 64-bit。 我已经对其他平台进行了测试,我没有亲自汇编本地图书馆,因此你的里程可能有所不同。


详情如下:

最初,我的接口就是这样:

Foo extends Library {
    void foo();
}

我试图将土著图书馆装上这样的图书馆:

Native.loadLibrary("foo", Foo.class);

在Mac和Holt开展工作,但不在Windows 7 32-bit:Error 查询功能 f: 具体程序无法找到。

因此,我改变了我的接口:

Foo extends StdCallLibrary {
    void foo();
}

and I tried to load the library with the stdcall specific function mapper:

Map<String, ?> options = Collections.singletonMap(
    Library.OPTION_FUNCTION_MAPPER,
    StdCallLibrary.FUNCTION_MAPPER
);
Foo proxy = Native.loadLibrary("foo", Foo.class, options);

如今,它一直在Windows 7 32-bit上工作,但并未在Mac或lin上工作:未经承认的电话公约:63:-

我认为,每座平台都需要一条不同的密码途径,甚至可以添加<条码>:Library或<条码>StdCallLibrary动态接口(加上另一个<条码>Proxy),但我发现我们可以有午餐,吃饭! 见上文。

我不敢肯定,尽管这种特殊行为是由日本国家武装部队确定的,或者是一种随着日本国家武装部队的下一次释放而可能发生变化的uck事故。 不管怎么说,这对我来说是好的。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...