I have string in BSTR, and I would like to convert it using W2CA (WideCharToMultiByte):
USES_CONVERSION;
std::string myMBS = W2CA(myBSTR); // myBSTR is BSTR
But when string is extremely large - it throws exception "StackOverFlowException" on this line.
But when I use this:
std::wstring myWide(myBSTR);
std::string myMBS(myWide.begin(), myWide.end());
I works fine. Could anyone help with this behavior?
UPDATE: With large string I mean string about 10MB.
Look at the actual definition of
W2CA
fromatlconv.h
:Now look at the definition of
W2A
:It calls
alloca
, which allocates memory on the stack. So naturally if the string is very long, you risk exhausting the available stack space.