Wsprintf, a common function in Win32 API, is a string Formatting Function that translates numeric values into strings in the specified format. It is similar to the printf function in C language. Its prototype is as follows:
Int wsprintf (
Lptstr lpout, // output buffer address
Lpctstr lpfmt, // format the string address
... // Variable list
The number of variable lists is specified by the formatting string. wsprintf processes the formatting string and directly copies the string to the output if a common character is encountered. If % character is encountered, there is a variable, different letters after % indicate different output formats. For example, % d indicates that the output is an integer, % x indicates that the output is hexadecimal, and % s indicates the output string.
The % symbol can be used between letters such as D, X, and s to specify the length of the bit occupied by the output. If the length of the output bit is not long enough, the function will fill in space. In addition, you can add 0 before the number indicating the bit length to indicate that "0" rather than a space is used for filling, for example, % 08x indicates the hexadecimal number filled with 0 in front of the 8-digit output.
Wsprintf is Win32
The API only has a function with an indefinite number of parameters. When using the wsprintf function, the number of parameters depends on the number specified by the "%" sign in the formatting string, the number of variable lists, and the number of formatting strings.
The % format must be one-to-one. If the letters D, x s, and so on are uppercase, the output string is uppercase.
Invoke wsprintf, ADDR szbuffer, ADDR szreceive, lparam, lparam
This statement converts the value of lparam and the string of lparam according to the format defined by szreceive formatting string, and stores the result in szbuffer. Then, the program displays the content of szbuffer in a message box:
Invoke MessageBox, hwnd, offset szbuffer, ADDR szcaptionmain, mb_ OK