I was trying to find out how JNA works, so I decided to use the specify API (libspotify 0.0.7). I managed to load my dll correctly, but then it looks like my code does not find any of the methods defined in the API.
Here is my code:
My main file:
public class Test{
private static final int SPOTIFY_API_VERSION = 7;
private static final char[] APP_KEY = { };
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);
}
}
My library interface:
public interface JLibspotify extends Library {
JLibspotify INSTANCE = (JLibspotify)Native.loadLibrary("libspotify", JLibspotify.class);
sp_error sp_session_create(sp_session_config config, sp_session sess);
}
My sp_session object (opaque C structure)
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;
public String cache_location;
public String settings_location;
public char[] application_key};
public int application_key_size;
public String user_agent;
public sp_session_callbacks callbacks;
public Pointer userdata;
public boolean compress_playlists;
public boolean dont_save_metadata_for_playlists;
public boolean initially_unload_playlists;
}
My sp_error enum
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
}
My exception stack trace
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)
Declaring a C ++ Method I'm Trying to Run
SP_LIBEXPORT(sp_error) sp_session_create(const sp_session_config *config, sp_session **sess);