Re: CRichEditCtrl contents from RTF file
"Joseph M. Newcomer" wrote:
Although you test the "remaining" field, I don't see where you set it.
Have you single-stepped any of this to see where it is terminating the read, and why? Or
put breakpoints on the 'return 1' statements?
joe
I do it in OnInitDialog(), I missed that line earlier:
StreamInCookie streamIn;
streamIn.file = &eulaFile;
streamIn.remaining = (DWORD_PTR)eulaFile.GetLength();
EDITSTREAM es;
......
Yes, I've set breakpoints and noticed that the callbacks don't come after
some time. At the last point the callback was received, the "remaining" field
was 36671, and 0 was successfully returned from the callback.
The size of the EULA RTF file is quite big, about 13 pages (about 140 KB).
Not sure if it's got anything to do with the size.
I've created a sample dialog based application to test this, but I don't
think I could upload that here, so you could see the complete code.
Interestingly, the sample that I found here also gives the exact same
behavior, when I try to load the RTF file. It gets truncated at the exact
same point.
http://www.codeproject.com/KB/edit/rulerricheditctrl.aspx?msg=1110746
Thanks again,
JY
On Tue, 27 Apr 2010 08:20:06 -0700, JY <sd@nospamgroup.com> wrote:
Hi Joe,
I've taken some snippets from what you'd posted and I still have the same
problem as earlier. Only a truncated portion of the file appears in the
CRichEditCtrl. Here's my latest code:
class StreamInCookie
{
public:
CFile *file;
DWORD_PTR remaining;
DWORD err;
};
static DWORD CALLBACK EULAStreamInCallback(DWORD_PTR dwCookie, LPBYTE
pbBuff, LONG cb, LONG *pcb)
{
StreamInCookie * streamIn = (StreamInCookie *)dwCookie;
if(streamIn->remaining == 0)
{
*pcb = 0;
streamIn->err = ERROR_SUCCESS;
return 1; // nonzero value terminates read
}
DWORD bytesToRead = min(streamIn->remaining, (DWORD)cb);
UINT bytesRead;
try
{
bytesRead = streamIn->file->Read(pbBuff, bytesToRead);
}
catch(CFileException * e)
{
streamIn->err = e->m_lOsError;
e->Delete();
streamIn->remaining = 0;
return 1;
}
if(bytesRead == 0)
{
streamIn->err = ::GetLastError();
*pcb = 0;
return 1; // return nonzero to stop operation
}
streamIn->remaining -= bytesRead;
*pcb = bytesRead;
streamIn->err = ERROR_SUCCESS;
return 0;
}
BOOL CREPage::OnInitDialog()
{
CBasePage::OnInitDialog();
if (m_strRTFFilePath.GetLength())
{
m_RECtrl.ShowScrollBar(SB_VERT, TRUE);
try
{
StreamInCookie streamIn;
CFile eulaFile(m_strRTFFilePath, CFile::modeRead|CFile::shareExclusive);
streamIn.file = &eulaFile;
EDITSTREAM es;
es.dwCookie = (DWORD_PTR)&streamIn;
es.pfnCallback = (EDITSTREAMCALLBACK)EULAStreamInCallback;
m_RECtrl.StreamIn(SF_RTF, es);
}
catch (CFileException *pEx)
{
//not shown for brevity
}
}
return TRUE;
}
Thanks,
JY
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.