J
John Smith
I'm in the process of creating a wrapper for my existing C library to make
it usable from java.
Lets say you have a native function which return an integer (part of this
library) which I want to call from my jni function.
This function has the prototype of:
typedef int X_STATUS;
X_STATUS f1(...);
Then the possible errorcodes are encoded into an enum like (on the java
side):
public enum Errors
{
A,
B,
C
}
So now when I declared my native function in java it wants jobject as return
type. This jobject referes to the enum which it expects. But this is
actually rather silly since it requires so much more work to create the enum
on the native side as return value then just return the integer directly.
So is it possible to make it return the integer and then typecast this value
on java side to the enum errorcode? Essentially the two things are the same
but it was not clear from the JNI documentation how to create this errorcode
on the native side and make it into a jobject.
What I tried was also to make the native function return an 'int' and cast
that into the Errors enum but java does not seem to like these type of
typecasts.
Thanks in advance.
-- John
it usable from java.
Lets say you have a native function which return an integer (part of this
library) which I want to call from my jni function.
This function has the prototype of:
typedef int X_STATUS;
X_STATUS f1(...);
Then the possible errorcodes are encoded into an enum like (on the java
side):
public enum Errors
{
A,
B,
C
}
So now when I declared my native function in java it wants jobject as return
type. This jobject referes to the enum which it expects. But this is
actually rather silly since it requires so much more work to create the enum
on the native side as return value then just return the integer directly.
So is it possible to make it return the integer and then typecast this value
on java side to the enum errorcode? Essentially the two things are the same
but it was not clear from the JNI documentation how to create this errorcode
on the native side and make it into a jobject.
What I tried was also to make the native function return an 'int' and cast
that into the Errors enum but java does not seem to like these type of
typecasts.
Thanks in advance.
-- John