mirror of
https://github.com/janbodnar/Windows-API-examples.git
synced 2024-11-24 11:25:30 +00:00
Create safe_copy.c
This commit is contained in:
parent
ac8d8b1a38
commit
f0d35c6d50
27
strings/safe_copy.c
Normal file
27
strings/safe_copy.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user