You are not logged in.

  • "Gerome GUILLEMIN" started this thread

Posts: 14

Date of registration: Feb 16th 2009

  • Send private message

1

Monday, February 23rd 2009, 8:21pm

A better JNI implementation...JNA?

Hello,

Installed latest NetBeans package and discovered a better JNI interface, its Jar file is called jna-3.0.2.jar, into the NetBeans 6.5\platform9\modules\ext folder.

Its DLL seems largely better than the actual Jabaco's DLL JNI support, and supports pointers & callbacks.

If you want to see its internal mechanism you can get a good decompiler called JD-GUI there :

http://java.decompiler.free.fr/?q=jdgui



As well see the officlal site :

https://jna.dev.java.net/

May be a next Jabaco's version with this newest JNI support? :)

Have fun! :!:



PS : I've experimented this java code under netbeans using JNA :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package javaTest; 

import com.sun.jna.*; 

/** Simple example of native library declaration and usage. */ 
public class HelloWorld { 

// Most C libraries will just extend com.sun.jna.Library, 
public interface Kernel32 extends Library { 
// Method declarations, constant and structure definitions go here 
Kernel32 INSTANCE = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class); 

// Optional: wraps every call to the native library in a synchronized block, limiting native calls to one at a time 
Kernel32 SYNC_INSTANCE = (Kernel32)Native.synchronizedLibrary(INSTANCE); 

public static class SYSTEMTIME extends Structure { 
public short wYear; 
public short wMonth; 
public short wDayOfWeek; 
public short wDay; 
public short wHour; 
public short wMinute; 
public short wSecond; 
public short wMilliseconds; 
} 

void GetSystemTime(SYSTEMTIME result); 
} 

public static void main(String[] args) { 
Kernel32 lib = Kernel32.INSTANCE; 
Kernel32.SYSTEMTIME time = new Kernel32.SYSTEMTIME(); 
lib.GetSystemTime(time); 
System.out.println("Today's integer value is " + time.wDay + '/' + time.wMonth + '/' + time.wYear); 

} 
}




And a native call to FBSL.DLL engine :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package javaTest; 



import com.sun.jna.*; 



/** Simple example of native library declaration and usage. */ 
public class HelloWorld { 



// Most C libraries will just extend com.sun.jna.Library, 
public interface FBSL extends Library { 
// Method declarations, constant and structure definitions go here 
FBSL INSTANCE = (FBSL)Native.loadLibrary("FBSL", FBSL.class); 



// Optional: wraps every call to the native library in a synchronized block, 
// limiting native calls to one at a time 
FBSL SYNC_INSTANCE = (FBSL)Native.synchronizedLibrary(INSTANCE); 



int FBSL_ExecuteScriptBuffer( String szBuffer ); 
} 



public static void main(String[] args) { 
FBSL lib = FBSL.INSTANCE; 
lib.FBSL_ExecuteScriptBuffer("msgbox(Null, "Hello from FBSL!","Title",48)"); 
} 
}

This post has been edited 4 times, last edit by "Gerome GUILLEMIN" (Feb 23rd 2009, 10:15pm)


Rate this thread
WoltLab Burning Board