Hi guys,
I wonder,
for example in C, the custom-mada data type is formed with typef struct
as the followings
typedef struct {
ULONG length; // length of binary data
UCHAR *data; // binary data
} EBUFFER;
EBUFFER *eBuffer
..
so for this eBuffer, how do i pass a java arguement to it? Should i use
a String[]? I
use array for other C or C++ pointers.. but in this case, i really dont
know.
Thanks in advance.
Please help :)
Gordon Beaton - 07 Aug 2006 20:15 GMT
> for example in C, the custom-mada data type is formed with typef
> struct as the followings
[quoted text clipped - 10 lines]
> use a String[]? I use array for other C or C++ pointers.. but in
> this case, i really dont know.
What are you trying to do? Be specific. You can't pass this struct as
an argument to a Java function in any meaningful manner.
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Mark Space - 08 Aug 2006 00:13 GMT
> Hi guys,
>
[quoted text clipped - 18 lines]
>
> Please help :)
What Gordon says is correct. We really need more info.
Try this:
http://www.darksleep.com/player/JavaAndUnsignedTypes.html
But String[] is wrong, for sure. Try byte[] or short[]. char[] is
right out also, unless you are very certain of the internal character
encoding that your Java uses.
JPractitioner - 08 Aug 2006 07:10 GMT
Hi Mark and Gordon, first of all, thank u for replying me.
Ok, back to the thing here. I wanted to call a function of C code from
my java application. I figured out that, some arguments of the function
is of C's typedef struct. I know that, java does not support struct. I
do not know what is the approprate data type from java that i can use
to match with this kind of arguments
such as the followings..
typedef struct {
ULONG length; // length of
binary data
UCHAR *data; // binary data
} EBUFFER;
let me add more codes here, suppose that the C function signature is
int ESX_0100 (EBUFFER *buffer)
so, on my java code (which i will run javah),
what do i write for the native method declaration?
Should I write it as..
public native int EFT_EE0801_Decipher(char[] buffer);//or
public native int EFT_EE0801_Decipher(String buffer);//or even
public native int EFT_EE0801_Decipher(String[] buffer);//?
I know that in java, the non-primitive type (such as String) and array
(of any type if not mistaken) will be assigned a memory sector that
keeps address which will point to the place where the value is actually
being kept. So, in my opinion, to address a C pointer i could use a
String or array of data types provided that the pointer is using data
type known to java. However, I do not know how to do it in the case of
addressing a custom-made data type such as in this case.
So guys, while i am still doing this reasearch, i really hope that u
guys could throw me some ideas.
Thanks a lot for the time. I do appreciate.
Gordon Beaton - 08 Aug 2006 07:34 GMT
> Ok, back to the thing here. I wanted to call a function of C code
> from my java application. I figured out that, some arguments of the
[quoted text clipped - 14 lines]
> so, on my java code (which i will run javah),
> what do i write for the native method declaration?
You cannot call this (or any other arbitrary) C function directly from
Java.
JNI lets you implement some or all of a class' methods in e.g. C, and
those methods *must* be written to conform with a specific naming and
calling standard, i.e. they must be written specifically for use with
JNI. You must declare your methods in Java and generate a set of
native method signatures using javah.
From your native methods you can call any other C functions you like,
including the one in your example. In that case it's up to the native
method to perform the necessary conversion between pure Java types and
the pure native types needed by the function, using the functions
provided by the JNI API.
For further reading:
http://java.sun.com/docs/books/jni/index.html
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
JPractitioner - 08 Aug 2006 08:01 GMT
Hmm.. i guess thats the only way i could use now.
I will get some data sample to help me get the idea of constructing a
suitable native method signature and
include (import) the header files (which specify the custom types) in
my C implementation file.
Later, i will have to redeclare the arguments with the custom types.
Sounds like a casting.. is this possible in C ? hmm...
Thanks.