All of the _s
functions (swprintf_s
, memcpy_s
) are Microsoft additions. They are part of Microsoft's C library. When you use GCC, you will end up using a different C library, which doesn't include Microsoft's additions (but may include its own additions). Microsoft calls their C library the "CRT" or "C runtime", GCC users refer to it as "libc" or even "glibc" (which is a specific implementation).
If you look at a list of functions in Microsoft's standard C library (MSDN docs), with a sharp eye you'll notice a fairly large number of non-standard functions. Most of these are part of Microsoft's "security enhancements" (MSDN docs). In general, I recommend avoiding the security enhancements since they are non-portable and they are not necessary for writing safe code.
Fix: You can use swprintf
instead of swprintf_s
. The swprintf
function is part of the C standard so it is present on many implementations (although it should be avoided on non-Windows platforms, since it uses wchar_t
).
LPCWSTR foo = L"É %s";
LPCWSTR arg = L"bá";
size_t msgbuflen = wcslen(foo) + wcslen(arg) + 1;
LPCWSTR msg = malloc(len);
if (!msg) error...;
swprintf(msg, msgbuflen, foo, arg);
Note that LPCWSTR
is just a fancy typedef for const wchar_t *
, so you don't need to cast it to wchar_t *
.