Formatted output function for winapi:wvsprintf and wsprintf-windows (RPM)

Source: Internet
Author: User

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 stdcallvar 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.