Please help! I need this conversion to write wrapper for some C headers for Delphi.
As an example:
function pushfstring(fmt: PAnsiChar): PAnsiChar; c
The wrapper you are trying to write is possible in Free Pascal, since Free Pascal supports 2 equvalent declarations for varargs external functions:
http://www.freepascal.org/docs-html/ref/refsu68.html
so instead of
function pushfstring(fmt: PAnsiChar): PAnsiChar; cdecl; varargs; external;
you should write
function pushfstring(fmt: PAnsiChar; Args: Array of const): PAnsiChar; cdecl; external;
Update: I have tried the same trick in Delphi, but it does not work:
//function sprintf(S, fmt: PAnsiChar; const args: array of const): Integer;
// cdecl; external 'MSVCRT.DLL';
function sprintf(S, fmt: PAnsiChar): Integer;
cdecl; varargs; external 'MSVCRT.DLL';
procedure TForm1.Button1Click(Sender: TObject);
var
S, fmt: Ansistring;
begin
SetLength(S, 99);
fmt:= '%d - %d';
// sprintf(PAnsiChar(S), PAnsiChar(fmt), [1, 2]);
sprintf(PAnsiChar(S), PAnsiChar(fmt), 1, 2);
ShowMessage(S);
end;