This package contains a set of macros which can be used to minimize the differences between JNI and RNI. You can use these macros when building native libraries in order to minimize the amount of special case code you must write. These macros are meant only to be a starting point; you will need to modify them to suit your purposes.
This package also contains a sample Java application which illustrates the use of the macros, and which can be used as a template for your native DLLs. The sample application loads one of two native DLLs, depending on whether it's running on the MSVM, or the SunJDK. Java and C source code is included. To build the DLLs, you will need to have the following software installed:
A Metrowerks CodeWarrior Pro2 project is included to build the native DLLs; however, you can modify the included files if your environment is different. This package is brought to you by Samizdat Productions. For more free Java tools, applets, and applications, be sure and visit us at www.tolstoy.com.
See Java Samples for the latest version of this package.
For more information, send email to samizdat@tolstoy.com
This package contains the following files:
You will need to modify the batch files depending on the locations where you have installed the various SDKs. Instructions are given in the batch files. Also, if you get the error message 'Out of Environment Space', right click on the batch file, and choose 'Properties'. On the 'Memory' tab, in the 'Conventional Memory' area, set the 'Initial Environment' popup menu to its highest setting.
The following is a description of the macros.
FUNC(pkg,clz,mth)
Replaces the header of a native routine. See 'main.cpp' for examples of use.
JSTRING
Represents a Java string.
JINT
Represents a Java int and a C long.
JLONG
Represents a Java long and a C long long.
JINTARRAY
Represents an array of Java ints.
JLONGARRAY
Represents an array of Java longs.
JSTRINGARRAY
Represents an array of Java strings.
CHECKNULL( JOBJECT a )
If 'a' is NULL, returns kErrParamErr. This constant is defined in the header files.
CHECKSIZE( JARRAY a, JINT b )
If the array 'a' doesn' have at least 'b' elements, returns kErrParamErr.
This constant is defined in the header files.
JINT GETINTARRAYLEN( JINTARRAY a )
Returns the length of the given JINTARRAY.
JINT *LOCKINTARRAY( JINTARRAY a )
Returns a pointer to the first element of the given JINTARRAY. You must save the value returned
from this macro, and pass it to the UNLOCKINTARRAY macro unchanged.
void UNLOCKINTARRAY( JINTARRAY a, JINT *b )
After you are done using a JINTARRAY, call this macro with the JINTARRAY and the value returned
from LOCKINTARRAY.
void SETINTARRAY( JINTARRAY a, JINT startIndex, JINT numToSet, JINT *values )
Sets a region of the given JINTARRAY to values containing in an array of C long values. startIndex
is the index of the JINTARRAY at which to start, and numToSet is the number of elements to set. The
values which are set will be retrieved from successive locations pointed to by the values argument.
JINT GETLONGARRAYLEN( JLONGARRAY a )
Returns the length of the given JLONGARRAY.
JLONG *LOCKLONGARRAY( JLONGARRAY a )
Returns a pointer to the first element of the given JLONGARRAY. You must save the value returned
from this macro, and pass it to the UNLOCKLONGARRAY macro unchanged.
void UNLOCKLONGARRAY( JLONGARRAY a, JLONG *b )
After you are done using a JLONGARRAY, call this macro with the JLONGARRAY and the value returned
from LOCKLONGARRAY.
void SETLONGARRAY( JLONGARRAY a, JINT startIndex, JINT numToSet, JLONG *values )
Sets a region of the given JLONGARRAY to values containing in an array of C long values. startIndex
is the index of the JLONGARRAY at which to start, and numToSet is the number of elements to set. The
values which are set will be retrieved from successive locations pointed to by the values argument.
JINT GETOBJECTARRAYLEN( JOBJECTARRAY oa )
Returns the length of the given JOBJECTARRAY.
JOBJECT GETOBJECTARRAYELEMENT( JOBJECTARRAY oa, JINT which )
Returns the value at the given index into the given JOBJECTARRAY.
void SETOBJECTARRAYELEMENT( JOBJECTARRAY oa, JINT which, JOBJECT newObj )
Sets the value at the given index into the given JOBJECTARRAY to newObj.
JSTRING NEWSTRINGUTF( JCHAR *cs )
Create a Java string from a zero-terminated C string.
JINT GETSTRINGUTFLEN( JSTRING js )
Returns the number of UTF characters in the given Java string.
JCHAR *GETSTRINGUTF( JSTRING js, char *buf, JINT bufLen )
Gets the UTF characters of the given Java string into a zero-terminated C string. bufLen is the length
of buf.
This file and the other files included with this distribution are referred to as the Software. The Software is Copyright (c) 1998 Samizdat Productions. All Rights Reserved.
You may use the Software without restriction. You may redistribute the Software, provided that you redistribute the Software in its entirety, including this file. You may redistribute modified versions of the Software, provided that you indicate that you have created a derived work based on the original Software. You may not remove the copyright notices which are contained in the individual files of the Software; you may, however, add your own information to these notices. You may only redistribute the Software subject to this Agreement; you may not redistribute the Software with a license agreement, or under any terms or conditions which will in any way replace or modify this Agreement. By using or redistributing the Software, you agree to abide by the terms of this Agreement.
This software is provided on an "as-is" basis; use this software at your own risk. No warranty of fitness for any purpose is claimed, implicitly or otherwise.