Introduction to Using the Raw Native Interface
 
 

Java & Native Code    PreviousRNI
Introduction to Using the Raw Native Interface     Previous RNI

 


Miscellaneous

To check if an object is of a particular type, you can use isInstanceOf, as shown in the following example.

    if (isInstanceOf(phSomeObject, "java/awt/Rectangle"))
    {
        // Object is a Rectangle...
    }

The first parameter is an object pointer and the second parameter is the full class name you want to test against.

Given a Java String type, you can query the number of Java characters it contains with javaStringLength(). For example:

    int cchString = javaStringLength(phString);

You can copy a Java String type to a C string buffer (converting from Unicode to multi-byte characters) using the javaString2CString function. This is shown in the following example.

    char szMBCS[256];

    javaString2CString(phString, szMBCS, sizeof(szMBCS);

The first parameter is the String object, the second is the destination buffer, and the third is the size of the buffer (in bytes), including the terminating NULL.

You can copy from one array to the other using the ArrayCopy function. The following is an example of copying 10 elements from one array (starting at position 3) to another (starting at position 5).

    ArrayCopy(phabSrc, 3, phabDst, 5, 10);

The first parameter is the source array, the second parameter is the source offset, the third is the destination array, the fourth is destination offset, and the fifth is the number of elements to copy.

Top © 1998 Microsoft Corporation. All rights reserved. Terms of use.