Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transfer of a java object with JNI

Status
Not open for further replies.

nora1966

Programmer
Oct 12, 2006
10
0
0
FR
Hi;

I search an JNI example with C/C++ to check if it is possible to send a java object with JNI.
I have a class java “A” with 2 methods:
- getCustomer (): get an java object Customer
- checkCustomer (Customer c): print an Customer object
The external prog (C/++ or other) calls the method “getPeronne” to retrieve an Customer object empties, it fills and it must return to java prog via the method checkCustomer or another means to be store in database.
For the “getPersonne” method it is OK for my but I would like to know how implement the return of object “Customer” ?

Regards;
 
What do you mean with "send"? Pass as parameter or actually send it through a socket or something?

Cheers,
Dian
 
See this article, it describes the use of returning custom Java objects.


Particularly :

Code:
JNIEXPORT jobject JNICALL Java_SysInfo_getVersion (JNIEnv *env, jclass clazz)
{
    OSVERSIONINFO osVersionInfo;
    // Get operating system version information.
    osVersionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
    GetVersionEx (&osVersionInfo);
    // Attempt to find the Version class.
    clazz = env->FindClass ("Version");
    // If this class does not exist then return null.
    if (clazz == 0)
            return 0;
    // Allocate memory for a new Version class object.  Do not bother calling
    // the constructor (the default constructor does nothing).
    jobject obj = env->AllocObject (clazz);
    // Attempt to find the major field.
    jfieldID fid = env->GetFieldID (clazz, "major", "I");
    // If this field does not exist then return null.
    if (fid == 0)
            return 0;
    // Set the major field to the operating system's major version.
    env->SetIntField (obj, fid, osVersionInfo.dwMajorVersion);
    // Attempt to find the minor field.
    fid = env->GetFieldID (clazz, "minor", "I");
    // If this field does not exist then return null.
    if (fid == 0)
            return 0;
    // Set the minor field to the operating system's minor version.
    env->SetIntField (obj, fid, osVersionInfo.dwMinorVersion);
    return obj;
}

where the "Version" class is :

Code:
public class Version
{
   int major;
   int minor;
}


--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top