[fpc-pascal] android JNI JString to String
herux
heruxi at gmail.com
Tue Apr 26 10:37:03 CEST 2011
I have a strange problem, I pass data from the android String via JNI. pass
data from FreePascal wideString successfully using the following code
NewString: function (Env: PJNIEnv; const Unicode: PJChar; Len: JSize):
JString; cdecl;
GetStringChars:function(Env:PJNIEnv;Str:JString;IsCopy:PJBoolean):PJChar;
cdecl;
function JNI_WideStringToJString(Env: PJNIEnv; const WStr: WideString):
JString;
begin
Result := Env^.NewString(Env, Pointer(WStr), Length(WStr));
end;
but when passing data JString to widestring, using this code :
function JNI_JStringToWideString(Env: PJNIEnv; JStr: JString): WideString;
var
IsCopy: JBoolean;
Chars: PJChar;
begin
if (JStr = nil) then begin
Result := '';
Exit;
end;
Chars := Env^.GetStringChars(Env, JStr, IsCopy);
if (Chars = nil) then begin
Result := ''
end else begin
Result := WideString(Chars);
Env^.ReleaseStringChars(Env, JStr, Chars);
end;
end;
return only 1 character leading.
if anyone has ever experienced ? or there's something wrong with JNI header
?
thanks
-----
-
--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/android-JNI-JString-to-String-tp4340388p4340388.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
More information about the fpc-pascal
mailing list