wvsprintf function Declaration:
wvsprintf (Output:pchar; {The buffer to return} Format:pchar; {format, similar to format, should be the same format as the C language of printf}{array pointer}{Returns the length of the actual string to the buffer}
Examples of wvsprintf functions:
//Example one:varBuf:pchar; ArrArray[0..1] ofPointer;beginBUF: = PChar (Stringofchar (#0,255));{I prepare buffers like this}arr[0]: = PChar (' ln case '); arr[1]: = Pointer (123); wvsprintf (BUF,'%s,%d ', @arr); ShowMessage (BUF);{Show Results: In case, 123}End;//Case TWO:varBuf:pchar; ArrArray ofPointer;the difference between {and the previous example is that a dynamic array is used here}beginBUF: = PChar (Stringofchar (#0,255)); SetLength (arr, Length (arr) +1); Arr[high (arr)]: = PChar (' ln case '); SetLength (arr, Length (arr) +1); Arr[high (arr)]: = Pointer (123); wvsprintf (BUF,'%s,%d ', PChar (arr));//wvsprintf (buf, '%s,%d ', @arr [0]); {or so}ShowMessage (BUF);{Show Results: In case, 123}End;
wsprintf function and wvsprintf difference is: wvsprintf to a set of data; wsprintf is a data pair. The statement reads as follows:
{The buffer to return} {format} {data pointer} {The length of the actual string returned to the buffer}
It is particularly necessary to note that in Delphi 2007, wsprintf function declaration error, a parameter is missing; You need to re-declare it when you use it:
If only in this unit use can be declared as follows:
... Implementation {$R *.DFM} function stdcall External ' WSPRINTFA ';
If global use requires this declaration:
... function stdcall; var Form1:tform1; Implementation {$R *.DFM} function External ' WSPRINTFA ';
Examples of wsprintf functions:
functionwsprintf (Output:pchar; Format:pchar; Data:pointer): Integer;stdcall;ExternalUser32 Name' WSPRINTFA ';procedureTform1.formcreate (Sender:tobject);varBuf:pchar;beginBUF: = PChar (Stringofchar (#0,255)); wsprintf (BUF,' I am%s ', PChar (' ln case ')); ShowMessage (BUF);{I was in case}wsprintf (BUF,' It's%d years ', Pointer ( -)); ShowMessage (BUF);{Now is 2008}End;
Finally, test them in hexadecimal with the Format function (the Delphi format function is rewritten with assembler, not calling the API):
varBuf:pchar; ArrArray[0..0] ofPointer; I:integer;beginBUF: = PChar (Stringofchar (#0,255)); I: = MaxInt; arr[0]: = Pointer (i); ShowMessage (Format ('%x ', [i]));{7FFFFFFF}SHOWMESSAGEFMT ('%x ', [i]);{7FFFFFFF}wvsprintf (BUF,'%x ', @arr); ShowMessage (BUF);{7FFFFFFF}End;
Formatted output function for winapi:wvsprintf and wsprintf-windows (RPM)