Skip to main content

char* Please Help JNA

No replies
ogoto1
Offline
Joined: 2010-03-02

Hi,

I would really appreciate your professional feedback on handling char* for Java Strings via JNA. I apologize in advanced and hope this is a concise to the point example.

==========================================================
I have the following:
in my .h:
char* DLLEXPORT getReport();

==========================================================
my .c:
char* returnMessage(char *message)
{
char *s=" Twist";
return strcat(message,s);;
}

char* getReport(){
char *ptrTest = NULL;
char test[] = "Oliver";
ptrTest = test;
char* ptrRtn = returnMessage(ptrTest);
printf("%s",ptrRtn);
return ptrRtn;
}

===================================================
The Java end:
public interface ELib extends Library {

....
....
String getReport();

}

====================================================
My java User for the ELib:

ELib lib = (ELib) Native.loadLibrary ("/usr/enew/core/DLL Debug/libcore.dll",
ELib.class);

String str = lib.getReport();

System.out.println("s: "+str);
=============================================================
What I get is the following output:

The C end I get Oliver Twist ----- printf("%s",ptrRtn);
the s: Java end is binary ------- System.out.println("s: "+str);

============================================================
Is there magic that I need to complete to get the char* from C to the Java String????
the str leading not to binary???? I feel like I have a cube and a round hole.
============================================================
I've played with multiple things and had a mental core dump up to this point :-)
Any input would be greatly appreciated.
============================================================

on interesting thing is that the char* gerReport----->

return ("123456");
gives me java on the correct end ok.... odd but i'm unable to get anything else to work.

Thank you for in advance and I really look forward to hearing from you.