Results 1 to 2 of 2
  1. #1
    comsci is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Question Java Native Access (JNA) to Windows DLL behaviour does not match C Exe behaviour.

    I have been struggling with this for more than a day now...

    I have a Windows C++ SDK dll that I wish to access from Java. To do this I wrote a simple C wrapper library for it and access this using JNA. Reasonably straightforward I thought, but whilst I can access and initialise the SDK from C when I try to do the same from Java it fails.

    I've tried to rule out any JNA mapping issues and am certain that my C library is being called from Java by reducing the problem to the smallest possible size:-

    So my library has just one call that takes no parameters and returns nothing but prints the number of video channels detected:

    void initSDK();

    My C exe is just:-

    Java Code:
    #include "MPEGIO2CLib.h"
    
    int main(int argc, char** argv) {
    
        initSDK();
        
        return (0);
    }
    My Java App is

    Java Code:
    package mpegio2javatest;
    
    import com.sun.jna.Library;
    import com.sun.jna.Native;
    
    public class MPEGIO2JavaTest {
    
        public interface MPEGIO2CLib extends Library {
    
            MPEGIO2CLib INSTANCE = (MPEGIO2CLib) Native.loadLibrary("MPEGIO2CLib", MPEGIO2CLib.class);
    
            public void initSDK();
        }
    
        public static void main(String[] args) {
    
            MPEGIO2CLib mpegio2 = MPEGIO2CLib.INSTANCE;
            
            mpegio2.initSDK();
           
        }
    }
    I've created a C .exe and a Java jar file and have tried running both of them from the command line in a user directory with all the required SDK dlls and init files. The SDK performs some low level stuff to interrogate the PCI bus and initialise any suitable hardware detected. I think it reads a few ini files from the current directory and possibly also requires write access to them. The C .exe succeeds but the Java jar appears to be going through the motions but fails halfway through the initialisation without any meaningful error. Just 0 video channels detected.

    I've exhausted almost everything I can think of and can only assume it must be something to do with different permissions or privileges for a C .exe c.f. a Java jar.

    Anyone shed any light on this or suggest other things to try, please?

    I've attached the Java -verbose:jni -Xdiag log below if that helps anyone.

  2. #2
    comsci is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Default Re: Java Native Access (JNA) to Windows DLL behaviour does not match C Exe behaviour.

    Here's the debug output:


    C:\Users\MPR\dist>java -verbose:jni -Xdiag -jar MPEGIO2JavaTest.jar
    [Dynamic-linking native method java.lang.Object.registerNatives ... JNI]
    [Registering JNI native method java.lang.Object.hashCode]
    [Registering JNI native method java.lang.Object.wait]
    [Registering JNI native method java.lang.Object.notify]
    [Registering JNI native method java.lang.Object.notifyAll]
    [Registering JNI native method java.lang.Object.clone]
    [Dynamic-linking native method java.lang.System.registerNatives ... JNI]
    [Registering JNI native method java.lang.System.currentTimeMillis]
    [Registering JNI native method java.lang.System.nanoTime]
    [Registering JNI native method java.lang.System.arraycopy]
    [Dynamic-linking native method java.lang.System.identityHashCode ... JNI]
    [Dynamic-linking native method java.lang.Thread.registerNatives ... JNI]
    [Registering JNI native method java.lang.Thread.start0]
    [Registering JNI native method java.lang.Thread.stop0]
    [Registering JNI native method java.lang.Thread.isAlive]
    [Registering JNI native method java.lang.Thread.suspend0]
    [Registering JNI native method java.lang.Thread.resume0]
    [Registering JNI native method java.lang.Thread.setPriority0]
    [Registering JNI native method java.lang.Thread.yield]
    [Registering JNI native method java.lang.Thread.sleep]
    [Registering JNI native method java.lang.Thread.currentThread]
    [Registering JNI native method java.lang.Thread.countStackFrames]
    [Registering JNI native method java.lang.Thread.interrupt0]
    [Registering JNI native method java.lang.Thread.isInterrupted]
    [Registering JNI native method java.lang.Thread.holdsLock]
    [Registering JNI native method java.lang.Thread.getThreads]
    [Registering JNI native method java.lang.Thread.dumpThreads]
    [Registering JNI native method java.lang.Thread.setNativeName]
    [Dynamic-linking native method java.security.AccessController.getStackAccessContr olContext ... JNI]
    [Dynamic-linking native method java.security.AccessController.getInheritedAccessC ontrolContext ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader.registerNatives ... JNI]
    [Registering JNI native method java.lang.ClassLoader.retrieveDirectives]
    [Dynamic-linking native method java.security.AccessController.doPrivileged ... JNI]
    [Dynamic-linking native method java.lang.Class.registerNatives ... JNI]
    [Registering JNI native method java.lang.Class.getName0]
    [Registering JNI native method java.lang.Class.getSuperclass]
    [Registering JNI native method java.lang.Class.getInterfaces]
    [Registering JNI native method java.lang.Class.getClassLoader0]
    [Registering JNI native method java.lang.Class.isInterface]
    [Registering JNI native method java.lang.Class.getSigners]
    [Registering JNI native method java.lang.Class.setSigners]
    [Registering JNI native method java.lang.Class.isArray]
    [Registering JNI native method java.lang.Class.isPrimitive]
    [Registering JNI native method java.lang.Class.getComponentType]
    [Registering JNI native method java.lang.Class.getModifiers]
    [Registering JNI native method java.lang.Class.getDeclaredFields0]
    [Registering JNI native method java.lang.Class.getDeclaredMethods0]
    [Registering JNI native method java.lang.Class.getDeclaredConstructors0]
    [Registering JNI native method java.lang.Class.getProtectionDomain0]
    [Registering JNI native method java.lang.Class.setProtectionDomain0]
    [Registering JNI native method java.lang.Class.getDeclaredClasses0]
    [Registering JNI native method java.lang.Class.getDeclaringClass]
    [Registering JNI native method java.lang.Class.getGenericSignature]
    [Registering JNI native method java.lang.Class.getRawAnnotations]
    [Registering JNI native method java.lang.Class.getConstantPool]
    [Registering JNI native method java.lang.Class.desiredAssertionStatus0]
    [Registering JNI native method java.lang.Class.getEnclosingMethod0]
    [Dynamic-linking native method sun.misc.Unsafe.registerNatives ... JNI]
    [Registering JNI native method sun.misc.Unsafe.getLoadAverage]
    [Dynamic-linking native method java.lang.Throwable.fillInStackTrace ... JNI]
    [Registering JNI native method sun.misc.Unsafe.copyMemory]
    [Registering JNI native method sun.misc.Unsafe.setMemory]
    [Registering JNI native method sun.misc.Unsafe.defineAnonymousClass]
    [Registering JNI native method sun.misc.Unsafe.getObject]
    [Registering JNI native method sun.misc.Unsafe.putObject]
    [Registering JNI native method sun.misc.Unsafe.getObjectVolatile]
    [Registering JNI native method sun.misc.Unsafe.putObjectVolatile]
    [Registering JNI native method sun.misc.Unsafe.getBoolean]
    [Registering JNI native method sun.misc.Unsafe.putBoolean]
    [Registering JNI native method sun.misc.Unsafe.getBooleanVolatile]
    [Registering JNI native method sun.misc.Unsafe.putBooleanVolatile]
    [Registering JNI native method sun.misc.Unsafe.getByte]
    [Registering JNI native method sun.misc.Unsafe.putByte]
    [Registering JNI native method sun.misc.Unsafe.getByteVolatile]
    [Registering JNI native method sun.misc.Unsafe.putByteVolatile]
    [Registering JNI native method sun.misc.Unsafe.getShort]
    [Registering JNI native method sun.misc.Unsafe.putShort]
    [Registering JNI native method sun.misc.Unsafe.getShortVolatile]
    [Registering JNI native method sun.misc.Unsafe.putShortVolatile]
    [Registering JNI native method sun.misc.Unsafe.getChar]
    [Registering JNI native method sun.misc.Unsafe.putChar]
    [Registering JNI native method sun.misc.Unsafe.getCharVolatile]
    [Registering JNI native method sun.misc.Unsafe.putCharVolatile]
    [Registering JNI native method sun.misc.Unsafe.getInt]
    [Registering JNI native method sun.misc.Unsafe.putInt]
    [Registering JNI native method sun.misc.Unsafe.getIntVolatile]
    [Registering JNI native method sun.misc.Unsafe.putIntVolatile]
    [Registering JNI native method sun.misc.Unsafe.getLong]
    [Registering JNI native method sun.misc.Unsafe.putLong]
    [Registering JNI native method sun.misc.Unsafe.getLongVolatile]
    [Registering JNI native method sun.misc.Unsafe.putLongVolatile]
    [Registering JNI native method sun.misc.Unsafe.getFloat]
    [Registering JNI native method sun.misc.Unsafe.putFloat]
    [Registering JNI native method sun.misc.Unsafe.getFloatVolatile]
    [Registering JNI native method sun.misc.Unsafe.putFloatVolatile]
    [Registering JNI native method sun.misc.Unsafe.getDouble]
    [Registering JNI native method sun.misc.Unsafe.putDouble]
    [Registering JNI native method sun.misc.Unsafe.getDoubleVolatile]
    [Registering JNI native method sun.misc.Unsafe.putDoubleVolatile]
    [Registering JNI native method sun.misc.Unsafe.getByte]
    [Registering JNI native method sun.misc.Unsafe.putByte]
    [Registering JNI native method sun.misc.Unsafe.getShort]
    [Registering JNI native method sun.misc.Unsafe.putShort]
    [Registering JNI native method sun.misc.Unsafe.getChar]
    [Registering JNI native method sun.misc.Unsafe.putChar]
    [Registering JNI native method sun.misc.Unsafe.getInt]
    [Registering JNI native method sun.misc.Unsafe.putInt]
    [Registering JNI native method sun.misc.Unsafe.getLong]
    [Registering JNI native method sun.misc.Unsafe.putLong]
    [Registering JNI native method sun.misc.Unsafe.getFloat]
    [Registering JNI native method sun.misc.Unsafe.putFloat]
    [Registering JNI native method sun.misc.Unsafe.getDouble]
    [Registering JNI native method sun.misc.Unsafe.putDouble]
    [Registering JNI native method sun.misc.Unsafe.getAddress]
    [Registering JNI native method sun.misc.Unsafe.putAddress]
    [Registering JNI native method sun.misc.Unsafe.allocateMemory]
    [Registering JNI native method sun.misc.Unsafe.reallocateMemory]
    [Registering JNI native method sun.misc.Unsafe.freeMemory]
    [Registering JNI native method sun.misc.Unsafe.objectFieldOffset]
    [Registering JNI native method sun.misc.Unsafe.staticFieldOffset]
    [Registering JNI native method sun.misc.Unsafe.staticFieldBase]
    [Registering JNI native method sun.misc.Unsafe.ensureClassInitialized]
    [Registering JNI native method sun.misc.Unsafe.arrayBaseOffset]
    [Registering JNI native method sun.misc.Unsafe.arrayIndexScale]
    [Registering JNI native method sun.misc.Unsafe.addressSize]
    [Registering JNI native method sun.misc.Unsafe.pageSize]
    [Registering JNI native method sun.misc.Unsafe.defineClass]
    [Registering JNI native method sun.misc.Unsafe.defineClass]
    [Registering JNI native method sun.misc.Unsafe.allocateInstance]
    [Registering JNI native method sun.misc.Unsafe.monitorEnter]
    [Registering JNI native method sun.misc.Unsafe.monitorExit]
    [Registering JNI native method sun.misc.Unsafe.tryMonitorEnter]
    [Registering JNI native method sun.misc.Unsafe.throwException]
    [Registering JNI native method sun.misc.Unsafe.compareAndSwapObject]
    [Registering JNI native method sun.misc.Unsafe.compareAndSwapInt]
    [Registering JNI native method sun.misc.Unsafe.compareAndSwapLong]
    [Registering JNI native method sun.misc.Unsafe.putOrderedObject]
    [Registering JNI native method sun.misc.Unsafe.putOrderedInt]
    [Registering JNI native method sun.misc.Unsafe.putOrderedLong]
    [Registering JNI native method sun.misc.Unsafe.park]
    [Registering JNI native method sun.misc.Unsafe.unpark]
    [Dynamic-linking native method java.lang.Runtime.freeMemory ... JNI]
    [Dynamic-linking native method java.lang.Class.getPrimitiveClass ... JNI]
    [Dynamic-linking native method java.lang.Float.floatToRawIntBits ... JNI]
    [Dynamic-linking native method java.lang.Double.doubleToRawLongBits ... JNI]
    [Dynamic-linking native method sun.misc.VM.initialize ... JNI]
    [Dynamic-linking native method sun.reflect.Reflection.getCallerClass ... JNI]
    [Dynamic-linking native method java.lang.String.intern ... JNI]
    [Dynamic-linking native method java.lang.System.initProperties ... JNI]
    [Dynamic-linking native method java.lang.Runtime.maxMemory ... JNI]
    [Dynamic-linking native method java.io.FileInputStream.initIDs ... JNI]
    [Dynamic-linking native method java.io.FileDescriptor.initIDs ... JNI]
    [Dynamic-linking native method java.io.FileDescriptor.set ... JNI]
    [Dynamic-linking native method java.io.FileOutputStream.initIDs ... JNI]
    [Dynamic-linking native method java.lang.System.setIn0 ... JNI]
    [Dynamic-linking native method java.lang.Object.getClass ... JNI]
    [Dynamic-linking native method java.lang.Class.forName0 ... JNI]
    [Dynamic-linking native method sun.reflect.Reflection.getClassAccessFlags ... JNI]
    [Dynamic-linking native method sun.reflect.NativeConstructorAccessorImpl.newInsta nce0 ... JNI]
    [Dynamic-linking native method java.lang.System.setOut0 ... JNI]
    [Dynamic-linking native method java.lang.System.setErr0 ... JNI]
    [Dynamic-linking native method java.io.FileSystem.getFileSystem ... JNI]
    [Dynamic-linking native method java.io.Win32FileSystem.initIDs ... JNI]
    [Dynamic-linking native method java.io.WinNTFileSystem.initIDs ... JNI]
    [Dynamic-linking native method java.lang.System.mapLibraryName ... JNI]
    [Dynamic-linking native method java.io.WinNTFileSystem.getBooleanAttributes ... JNI]
    [Dynamic-linking native method java.io.WinNTFileSystem.canonicalize0 ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader$NativeLibrary.load ... JNI]
    [Dynamic-linking native method sun.misc.Signal.findSignal ... JNI]
    [Dynamic-linking native method sun.misc.Signal.handle0 ... JNI]
    [Dynamic-linking native method sun.io.Win32ErrorMode.setErrorMode ... JNI]
    [Dynamic-linking native method java.lang.Compiler.registerNatives ... JNI]
    [Registering JNI native method java.lang.Compiler.compileClass]
    [Registering JNI native method java.lang.Compiler.compileClasses]
    [Registering JNI native method java.lang.Compiler.command]
    [Registering JNI native method java.lang.Compiler.enable]
    [Registering JNI native method java.lang.Compiler.disable]
    [Dynamic-linking native method java.lang.ClassLoader.getCaller ... JNI]
    [Dynamic-linking native method java.util.concurrent.atomic.AtomicLong.VMSupportsC S8 ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader$NativeLibrary.find ... JNI]
    [Dynamic-linking native method java.security.AccessController.doPrivileged ... JNI]
    [Dynamic-linking native method java.io.FileInputStream.open ... JNI]
    [Dynamic-linking native method java.io.FileInputStream.readBytes ... JNI]
    [Dynamic-linking native method java.io.FileInputStream.available ... JNI]
    [Dynamic-linking native method java.lang.reflect.Array.newArray ... JNI]
    [Dynamic-linking native method java.lang.Runtime.availableProcessors ... JNI]
    [Dynamic-linking native method java.io.FileInputStream.close0 ... JNI]
    [Dynamic-linking native method java.io.WinNTFileSystem.list ... JNI]
    [Dynamic-linking native method java.io.WinNTFileSystem.canonicalizeWithPrefix0 ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.initIDs ... JNI]
    [Dynamic-linking native method java.io.WinNTFileSystem.getLastModifiedTime ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.open ... JNI]
    [Dynamic-linking native method sun.misc.Perf.registerNatives ... JNI]
    [Registering JNI native method sun.misc.Perf.attach]
    [Registering JNI native method sun.misc.Perf.detach]
    [Registering JNI native method sun.misc.Perf.createLong]
    [Registering JNI native method sun.misc.Perf.createByteArray]
    [Registering JNI native method sun.misc.Perf.highResCounter]
    [Registering JNI native method sun.misc.Perf.highResFrequency]
    [Dynamic-linking native method java.util.zip.ZipFile.getTotal ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getEntry ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getEntryFlag ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getEntryTime ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getEntryCrc ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getEntrySize ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getEntryCSize ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getEntryMethod ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getEntryBytes ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.freeEntry ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.read ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.close ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader.findLoadedClass0 ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader.findBootstrapClass ... JNI]
    [Dynamic-linking native method java.security.AccessController.doPrivileged ... JNI]
    [Dynamic-linking native method java.lang.Package.getSystemPackage0 ... JNI]
    [Dynamic-linking native method java.util.jar.JarFile.getMetaInfEntryNames ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader.defineClass1 ... JNI]
    [Dynamic-linking native method java.util.zip.Inflater.initIDs ... JNI]
    [Dynamic-linking native method java.util.zip.Inflater.init ... JNI]
    [Dynamic-linking native method java.util.zip.Inflater.inflateBytes ... JNI]
    [Dynamic-linking native method java.util.zip.Inflater.reset ... JNI]
    [Dynamic-linking native method java.security.AccessController.doPrivileged ... JNI]
    [Dynamic-linking native method java.lang.Double.longBitsToDouble ... JNI]
    [Dynamic-linking native method java.lang.Class.isAssignableFrom ... JNI]
    [Dynamic-linking native method sun.security.provider.NativeSeedGenerator.nativeGe nerateSeed ... JNI]
    [Dynamic-linking native method java.net.InetAddress.init ... JNI]
    [Dynamic-linking native method java.net.InetAddressImplFactory.isIPv6Supported ... JNI]
    [Dynamic-linking native method java.net.Inet6AddressImpl.getLocalHostName ... JNI]
    [Dynamic-linking native method java.net.Inet6AddressImpl.lookupAllHostAddr ... JNI]
    [Dynamic-linking native method java.net.Inet4Address.init ... JNI]
    [Dynamic-linking native method java.net.Inet6Address.init ... JNI]
    [Dynamic-linking native method sun.nio.fs.WindowsNativeDispatcher.initIDs ... JNI]
    [Dynamic-linking native method sun.nio.fs.WindowsNativeDispatcher.FindFirstFile0 ... JNI]
    [Dynamic-linking native method sun.nio.fs.WindowsNativeDispatcher.FindNextFile ... JNI]
    [Dynamic-linking native method sun.nio.fs.WindowsNativeDispatcher.FindClose ... JNI]
    [Dynamic-linking native method java.lang.Runtime.totalMemory ... JNI]
    [Dynamic-linking native method java.io.WinNTFileSystem.createFileExclusively ... JNI]
    [Dynamic-linking native method java.io.FileOutputStream.open ... JNI]
    [Dynamic-linking native method java.io.FileOutputStream.writeBytes ... JNI]
    [Dynamic-linking native method java.io.FileOutputStream.close0 ... JNI]
    [Dynamic-linking native method com.sun.jna.Native.sizeof ... JNI]
    [Dynamic-linking native method com.sun.jna.Native.initIDs ... JNI]
    [Dynamic-linking native method com.sun.jna.Native.open ... JNI]
    [Dynamic-linking native method java.lang.reflect.Proxy.defineClass0 ... JNI]
    [Dynamic-linking native method sun.reflect.NativeMethodAccessorImpl.invoke0 ... JNI]
    [Dynamic-linking native method com.sun.jna.Native.findSymbol ... JNI]
    [Dynamic-linking native method com.sun.jna.Native.invokeVoid ... JNI]

    Device \\.\vw_2010-0 BusNum=4, DevNum=11

    Device \\.\DrvVideoDevice-1 BusNum=4

    Device \\.\vw_2010-1 BusNum=4, DevNum=14

    Device \\.\DrvVideoDevice-2 BusNum=4

    28 PCI Device Found
    => setMsgLevel set to 0
    From CLib Channels = 0
    [Dynamic-linking native method java.io.WinNTFileSystem.delete0 ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader$NativeLibrary.unload ... JNI]

    ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++
    When running the C .EXE:-


    C:\Users\MPR\dist>mpegio2clibtest.exe

    Device \\.\vw_2010-0 BusNum=4, DevNum=11

    Device \\.\DrvVideoDevice-1 BusNum=4

    Device \\.\vw_2010-1 BusNum=4, DevNum=14

    Device \\.\DrvVideoDevice-2 BusNum=4

    28 PCI Device Found
    => setMsgLevel set to 0
    length of encode is 2147483647
    transfer timeout is 5
    single transfer is 8 pages
    => setMsgLevel set to 0
    length of encode is 2147483647
    transfer timeout is 5
    single transfer is 8 pages
    From CLib Channels = 2

    C:\Users\MPR\dist>

Similar Threads

  1. StringWorker different behaviour
    By _SAS in forum Threads and Synchronization
    Replies: 5
    Last Post: 08-06-2011, 10:18 PM
  2. Replies: 5
    Last Post: 03-19-2011, 08:27 AM
  3. NetworkInterface class behaviour for 32bit vs 64bit java
    By CitizenErased in forum Advanced Java
    Replies: 0
    Last Post: 12-09-2010, 03:25 PM
  4. BoxLayout Behaviour
    By PetalumaBoy in forum AWT / Swing
    Replies: 4
    Last Post: 06-10-2009, 02:27 PM
  5. Java applet strange painting behaviour
    By sirdori in forum New To Java
    Replies: 1
    Last Post: 01-07-2009, 02:14 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •