@@ -238,9 +238,42 @@ void CTextView::SerializeRaw(CArchive& ar)
238
238
{
239
239
CFile* pFile = ar.GetFile ();
240
240
ASSERT (pFile->GetPosition () == 0 );
241
- DWORD nFileSize = pFile->GetLength ();
241
+ DWORD nLen = pFile->GetLength ();
242
242
// ReadFromArchive takes the number of characters as argument
243
- ReadFromArchive (ar, (UINT)nFileSize/sizeof (TCHAR));
243
+
244
+ // REPLACING: ReadFromArchive(ar, (UINT)nFileSize/sizeof(TCHAR));
245
+
246
+ // with this (we got garbage at times):
247
+
248
+ LPVOID hText = LocalAlloc (LMEM_MOVEABLE, (nLen+1 )*sizeof (TCHAR));
249
+ if (hText == NULL )
250
+ AfxThrowMemoryException ();
251
+
252
+ LPTSTR lpszText = (LPTSTR)LocalLock (hText);
253
+ ASSERT (lpszText != NULL );
254
+ if (ar.Read (lpszText, nLen*sizeof (TCHAR)) != nLen*sizeof (TCHAR))
255
+ {
256
+ LocalUnlock (hText);
257
+ LocalFree (hText);
258
+ AfxThrowArchiveException (CArchiveException::endOfFile);
259
+ }
260
+ // Replace the editing edit buffer with the newly loaded data
261
+ lpszText[nLen] = ' \0 ' ;
262
+
263
+ // set the text with SetWindowText, then free
264
+ BOOL bResult = ::SetWindowText (m_hWnd, lpszText);
265
+ LocalUnlock (hText);
266
+ LocalFree (hText);
267
+
268
+ // make sure that SetWindowText was successful
269
+ if (!bResult || ::GetWindowTextLength (m_hWnd) < (int )nLen)
270
+ AfxThrowMemoryException ();
271
+
272
+ // remove old shadow buffer
273
+ delete[] m_pShadowBuffer;
274
+ m_pShadowBuffer = NULL ;
275
+ m_nShadowSize = 0 ;
276
+
244
277
}
245
278
ASSERT_VALID (this );
246
279
} /* end of CTextView::SerializeRaw */
0 commit comments