Hi,

I have some serious problem with memory corruption on the heap, using the new and delete [] operators with TCHAR * and MultiByteToWideChar() function.

I´ve been working on an application for WinCE with VC++ Embeded and all the strings have to be converted to UNICODE. Up to here that´s OK. The problem starts when I use a code like this :

Code:
...
   int iBufferLen;
   TCHAR * Buffer;
   Buffer = new TCHAR[ iBufferLen ] ;
...
   WideCharToMultiByte(...);
...
   delete [] Buffer; // <- HERE HEAPENS THE BUG!
And the BUG is :
"When the program line execute the delete [] Buffer; another part of memory is erased and this causes memory corruption."

Does anyone have any idea of what is going on ?

Thanks in advanced.
Best Regards.

Marcelo Franco
Brazil.