B4J Question Where to put .dll used in LoadLibary() in library?

Discussion in 'B4J Questions' started by alwaysbusy, Apr 1, 2014.

  1. alwaysbusy

    alwaysbusy Expert Licensed User

    I'm writing a library that uses an external dll (ThinkGear.dll). In the eclipse library it is used as:

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

    No problems so far. When I now run it, I'll get the following error:

    Code:
    java.lang.ExceptionInInitializerError
    Caused by: java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: no thinkgear 
    in java.library.path
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    113)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    82)
        at b4j.example.main.<clinit>(main.java:
    16)
    Caused by: java.lang.UnsatisfiedLinkError: no thinkgear 
    in java.library.path
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:
    1886)
        at java.lang.Runtime.loadLibrary0(Runtime.java:
    849)
        at java.lang.System.loadLibrary(System.java:
    1088)
        at com.AB.ABThinkGear.ABThinkGear.<clinit>(ABThinkGear.java:
    12)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:
    190)
        at anywheresoftware.b4a.shell.Shell.getCorrectClassName(
    Shell.java:451)
        at anywheresoftware.b4a.shell.Shell.createObject(
    Shell.java:438)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:239)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:156)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.lang.reflect.Method.invoke(Method.java:
    606)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    93)
        ... 
    2 more
    Exception in thread "main"
    Makes sense, I haven't put the dll anywhere. I would suspect it needs to be in the \B4J\Objects\shell\bin\classes\b4j\example folder. I made it read only, but then I can't compile the project anymore.

    [​IMG]


    Is there a special folder I can use?

    Cheers,

    Alain
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Try this:
    Put the file in the Objects folder. This is equivalent to File.DirApp.

    Now call
    Code:
    System.load(anywheresoftware.b4a.objects.streams.File.getDirApp & "/thinkgear.dll"); //load not loadLibrary.
     
    eps likes this.
  3. alwaysbusy

    alwaysbusy Expert Licensed User

    Closer, but no sigar!

    I can compile, but not run:

    Code:
    Program started.
    java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: com.AB.ABThinkGear.ABThinkGear.TG_GetDriverVersion()I
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    113)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    82)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    84)
        at b4j.example.main.start(main.java:
    35)
        at com.sun.javafx.application.LauncherImpl$
    5.run(LauncherImpl.java:319)
        at com.sun.javafx.application.PlatformImpl$
    5.run(PlatformImpl.java:219)
        at com.sun.javafx.application.PlatformImpl$
    4$1.run(PlatformImpl.java:182)
        at com.sun.javafx.application.PlatformImpl$
    4$1.run(PlatformImpl.java:179)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl$
    4.run(PlatformImpl.java:179)
        at com.sun.glass.ui.InvokeLaterDispatcher$
    Future.run(InvokeLaterDispatcher.java:76)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.access$
    100(WinApplication.java:17)
        at com.sun.glass.ui.win.WinApplication$
    3$1.run(WinApplication.java:67)
        at java.lang.Thread.run(
    Thread.java:744)
    Caused by: java.lang.UnsatisfiedLinkError: com.AB.ABThinkGear.ABThinkGear.TG_GetDriverVersion()I
        at com.AB.ABThinkGear.ABThinkGear.TG_GetDriverVersion(Native Method)
        at com.AB.ABThinkGear.ABThinkGear.GetDriverVersion(ABThinkGear.java:
    95)
        at b4j.example.main._appstart(main.java:
    74)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.lang.reflect.Method.invoke(Method.java:
    606)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:558)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:224)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:156)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.lang.reflect.Method.invoke(Method.java:
    606)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    93)
        ... 
    14 more
    Attached is the B4J project and the java library project. In my view, this should be a very simple 'wrap'. The GetDriverVersion() function shuold work without having the hardware. I did this wrapper in Xojo (using declares) but thought this could be a grood project to test out B4J :)

    Cheers,

    Alain
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

  5. alwaysbusy

    alwaysbusy Expert Licensed User

    I found several versions around. I think this one is based on the Official SDK of NeuroSky.

    Here are some versions I have:

    ThinkGear1: using jna to access the dll (could not get it working as it had problems finding the jna lib)
    ThinkGear2: The official one I based mine on
    ThinkGearSocket3: The one using sockets (like you suggested), written for Processing (is java like)

    I was just trying it out like this at it seemed straightforward (and very similar to use as the xojo one). But I guess I will have to try to get a go with the third option anyway.
     

    Attached Files:

  6. Thuong

    Thuong Member Licensed User

    Dear
    I code static { System.load("/thinkgear.dll"); } and compile is ok to B4A library
    It is correct ?
     
  7. alwaysbusy

    alwaysbusy Expert Licensed User

    No. B4A cannot work with Windows dlls. This was me trying to build a library for B4J, but I've never got it working. For B4A, you'll need the code I've PM'ed you, using the .jar files. 'see the @DependsOn()' lines.
     
  8. lindomar

    lindomar Member Licensed User

    I'm having the same problem to load a DLL library...
    Can you help me?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    You cannot work directly with dlls. You need to create a Java wrapper that will call the native dll with jni calls.
     
  10. lindomar

    lindomar Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice