I tried this code in VS2017 and it worked correctly. I made only slight changes.
void mergeWChar( wchar_t*& dest, const wchar_t* source )
{
if( dest == nullptr )
{
dest = const_cast<wchar_t*>( source );
return;
}
size_t count = wcslen( dest ) + wcslen( source ) + 1;
wchar_t * newdest = (wchar_t*)malloc( count * sizeof( wchar_t ) );
wcscpy( newdest, dest );
wcscat( newdest, source );
dest = newdest;
}
void DoMergeCharTest()
{
wchar_t* msg = nullptr;
wchar_t* wcs1 = _T( "Son" );
wchar_t* wcs2 = _T( "Van" );
trace( _T( "MergeCharTest : '%s' and '%s'\n" ), wcs1, wcs2 );
mergeWChar( msg, wcs1 );
mergeWChar( msg, wcs2 );
trace( _T( "result is '%s'\n" ), msg );
free( msg );
}
The output was :
MergeCharTest : 'Son' and 'Van'
result is 'SonVan'