Hello,

I need to migrate a project in VC6 to Visual Studio 2005 (VC8) and got a problem. Basically, I need an array of CString. The original code is:

CString* pLabel = (CString*) new BYTE[ nArraySize * sizeof(CString) ];
ConstructElements( pLabel, nArraySize );
// ...some string assignment of pLabel and other function calls

// the way the array is deleted is
delete[] (BYTE*)pLabel ;

Since ConstructElements() is not available in VC8, I have difficulty to find a way to replace it. Also, this array is used by many other functions or even other external projects so I can't change it to CStringArray or other forms.

Anyway, I try to modified the code in VC8 as:

CString* pLabel = (CString*) new BYTE[ nArraySize * sizeof(CString) ];
memset( (void*)pLabel, 0, nArraySize * sizeof(CString) );
for( int i = 0; i < nArraySize; i++, pTmp++ )
::new((void*)pTmp)CString; // call constructor

This change works OK in the projects. However, I got memory leak.

Can anybody help? Thank you very much.