[5275] in java-interest
Re: Returning arrays from native methods...
daemon@ATHENA.MIT.EDU (Pradeep Badri)
Sun Feb 4 21:51:47 1996
From: Pradeep Badri <pbadri@cisco.com>
To: descarte@hermetica.com (Alligator Descartes)
Date: Sun, 4 Feb 96 17:32:33 PST
Cc: java-interest@java.sun.com
In-Reply-To: <199602042018.UAA24784@fruitbat.mcqueen.com>; from "Alligator Descartes" at Feb 4, 96 8:18 pm
Here's a sample code of ftn returniong an array of bytes :
You will have to substitute the data type as needed.
java declaration would be native byte[] someFtn() ;
the C code would be:
HArrayOfByte *mypkg_someFtn(........)
{
HArrayOfByte *pbyteBuf ;
char *someData = "Some data..." ;
pbyteBuf = (HArrayOfByte *)ArrayAlloc(T_BYTE, strlen(someData)) ;
if (pbyteBuf == 0) {
SignalError(0, JAVAPKG, "OutOfMemoryException", 0) ;
return NULL ;
}
memcpy((char *)unhand(pbyteBuf)->body, (char *)someData,
sizearray(T_BYTE, strlen(someData)) ;
return pbyteBuf ;
}
Hope it helps.
-pradeep.
Pradeep Badri.
Cisco Systems.
>
>
> Hi all. I'm attempting to return an array of ints back from a
> native method, but seem to be having no luck at all with the
> endeavour.
>
> Returning Strings and single value seem fine, but arrays are
> eluding me completely.
>
> Can someone give me a pointer here? The page in question on
> java.sun.com has got the interminably irritating "Piss off,
> we haven't written it yet" message.
>
> Regards.
>
> --
> Alligator Descartes | "...Nil posse creari De nilo"
> descarte@hermetica.com | -- Lucretius, De Rerum Natura I, l.155
> http://www.hermetica.com/descarte |
> -
> This message was sent to the java-interest mailing list
> Info: send 'help' to java-interest-request@java.sun.com
>
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com