mirror of
https://github.com/janbodnar/Windows-API-examples.git
synced 2024-11-24 03:15:30 +00:00
Create safe_format.c
This commit is contained in:
parent
e931200175
commit
b13b341216
28
strings/safe_format.c
Normal file
28
strings/safe_format.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include <windows.h>
|
||||||
|
#include <strsafe.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
#define BUF_LEN 256
|
||||||
|
|
||||||
|
int wmain(void) {
|
||||||
|
|
||||||
|
wchar_t *word = L"table";
|
||||||
|
int count = 6;
|
||||||
|
|
||||||
|
wchar_t buf[BUF_LEN] = {0};
|
||||||
|
wchar_t *line = L"There are %d %lss";
|
||||||
|
|
||||||
|
HRESULT r = StringCchPrintfW(buf, ARRAYSIZE(buf), line, count, word);
|
||||||
|
|
||||||
|
if (SUCCEEDED(r)) {
|
||||||
|
|
||||||
|
wprintf(L"%ls\n", buf);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
wprintf(L"StringCchPrintfW() failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user