wsprintf と sprintf
Win32 API に、 wsprintf という関数がある。一見すると、C標準の sprintf と同じ、いや、 UNICODE が定義されていると、ワイド版になるところも含めると、_stprintf か?と思ったら、実は wsprintf は sprintf にはない制限事項が。
wsprintfThe wsprintf function formats and stores a series of characters and values in a buffer. Any arguments are converted and copied to the output buffer according to the corresponding format specification in the format string. The function appends a terminating null character to the characters it writes, but the return value does not include the terminating null character in its character count.
int wsprintf(
LPTSTR lpOut, // pointer to buffer for output
LPCTSTR lpFmt, // pointer to format-control string
... // optional arguments
);
Parameters
- lpOut
- Pointer to a buffer to receive the formatted output. The maximum size of the buffer is 1024 bytes.
- lpFmt
- Pointer to a null-terminated string that contains the format-control specifications. In addition to ordinary ASCII characters, a format specification for each argument appears in this string. For more information about the format specification, see the Remarks section.
- ...
- Specifies one or more optional arguments. The number and type of argument parameters depend on the corresponding format-control specifications in the lpFmt parameter.
そう、出力結果の上限が 1024 バイトまでなのだ。それを越えた出力結果はちょん切られる。終端には '\0' が付かないようである。sprintf では、上限は知らないけど、もっと大きなサイズを扱うことができるのは確かである。
トラックバック
- このエントリーにトラックバック:
- http://frog.raindrop.jp/cgi-bin/mt/mt-tb.cgi/523
コメント