Hello great fpc people. It is about functions dealing with string inside a library...
If i use that kind of function inside the library : >> InLibStringFunction() : PChar ; It will be the memory manager of the library who deals with the PChar result. So difficult for the main application to manage the memory used by PChar. Some good guru show me the way how to deal with string result inside a library : >> In library : 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; >> And in main program : 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 ? Or maybe, does it exist a better way to do it ? Many thanks. Fred.
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal