It was the main thread (with its new stack) that was causing the corrupted memory due to the stack not being large enough.Previously, without using wcout, there was no memory corruption which makes sense now that it is clear what the problem was.I must say, working with C++ is really painful compared to C# (I used to do it a lot up to about 8 years ago when I started programming mainly in C#).