Twisol said:
This, perhaps?
http://blogs.msdn.com/b/michkap/archive/2004/11/13/257048.aspx
It says it was fixed in MFC 7; VS2005 has MFC 8, and VS2010 has MFC 10. I don't know what's up with the Release build working, though.
I spotted that page, thanks.
Let me show what they are talking about:
void CEditView::ReadFromArchive(CArchive& ar, UINT nLen)
// Read certain amount of text from the file, assume at least nLen
// characters (not bytes) are in the file.
{
ASSERT_VALID(this);
LPVOID hText = LocalAlloc(LMEM_MOVEABLE, (nLen+1)*sizeof(TCHAR));
if (hText == NULL)
AfxThrowMemoryException();
LPTSTR lpszText = (LPTSTR)LocalLock(hText);
ASSERT(lpszText != NULL);
if (ar.Read(lpszText, nLen*sizeof(TCHAR)) != nLen*sizeof(TCHAR))
{
LocalUnlock(hText);
LocalFree(hText);
AfxThrowArchiveException(CArchiveException::endOfFile);
}
// Replace the editing edit buffer with the newly loaded data
lpszText[nLen] = '\0';
#ifndef _UNICODE
if (afxData.bWin95)
{
// set the text with SetWindowText, then free
BOOL bResult = ::SetWindowText(m_hWnd, lpszText);
LocalUnlock(hText);
LocalFree(hText);
// make sure that SetWindowText was successful
if (!bResult || ::GetWindowTextLength(m_hWnd) < (int)nLen)
AfxThrowMemoryException();
// remove old shadow buffer
delete[] m_pShadowBuffer;
m_pShadowBuffer = NULL;
m_nShadowSize = 0;
ASSERT_VALID(this);
return;
}
#endif
LocalUnlock(hText);
HLOCAL hOldText = GetEditCtrl().GetHandle();
ASSERT(hOldText != NULL);
LocalFree(hOldText);
GetEditCtrl().SetHandle((HLOCAL)(UINT)(DWORD)hText);
Invalidate();
ASSERT_VALID(this);
}
The #ifndef _UNICODE only affects code that applies if you are Windows 95, right? Which I'm not, I am testing on XP.
However hoping that was the issue I had in fact forced it to think it *was* Windows 95, see here:
http://github.com/nickgammon/mushclient/commit/24e3b5253cd5c
Effectively I copied and pasted, removing the test for Windows 95 (otherwise not much point). And that worked, the window was not garbage.
Then I found it didn't save, because it was saving from the shadow buffer, not directly from the Edit control. So I changed the way it was written:
http://github.com/nickgammon/mushclient/commit/5e97cdfde237
So far so good. But then I found that the searches found nothing because it was *searching* the shadow buffer. So I thought "this is crazy" and it worked before anyway.
Surely there must be a fix? |