The main problem is where you write wcslen(say)
. At the point where you write it, say
has not been initialized and so wcslen(say)
invokes UB. You meant to write sizeof(say)/sizeof(wchar_t)
.
On top of that, sizeof(buff)
is the size in char
units. But the array has wchar_t
units. So that code is wrong.
You want something like this:
wchar_t buff[] = L"unable to start because %ls cannot be found.";
wchar_t say[MAX_PATH + sizeof(buff)/sizeof(wchar_t) - 3];
swprintf(say, sizeof(say)/sizeof(wchar_t), buff, filename);