harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tor-Einar Jarnbjo <Tor-Ei...@Jarnbjo.de>
Subject Re: [Legal] Requirements for Committers
Date Wed, 08 Jun 2005 00:19:09 GMT
Geir Magnusson Jr. wrote:

> What are you working on?

It's a framework to ease JNI programming, or more precisely to make it 
possible to call native, e.g. OS functions without writing wrapper code 
in C to do type conversions etc.

For example, invoking the Windows MessageBox function in user32.dll can 
be done like this:

EasyJni jni = EasyJni.getInstance();
NativeLibrary user32 = jni.loadNativeLibrary("user32");

long ctext = jni.createCString("Message box text", "UTF-16LE");
long ctitle = jni.createCString("Message box title", "UTF-16LE");

int res = (int)user32.invokeLong(
  "MessageBoxW", 0, ctext, ctitle, MessageBoxConstants.MB_OKCANCEL);


C structs can be mapped to Java classes using annotations, as here with 
the WAVEFORMAT struct used by the Windows audio API:

@NativeStruct(endian=Endian.little, size=16)
public class WaveFormat implements Modifiable {

    @NativeField(type=FieldType.int16, offset=0)
    private int formatTag;

    @NativeField(type=FieldType.int16, offset=2)
    private int channels;
    @NativeField(type=FieldType.int32, offset=4)
    private int samplesPerSecond;

    @NativeField(type=FieldType.int32, offset=8)
    private int avgBytesPerSecond;
    @NativeField(type=FieldType.int32, offset=12)
    private int blockAlign;

    // getter and setter methods ...

I needed this for some audio functionality, which is not available 
through JavaSound. The JNI library could probably be used in several 
fields, and seeing that Classpath does not implement any parts of 
JavaSound, my Windows media API wrappers are probably a good starting 
point for a new JavaSound implementation (at least targetted for Windows).


View raw message