|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jinvoke.Util
public class Util
Provides utility methods for converting Java types to native types and vice versa. Also provides miscellaneous methods for obtaining the size of structs, pointers, chars etc.
| Method Summary | ||
|---|---|---|
static int |
byteArrayToPtr(byte[] ba)
Allocates a block of native memory and copies the contents of the passed in byte array to native memory. |
|
static void |
free(int ptr)
Frees a block of native memory that has been allocated using alloc() |
|
static void |
freeCoTaskMem(int ptr)
Frees a block of native memory that has been allocated using CoTaskMemAlloc(). |
|
static javax.swing.Icon |
getIcon(int hicon)
Converts a Windows HICON to a Java Icon. |
|
static javax.swing.Icon |
getIcon(int hicon,
int iconSize)
Converts a Windows HICON to a Java Icon. |
|
static int |
getLastError()
On Windows, returns the calling threads's last error code. |
|
static int |
getStructSize(java.lang.Class structClass)
Returns the number of bytes occupied by a struct in native memory |
|
static int |
getStructSize(java.lang.Object struct)
Returns the number of bytes occupied by a struct in native memory |
|
static int |
getWindowHandle(java.awt.Component component)
Returns the Win32 HWND for a heavyweight Java component |
|
static byte[] |
ptrToByteArray(int ptr,
int numelements)
Allocates a Java byte array and copies numelements bytes pointed to by
ptr into the Java byte array. |
|
static java.lang.String |
ptrToString(int ptr)
Allocates a Java String and copies the characters from a null terminated Unicode string into it. |
|
static java.lang.String |
ptrToStringAnsi(int ptr)
Allocates a Java String and copies the characters from a null terminated Ansi string into it. |
|
static
|
ptrToStruct(int ptr,
java.lang.Class<T> structclass)
Converts data from a native block of memory to a Java object representing a structure. |
|
static void |
ptrToStruct(int ptr,
java.lang.Object o)
Converts data from a native block of memory to a Java object representing a structure. |
|
static byte |
readByte(int ptr)
Reads a byte value from a pointer to native memory |
|
static int |
readInt(int ptr)
Reads an int from a pointer to native memory |
|
static long |
readLong(int ptr)
Reads a long from a pointer to native memory |
|
static short |
readShort(int ptr)
Reads a short from a pointer to native memory |
|
static void |
readShort(int ptr,
short s)
Writes a short to native memory |
|
static int |
sizeOfChar()
Returns the number of bytes occupied by a char in native memory |
|
static int |
sizeOfPointer()
Returns the number of bytes occupied by a pointer in native memory |
|
static int |
sizeOfWideChar()
Returns the number of bytes occupied by a wide-character(wchar_t) in native memory |
|
static int |
stringToPtr(java.lang.String s)
Allocates a native Unicode(wide-character) string in native memory and sets it's characters to those in the Java String s. |
|
static int |
stringToPtrAnsi(java.lang.String s)
Allocates a native Ansi(char) string in native memory and sets it's characters to those in the Java String s. |
|
static void |
writeByte(int ptr,
byte b)
Writes a byte value to native memory |
|
static void |
writeInt(int ptr,
int i)
Writes an int to native memory |
|
static void |
writeLong(int ptr,
long l)
Writes a long to native memory |
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T> T ptrToStruct(int ptr,
java.lang.Class<T> structclass)
This method creates a new instance of the Java class structclass representing a
native struct and sets it's fields to the corresponding values in the native structure.
The structclass must represent a native struct. i.e. it must be annotated with the
NativeStruct annotation, and must have public fields corresponding to members of the
native struct.
ptr - - A pointer in native code (pointing to a struct)structclass - - A class representing a native struct (annotated with @NativeStruct annotation)
ptr
public static void ptrToStruct(int ptr,
java.lang.Object o)
This method sets the fields of the Java object o representing a native struct to
the corresponding values in the native structure.
The passed object must be an instance of a class annotated with the @NativeStruct annotation, and must have public fields corresponding to members of the native struct.
ptr - - A pointer to a struct in native memoryo - - An instance of a class representing a native struct (annotated with @NativeStruct annotation)public static java.lang.String ptrToString(int ptr)
ptr - - A pointer to a wide-character string in native memory
public static java.lang.String ptrToStringAnsi(int ptr)
ptr - - A pointer to an Ansi/character string in native memory
public static void free(int ptr)
ptr - - address of the block of memory to be freedpublic static void freeCoTaskMem(int ptr)
ptr - - address of the block of memory to be freedpublic static int stringToPtr(java.lang.String s)
s. Memory for the native string is allocated using
CoTaskMemAlloc and can be freed by the freeCoTaskMem() method.
s - - A Java String which is to be sent to native code as a pointer (LPWSTR, LPCWSTR, wchar_t*, etc).public static int stringToPtrAnsi(java.lang.String s)
s. Memory for the native string is allocated using
malloc and can be freed by the free() method.
s - - A Java String which is to be sent to native code as a pointer (LPSTR, LPCSTR, char*, etc).public static int sizeOfChar()
public static int sizeOfPointer()
public static int sizeOfWideChar()
public static int getStructSize(java.lang.Object struct)
struct - - An instance of a Java class representing a native struct (annotated with @NativeStruct annotation)
public static int getStructSize(java.lang.Class structClass)
structClass - - The Java class representing a native struct (annotated with @NativeStruct annotation)
public static int byteArrayToPtr(byte[] ba)
The number of bytes allocated is determined based on the size of the passed in byte array, ba.
The memory is allocated using malloc().
ba - - the byte array to be sent to native code
public static byte[] ptrToByteArray(int ptr,
int numelements)
numelements bytes pointed to by
ptr into the Java byte array. This method also frees the native memory pointed to
by ptr
ptr - - A pointer to a byte buffer in native memorynumelements - - the number of bytes to be copied to the returned Java byte array
numelements containing the bytes pointed to by ptrpublic static int getWindowHandle(java.awt.Component component)
component - a heavyweight Java component
public static int getLastError()
public static byte readByte(int ptr)
ptr -
public static short readShort(int ptr)
ptr -
public static int readInt(int ptr)
ptr -
public static long readLong(int ptr)
ptr -
public static void writeByte(int ptr,
byte b)
ptr - b - byte to write at the memory location specified in ptr argument
public static void readShort(int ptr,
short s)
ptr - s - short to write at the memory location specified in ptr argument
public static void writeInt(int ptr,
int i)
ptr - i - int to write at the memory location specified in ptr argument
public static void writeLong(int ptr,
long l)
ptr - l - long to write at the memory location specified in ptr argumentpublic static javax.swing.Icon getIcon(int hicon)
hicon - the HICON to be converted
public static javax.swing.Icon getIcon(int hicon,
int iconSize)
hicon - the HICON to be convertediconSize - icon size typically 16 or 32 - if you don't know the size use getIcon(int hicon)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||