This line is wrong:
swprintf(wWork, sizeof(wWork), L"%ls", achKey);
First error:
Parameters are for
snwprintf
.
Second error:
You are specifying a wide string in the format but passing a char string. Use "%hs" instead of "%ls".
So it must be
snwprintf(wWork, sizeof(wWork), L"%hs", achKey);
or
swprintf(wWork, L"%hs", achKey);
[EDIT]
When not using a Unicode build, you must also use
MessageBoxW
and pass the title as wide string:
MessageBoxW(GetForegroundWindow(),
wWork,
L("Error"),
MB_OK | MB_ICONERROR | MB_APPLMODAL);