I am in the process of taking some 3rd party c++ source code, and converting it to VS2005. One thing I noticed over and over, is that when you are reading in file contents, you need to make sure to release the buffer, but with the length of the file as the parameter.
For example, this code:
CString myData;
if (file.Open(lpszFilename, CFile::modeRead))
{
DWORD dwLength = file.GetLength();
file.Read(myData.GetBuffer(dwLength), dwLength);
myData.ReleaseBuffer();
file.Close();
}
will throw an assertion when in debug mode
to fix, add the dwLength value to your ReleaseBuffer()
myData.ReleaseBuffer(dwLength);
if you run the bad code in release mode, nothing happens, which suprises me, you would think that the runtime would croak, but it doesn’t. Anyways, make sure to release your buffers.