+
=>
Yeah, I got it!
It's just as easy as... don't know
Here's the 'trick':
All you have to do is to rename your PB-Procedures.
If your Java-program calls the function '
testfunction', then your PB-procedure has to have the name '
Java_ClassNameOfCallingClass_testfunction'
That's all.
It's not soo convenient, because you have to rename your PB's procedures always if they should be called from another Java-program's class, but anyway, it works.
I tried it with byte (byte), word (short), long (int) and float (float).
I think a workaround for doubles would work, too.
But I wasn't able to send/receive a String, not even converted to a byte[]-array in Java. hmmm. It seems, that there's really a big difference in their handling, or it's not possible to access the other program's memory or something like that - I will try a little bit more.
But first, here's an example:
The PB-DLL:
Code: Select all
ProcedureDLL.b Java_dllCallClass_testfunctionB(a.l, b.l, c.b, d.b)
MessageRequester("",Str(a)+" "+Str(b)+" "+Str(c)+" "+Str(d),0)
ProcedureReturn c + d
EndProcedure
ProcedureDLL.w Java_dllCallClass_testfunctionW(a.l, b.l, c.w, d.w)
MessageRequester("",Str(a)+" "+Str(b)+" "+Str(c)+" "+Str(d),0)
ProcedureReturn c + d
EndProcedure
ProcedureDLL.l Java_dllCallClass_testfunctionL(a.l, b.l, c.l, d.l)
MessageRequester("",Str(a)+" "+Str(b)+" "+Str(c)+" "+Str(d),0)
ProcedureReturn c + d
EndProcedure
ProcedureDLL.f Java_dllCallClass_testfunctionF(a.l, b.l, c.f, d.f)
MessageRequester("",Str(a)+" "+Str(b)+" "+StrF(c)+" "+StrF(d),0)
ProcedureReturn c + d
EndProcedure
And the Java-Code:
Code: Select all
class dllCallClass
{
public static native byte testfunctionB (byte c, byte d);
public static native short testfunctionW (short c, short d);
public static native int testfunctionL (int c, int d);
public static native float testfunctionF (float c, float d);
static
{
System.loadLibrary("testdll");
}
}
class starttestdll
{
public static void main(String [] parm)
{
dllCallClass t = new dllCallClass();
System.out.println(t.testfunctionB((byte) 12,(byte) -23));
System.out.println(t.testfunctionW((short)1234,(short)-2345));
System.out.println(t.testfunctionL(23456,-34567));
System.out.println(t.testfunctionF((float) 2.345,(float) -3.456));
}
}
Just compile the DLL and copy it to the directory of the Java-file.
OK, now I will have a deeper look at the other types (strings, pointer, structures, arrays, lists), there is written something about it somewhere in the Net...
edit: now it's 12:17 - hmmm - i forgot to sleep last night !!! not 1 minute !!! It was just getting dark and then bright again...