This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes JNI - using native data types in java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JNI - using native data types in java code" Watch "JNI - using native data types in java code" New topic
Author

JNI - using native data types in java code

Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
I'm probably the only person in the world that wishes to do this but here goes. I have some C code which defines a few structures. I want to use these structures inside my java code but don't know how to represent them. There isn't any typedef or struct inside of java so I am clueless as to how to use them from within my java code. Does JNI support passing these types back and forth between java and native code?
Can classes be defined as native and defined in native code?
Thanks,
Frank
Pawel Veselov
Ranch Hand

Joined: Jan 14, 1999
Posts: 165
No, classes can't be defined native.
As for structures - since Java doesn't have structures, you have to define a class with fields only and then access this fields copying data from/to your native structures.
You can't pass a custom structure to/from JNI.

------------------
With best of best regards, Pawel S. Veselov ( aka Black Angel )


With best of best regards, Pawel S. Veselov ( aka Black Angel )
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JNI - using native data types in java code