Look at the actual definition of W2CA
from atlconv.h
:
#define W2CA(lpw) ((LPCSTR)W2A(lpw))
Now look at the definition of W2A
:
#define W2A(lpw) (\
((_lpw = lpw) == NULL) ? NULL : (\
(_convert = (lstrlenW(_lpw)+1), \
(_convert>INT_MAX/2) ? NULL : \
ATLW2AHELPER((LPSTR) alloca(_convert*sizeof(WCHAR)), _lpw,
_convert*sizeof(WCHAR), _acp))))
It calls alloca
, which allocates memory on the stack. So naturally if the string is very long, you risk exhausting the available stack space.