I am writing in C++ using MFC under Visual Studio 2022.
I have a CRichEditCtrl embedded in a dialog, and I want to feed it pre-formatted text markup written with an external RTF editor. In the end I want to embed the text within the program (to avoid having an external file), and so far as I can see the only way to do this is by putting the text into a CMemFile and then using CRichEditCtrl::StreamIn. If there is a better way of doing this I'd like to hear about it.
However, to start off I just tried to read from an external RFT file using the example code from the MSoft documentation.
For completion, here is my code version:
CFile cFile(TEXT("NeuroSimHelp.rtf"), CFile::modeRead);
EDITSTREAM es;
es.dwCookie = (DWORD)&cFile;
es.pfnCallback = FileStreamInCallback;
m_HelpRTF.StreamIn(SF_RTF, es);
static DWORD CALLBACK FileStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb);
static DWORD CALLBACK FileStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb)
{
CFile* pFile = (CFile*)dwCookie;
*pcb = pFile->Read(pbBuff, cb);
return 0;
}
This compiles and runs fine in x86 mode, but fails to compile in x64 mode.
The problem lies in the line:
es.pfnCallback = FileStreamInCallback;
which generates the compile error:
error C2440: '=': cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK'
As I said, this compiles and works in x86, so I guess the 64-bit callback function address does not fit into the DWORD_PTR dwCookie in EDITSTREAMCALLBACK type.
I'm probably missing something obvious, but if anyone knows how to fix this the help would be much appreciated.
Thanks,
Bill H