Create safe_copy.c

This commit is contained in:
Jan Bodnar 2016-04-07 15:44:45 +02:00
parent ac8d8b1a38
commit f0d35c6d50

27
strings/safe_copy.c Normal file
View File

@ -0,0 +1,27 @@
#include <windows.h>
#include <strsafe.h>
#include <wchar.h>
int wmain(void) {
wchar_t *sentence = L"Today is a rainy day.";
size_t size = wcslen(sentence) + 1;
wchar_t buf[size];
ZeroMemory(buf, size);
HRESULT r = StringCchCopyW(buf, size, sentence);
if (SUCCEEDED(r)) {
wprintf(L"%ls\n", buf);
} else {
wprintf(L"StringCchCopyW() failed\n");
return 1;
}
return 0;
}