Hi, I've been trying to use Bass Sound Engine in my projects as the audio library, so I've started coding the JNA wrapper for it. But after trying with only Init, Free and Play functions it just can't find the DLL.
So, I've tried running my old JNA project using DLLs that actually worked before. No luck, same story - "java.lang.UnsatisfiedLinkError: Unable to load library".
I've tried for about 4 hours today to get it working, but still, no luck.
Here is my code:
package pl.org.shocker.lib39dll; import com.sun.jna.Library; import com.sun.jna.Native; interface JNALib extends Library { JNALib lib = (JNALib)Native.loadLibrary("39dll",JNALib.class); double tcpconnect(String ip, double port, double mode); double tcplisten(double port, double maxClients, double mode); double tcpaccept(double sockID, double mode); double udpconnect(double port, double mode); double closesock(double sockID); double sockstart(); double sockexit(); double socklasterror(double sockID); double getsocketid(double sockID); String tcpip(double sockID); double setnagle(double sockID, double value); double tcpconnected(double sockID); double setformat(double sockID, double mode, String separator); String lastinIP(); double lastinPort(); double setsync(double sockID, double mode); String myhost(); String hostip(String host); double compareip(String ip, String mask); double sendmessage(double sockID, String ip, double port, double bufID); double receivemessage(double sockID, double len, double bufID); double peekmessage(double sockID, double len, double bufID); double writebyte(double val, double bufID); double writeshort(double val, double bufID); double writeushort(double val, double bufID); double writeint(double val, double bufID); double writeuint(double val, double bufID); double writefloat(double val, double bufID); double writedouble(double val, double bufID); double writechars(String string, double bufID); double writestring(String string, double bufID); double readbyte(double bufID); double readshort(double bufID); double readushort(double bufID); double readint(double bufID); double readuint(double bufID); double readfloat(double bufID); double readdouble(double bufID); String readchars(double len, double bufID); String readstring(double bufID); String readsep(String separator, double bufID); double getpos(double pos, double bufID); double clearbuffer(double bufID); double buffsize(double bufID); double setpos(double pos, double bufID); double bytesleft(double bufID); double createbuffer(); double freebuffer(double bufID); double copybuffer(double destID, double srcID); double copybuffer2(double destID, double start, double len, double srcID); String getmacaddress(); String md5string(String string); String md5buffer(double bufID); double bufferencrypt(String pass, double bufID); double adler32(double bufID); double bufferexists(double bufID); double netconnected(); double fileopen(String name, double mode); double fileclose(double fileID); double filewrite(double fileID, double bufID); double fileread(double fileID, double bytes, double bufID); double filepos(double fileID); double filesetpos(double fileID, double pos); double filesize(double fileID); double iptouint(String ip); String uinttoip(double uint); }package pl.org.shocker.lib39dll; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.BitSet; public class Lib39dll { static boolean init = false; static ArrayList<Buffer> buffers = new ArrayList<Buffer>(); static ArrayList<LibFile> files = new ArrayList<LibFile>(); private static final File pathTemp = new File(System.getProperty("java.io.tmpdir")); static { System.setProperty("jna.library.path",new File(System.getProperty("java.io.tmpdir")).getAbsolutePath()); File f = new File(pathTemp,"39dll.dll"); f.deleteOnExit(); } public static void libInit() { if (init) return; copy("39dll.dll",new File(pathTemp,"39dll.dll")); JNALib.lib.sockstart(); init = true; } public static void libDeinit() { if (!init) return; try { for (int i = 0; i < buffers.size(); i++) buffers.get(i).free(); for (int i = 0; i < files.size(); i++) files.get(i).close(); } catch (Lib39dllException e) {} JNALib.lib.sockexit(); init = false; } public static boolean libIsInit() throws Lib39dllException { if (!init) throw new Lib39dllException("Not initialized"); return true; } public static boolean netConnected() throws Lib39dllException { libIsInit(); return JNALib.lib.netconnected() == 1 ? true : false; } public static String myHost() throws Lib39dllException { libIsInit(); return JNALib.lib.myhost(); } public static String myMAC() throws Lib39dllException { libIsInit(); return JNALib.lib.getmacaddress(); } public static boolean matchesIP(String ip, String mask) throws Lib39dllException { libIsInit(); return JNALib.lib.compareip(ip,mask) == 1 ? true : false; } public static String hostIP(String host) throws Lib39dllException { libIsInit(); return JNALib.lib.hostip(host); } public static long ip2uint(String ip) throws Lib39dllException { libIsInit(); return (long)JNALib.lib.iptouint(ip); } public static String uint2ip(long uint) throws Lib39dllException { libIsInit(); return JNALib.lib.uinttoip(uint); } public static boolean bufferExists(Buffer buffer) throws Lib39dllException { return buffer.exists(); } public static boolean bufferExists(int bufID) throws Lib39dllException { libIsInit(); return JNALib.lib.bufferexists(bufID) == 1 ? true : false; } public static String md5(String str) throws Lib39dllException { libIsInit(); return JNALib.lib.md5string(str); } public static String md5(Buffer buf) throws Lib39dllException { return buf.md5(); } public static BitSet getBitSet(int val) { BitSet bs = new BitSet(8); for (int i = 0; i < 8; i++) if ((val & (int)Math.pow(2,i)) > 0) bs.set(i); return bs; } public static int getByte(BitSet bs) { int value = 0; for (int i = 0; i < 8; i++) if (bs.get(i)) value += Math.pow(2,i); return value; } private static void copy(String fname, File path) { try { InputStream in = Lib39dll.class.getClassLoader().getResourceAsStream(fname); FileOutputStream out = new FileOutputStream(path); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) out.write(buf,0,len); in.close(); out.close(); } catch (Exception e) {e.printStackTrace();} } }import pl.org.shocker.lib39dll.Lib39dll; public class App { public static void main(String[] args) { Lib39dll.libInit(); Lib39dll.libDeinit(); } }
And the error I get:
And the old code that worked before (but now isn't working):Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library '39dll': Nie mo?na odnale?? okre?lonego modu?
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrar y.java:166)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrar y.java:239)
at com.sun.jna.Library$Handler.<init>(Library.java:14 0)
at com.sun.jna.Native.loadLibrary(Native.java:393)
at com.sun.jna.Native.loadLibrary(Native.java:378)
at pl.org.shocker.lib39dll.JNALib.<clinit>(JNALib.jav a:7)
at pl.org.shocker.lib39dll.Lib39dll.libInit(Lib39dll. java:25)
at App.main(App.java:5)
package pl.org.shocker.lib39dll; import com.sun.jna.Library; import com.sun.jna.Native; interface JNALib extends Library { JNALib lib = (JNALib)Native.loadLibrary("39dll",JNALib.class); double tcpconnect(String ip, double port, double mode); double tcplisten(double port, double maxClients, double mode); double tcpaccept(double sockID, double mode); double udpconnect(double port, double mode); double closesock(double sockID); double sockstart(); double sockexit(); double socklasterror(double sockID); double getsocketid(double sockID); String tcpip(double sockID); double setnagle(double sockID, double value); double tcpconnected(double sockID); double setformat(double sockID, double mode, String separator); String lastinIP(); double lastinPort(); double setsync(double sockID, double mode); String myhost(); String hostip(String host); double compareip(String ip, String mask); double sendmessage(double sockID, String ip, double port, double bufID); double receivemessage(double sockID, double len, double bufID); double peekmessage(double sockID, double len, double bufID); double writebyte(double val, double bufID); double writeshort(double val, double bufID); double writeushort(double val, double bufID); double writeint(double val, double bufID); double writeuint(double val, double bufID); double writefloat(double val, double bufID); double writedouble(double val, double bufID); double writechars(String string, double bufID); double writestring(String string, double bufID); double readbyte(double bufID); double readshort(double bufID); double readushort(double bufID); double readint(double bufID); double readuint(double bufID); double readfloat(double bufID); double readdouble(double bufID); String readchars(double len, double bufID); String readstring(double bufID); String readsep(String separator, double bufID); double getpos(double pos, double bufID); double clearbuffer(double bufID); double buffsize(double bufID); double setpos(double pos, double bufID); double bytesleft(double bufID); double createbuffer(); double freebuffer(double bufID); double copybuffer(double destID, double srcID); double copybuffer2(double destID, double start, double len, double srcID); String getmacaddress(); String md5string(String string); String md5buffer(double bufID); double bufferencrypt(String pass, double bufID); double adler32(double bufID); double bufferexists(double bufID); double netconnected(); double fileopen(String name, double mode); double fileclose(double fileID); double filewrite(double fileID, double bufID); double fileread(double fileID, double bytes, double bufID); double filepos(double fileID); double filesetpos(double fileID, double pos); double filesize(double fileID); double iptouint(String ip); String uinttoip(double uint); } package pl.org.shocker.lib39dll; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.BitSet; import com.sun.jna.NativeLibrary; public class Lib39dll { static boolean init = false; static ArrayList<Buffer> buffers = new ArrayList<Buffer>(); static ArrayList<LibFile> files = new ArrayList<LibFile>(); private static File pathTemp; static { File f = new File(pathTemp,"39dll.dll"); f.deleteOnExit(); } public static void libInit() { if (init) return; pathTemp = new File(System.getProperty("java.io.tmpdir")); NativeLibrary.addSearchPath("39dll",pathTemp.getParentFile().getAbsolutePath()); try { InputStream in = Lib39dll.class.getClassLoader().getResourceAsStream("39dll.dll"); FileOutputStream out = new FileOutputStream(new File(pathTemp,"39dll.dll")); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) out.write(buf,0,len); in.close(); out.close(); } catch (FileNotFoundException e) {e.printStackTrace(); } catch (IOException e) {e.printStackTrace();} JNALib.lib.sockstart(); init = true; } public static void libDeinit() { if (!init) return; try { for (int i = 0; i < buffers.size(); i++) buffers.get(i).free(); for (int i = 0; i < files.size(); i++) files.get(i).close(); } catch (Lib39dllException e) {} JNALib.lib.sockexit(); init = false; } public static boolean libIsInit() throws Lib39dllException { if (!init) throw new Lib39dllException("Not initialized"); return true; } public static boolean netConnected() throws Lib39dllException { libIsInit(); return JNALib.lib.netconnected() == 1 ? true : false; } public static String myHost() throws Lib39dllException { libIsInit(); return JNALib.lib.myhost(); } public static String myMAC() throws Lib39dllException { libIsInit(); return JNALib.lib.getmacaddress(); } public static boolean matchesIP(String ip, String mask) throws Lib39dllException { libIsInit(); return JNALib.lib.compareip(ip,mask) == 1 ? true : false; } public static String hostIP(String host) throws Lib39dllException { libIsInit(); return JNALib.lib.hostip(host); } public static long ip2uint(String ip) throws Lib39dllException { libIsInit(); return (long)JNALib.lib.iptouint(ip); } public static String uint2ip(long uint) throws Lib39dllException { libIsInit(); return JNALib.lib.uinttoip(uint); } public static boolean bufferExists(Buffer buffer) throws Lib39dllException { return buffer.exists(); } public static boolean bufferExists(int bufID) throws Lib39dllException { libIsInit(); return JNALib.lib.bufferexists(bufID) == 1 ? true : false; } public static String md5(String str) throws Lib39dllException { libIsInit(); return JNALib.lib.md5string(str); } public static String md5(Buffer buf) throws Lib39dllException { return buf.md5(); } public static BitSet getBitSet(int val) { BitSet bs = new BitSet(8); for (int i = 0; i < 8; i++) if ((val & (int)Math.pow(2,i)) > 0) bs.set(i); return bs; } public static int getByte(BitSet bs) { int value = 0; for (int i = 0; i < 8; i++) if (bs.get(i)) value += Math.pow(2,i); return value; } }
What's wrong?