Hello,
My Goal is to call through a wrapper Function to Append Strings as PChar.
But I fail.
I have the following Code:
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:
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 ?