Currently Being Moderated

Mapping Native Types to JNIWrapper Classes

VERSION 1

Created on: Feb 5, 2009 4:00 PM by Roman Kazmin - Last Modified:  Feb 5, 2009 4:26 PM by Roman Kazmin

Please find below the mappings table for most commonly used data types along with some comments.

 

Native Type

(C/C++)

JNIWrapper Type

Comments

Boolean Types

bool

Bool(1 byte), IntBool(4 bytes)

Character Types

char

Char

wchar_t

WideChar

uchar *

Char, UInt8

Integer Types

short

ShortInt

The unsigned types are represented by prepending U to the type name, e.g. unsigned int (or unsigned) type is UInt.

There are also types for predefined-width integers: Int8, Int16, Int32 and Int64, they also have the unsigned variants.

int

Int

long

LongInt

Floating-point Types

float

SingleFloat

double

DoubleFloat

long double

LongDouble

Long double is the same as double (8-byte floating-point value) on win32 platform.

Pointer Types (not arrays)

void *

Pointer.Void

const

Pointer.Const

Use Pointer.Const if the referenced object is not to be modified by the calling function.

type *

Pointer

To create a pointer to the value (variable) of a known type, use the Pointer class.
For example:
int *i; is Pointer i = new Pointer(new Int());

type *

Pointer.OutOnly

Use Pointer.OutOnly if the referenced value is not read by the calling function.

char *

AnsiString

wchar_t *

WideString

Arrays

<c primitive type>[n]

PrimitiveArray(<corresponding JNIWrapper type>.class, n);

For example:
int i[10];
is
PrimitiveArray i =
  new PrimitiveArray(Int.class, 10);

Structures and Unions

struct

Structure

union

Union

Function Pointers

To create an object callable from the native code use the Callback class.

To call a function returned from the native code use the method asFunction of the Pointer.Void class.

 

 

 

Windows API includes many data types that are not listed here (for example, DWORD, HANDLE). If you need to use one of such types, read Windows-specific documentation such as MSDN to find out the actual C type that corresponds to it (for example, LPSTR corresponds to char*) and use the relevant JNIWrapper type for the argument. You can also check the Windows Data Types table that we have created for your reference.

Average User Rating
(0 ratings)




There are no comments on this document

More Like This

  • Retrieving data ...