FPC 3.2.2 Call Through don't work lazarus / 21-General ---------------------------------------------------------------------- paule32 · 2025-04-17 16:02 Hello, My Goal is to call through a wrapper Function to Append Strings as PChar. But I fail. I have the following Code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function StrCat_(Dest: PChar; Source: PChar): PChar; stdcall; export;var  D: PChar;begin  D := Dest;  while D^ <> #0 do    Inc(D);   // Hänge Source an  while Source^ <> #0 do  begin    D^ := Source^;    Inc(D);    Inc(Source);  end;   D^ := #0; // Nullterminator  Result := Dest;end;function StrCat(Dest: PChar; Source: PChar): PChar; stdcall;var  R: PChar;begin  result := StrCat_(R, Source);end;  Then in Code, the Call: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function foo;var  cmdline   : PAnsiChar;  Args      : PPAnsiChar;  ArgsCount : Integer;  R         : PChar;  TotalLen  : Integer;begin  result := nil;  CmdLine := GetCommandLineA;  Args    := CommandLineToArgvA(CmdLine, ArgsCount);    if Args = nil then  begin  MessageBoxA(0,'Error: can not parse command line.', 'Error', MB_OK);    ExitProcess(1);  end;        TotalLen := 128;    R := StrAlloc(TotalLen);    StrCopy(R, 'Count of Parameters: ');  StrCat(R, IntToStr(ArgsCount));    MessageBoxA(0, R, '222  11  222', 0);    StrDispose(R);  ExitProcess(0);end; the StrCat don't append the ArgsCount. When I use StrCat_ then the ArgsCount will be append to R I don't know how to fix this. Is the reserved TotalLen Space to small ? ---------------------------------------------------------------------- cdbc · 2025-04-17 16:42 Hi This:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function StrCat(Dest: PChar; Source: PChar): PChar; stdcall;var  R: PChar;begin  result := StrCat_(R, Source);end;tries to concatenate source onto 'R', which is totally unallocated!!! Sorry to have to say that it's useless! The first algorithm seems ok though... Regards Benny ---------------------------------------------------------------------- Thaddy · 2025-04-17 16:52 Use strlen on source and getmem/allocmem with that length for dest. Horrible code, though. C style string handling is way inferior to Pascal strings. It is also slower because strlen is slow (linear) and Pascal strings store length(one read). ---------------------------------------------------------------------- paule32 · 2025-04-17 18:35 yes, FPC is extremly fast and it extremly optimized the Code. I thought that C is a fast high level DSL ? Okay. Thanks for the reply.