# Sending Large Text Buffers to a Rich Edit Control

This topic is 4386 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys, I've been working with several Rich Edit controls lately. Things were going just fine while the amount of text I was sending was relatively short, but then I hit a snag when my text size got larger than 4K. This is my calling routine and the callback function.

//---------------------------------------------------------------------------
void ForumExportClass::FillExampleExportBox()
{
EDITSTREAM Stream;
string Description;
string rtfPrefix = "{\\rtf1\\ansi\\deff0\\deftab720{\\fonttbl{\\f0\\froman "
"Courier;}}\n{\\colortbl\\red255\\green255\\blue255;\\red230 \\green230\\blue0;"
"\\red100\\green100\\blue255;}\n"
"\\deflang1033\\pard\\plain\\f3\\fs22\\cf0 ";
string rtfPostfix = "\n\\par }";

Description.reserve(32768);

Description = rtfPrefix;
Description += FillExampleExportBoxTitle();
Description += FillExampleExportBoxAbilities();
Description += FillExampleExportBoxSkills();
Description += FillExampleExportBoxLevelBreakdown();
Description += rtfPostfix;

Stream.dwError = false;
Stream.pfnCallback = ExportExampleStreamCallback;
SendMessage(ExampleOutputBox, EM_STREAMIN, SF_RTF, (LPARAM)&Stream);
}

//---------------------------------------------------------------------------
DWORD CALLBACK ExportExampleStreamCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG FAR *pcb)
{

//String smaller than buffer
if( text.length() < cb )
{
*pcb = text.length();
memcpy(pbBuff,text.c_str(),*pcb);
}
//String larger than buffer
else
{
*pcb = cb;
memcpy(pbBuff,text.c_str(),*pcb);
text.erase(0,*pcb-1);
}
return 0;
}


This function works fine as long as text.length() < cb (which is 4K). However, the other case does not work. What happens is the string is printed to the control up to 4K worth of text, but then when it comes back to print the rest, the string is not modified, it just reprints the first 4K again. It does this over and over until the control hits it's max text limit (32K I believe). I've tried various permutations of this, but I simply cannot get it to work :) Anyone see what I'm doing wrong here?

##### Share on other sites
A guess out-my-ass.

Change:
 string text = *(string*)dwCookie;

to
 string& text = *(string*)dwCookie;

This is based off the fact that you seem to think changing the contents of "text" will do something, not off of any understanding of RTF controls. :)

##### Share on other sites
You totally nailed it, NotAYakk. Thank you so much! I was going crazy trying to figure out what was wrong with the control and it wasn't the control at all, heh. I HATE when I drop an ampersand, those are the worst bugs to find.

Thanks, you've saved my sanity. I can continue on with more productive work now.

1. 1
2. 2
frob
14
3. 3
4. 4
5. 5
Rutin
12

• 12
• 11
• 57
• 14
• 15
• ### Forum Statistics

• Total Topics
632114
• Total Posts
3004188

×