Stackoverflow Users !
I am trying to covert some functions that I had written in c++ to java. Exactly I have a .so library witch I have written in c++ and now I must call functions from my Android application. Functions like this:
unsignd int Uninitialize();
---------------------------------------
unsignd int DeviceOpen(
    const wchar_t* deviceID,
    unsigned long* phDevice);
---------------------------------------
typedef struct BlobData_s {
     unsigned long     length;
     unsigned char     data[1];
} dsmBlobData_t;
unsignd int Enroll(
    unsigned long       hDevice,
    const char*         userID,
    BlobData_s*         pInputInfo,
    void*               pUserData);
Now how you can see I have functions and typedefs that I want to write in java style, but my problem is that there are no unsigned int java type (link). I knew that instead of int I can use jint, in开发者_JS百科stead of char* I can use jchar* but what I must do with
- const wchar_t*
- unsigned long
- unsigned char
What can I use instead of that types.
I try in this way
jint Java_com_example_testApp_TestApp_DeviceOpen( jchar* deviceID, int* phDevice)
{ 
      return DeviceOpen((const wchar_t*)deviceID, (unsigned long*)phDevice);
}
Am I right ?*
Thanks in advance, ViToBrothers.
For starters, you'll have to map your types to Java types.  As you say,
there is no unsigned in Java, and no wchar_t.  Once you've decided
what types to use on the Java side (e.g. int instead of unsigned, or
maybe long; and probably java.lang.String for both char* and
wchar_t*), you'll have to declare your native methods using them, and
implement the JNI in a way which maps them to your internal values.
Also, if your C++ code uses exceptions, you'll have to catch them and remap them in the JNI interface.
For starters, I'd see if some existing tool, like swig, would do the job. If it didn't, I'd still use it to get example code, which can then be copy/pasted and edited.
I don't believe you can use jchar* as it not a valid type for Java.
I suggest you use javah to generate the Java header from a Java class with native methods. This will show you the correct types to use. (I don't know what the equivalent for Android is)
In many cases there is no direct equivalents so you have to used methods to copy the data.
BTW: I wouldn't be so worried about unsigned vs signed as the number involved just store an id. These are not values you can perform arithmetic operations on.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论