<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><font style="font-size: 12pt;" face="Arial" size="3">Hello great fpc people.</font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3">It is about functions dealing with string </font><font style="font-size: 12pt;" face="Arial" size="3"><font style="font-size: 12pt;" face="Arial" size="3"> inside a library</font>.</font><font style="font-size: 12pt;" face="Arial" size="3">..<br></font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3">If i use that kind of function inside the library :</font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3">>> InLibStringFunction() : PChar </font><font style="font-size: 12pt;" face="Arial" size="3">;</font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3">It will be the memory manager of the library who deals with the PChar result.</font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3">So difficult for the main application to manage the memory used by PChar.</font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3">Some good guru show me the way how to deal with string result inside a library :<br><br></font><font style="font-size: 12pt;" face="Arial" size="3"></font><font style="font-size: 12pt;" face="Arial" size="3">>> In library :
</font><pre class="wbox"><font style="font-size: 12pt;" face="Arial" size="3">MyStrTest(inStr:Pchar; outStr:pChar; size:integer):integer; cdecl;
var
MyRealResult :string;
begin
MyRealResult := inStr + ' added by function ';
Result := length(myRealResult);
if size >= result then move(OutStr[0], MyRealResult[1], result);
end;
</font><div class="quote3"><font style="font-size: 12pt;" face="Arial" size="3">>> And in main program :<br> </font></div><font style="font-size: 12pt;" face="Arial" size="3">function testLib(InputText : string) : string ;
var
MyStrOut : string;
MyLen : integer;
begin
MyLen := MyStrTest( @InputText[1],@MyStrOut[1], 0);
SetLEngth(MyStrOut, mylen+1);
FillChar(MyStrOut[1], MyLen+1,0);
MyStrTest(@InputText[1], @MyStrOut[1], 0);
result := MyStrOut ;
end;
I have test it but, sadly, MyStrOut is always a empty string... ;-(
Could somebody give a working code ?<br>Or maybe, does it exist a better way to do it ?<br><br>Many thanks.<br><br>Fred.<br></font></pre><font style="font-size: 12pt;" face="Arial" size="3"></font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><br> </div></body>
</html>