This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes JNI with C++ structures Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JNI with C++ structures" Watch "JNI with C++ structures" New topic
Author

JNI with C++ structures

John Coleman
Ranch Hand

Joined: Jul 24, 2001
Posts: 65
Hi,

I want to call a function in C++ that returns a pointer to a structure array, like this

BOOL __stdcall GetPositionBlotter(int* iCount, void* RecArray);

Where RecArray is elements like this

typedef struct _POSITIONREC {
char SymIdent[20];
char SymExchange[15];
char SymSecType[20];
char SymExpiry[30];
char SymRight[30];
char SymCurrency[20];
DWORD Quantity;
double MarketPrice;
double MarketValue;
double AverageCost;
double UnrealizedPNL;
double RealizedPNL;
} POSITIONREC, *LPPOSITIONREC;
;

How do I get that C++ structure back to Java? I suppose I need an array of a class? I guess somehow I need to instantiate those classes in C++ and load the fields in a loop and pass them back as the result.

Can anyone provide simple example code of how I do that please?

John


John Coleman, MSTA<br />Sun Certified Programmer for the Java� 2 Platform<br />john.coleman@eurobase-international.com<br />Eurobase banking solutions<br /><a href="http://www.eurobase-international.com/banking" target="_blank" rel="nofollow">http://www.eurobase-international.com/banking</a>
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
Very simple but complete working example. Study it thoroughly:

Regards
 
jQuery in Action, 2nd edition
 
subject: JNI with C++ structures
 
Similar Threads
Converting an array to a Vector -> Simple question with many doubts
need to convert string to unicode char array
Converting Strings to ints and other impracticalities
Data Structure
Data Structure Transfer