Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Sun, 8 Jun 2008 03:52:39 -0700 (PDT),    group: microsoft.public.win32.programmer.ui        back       


Rich Editbox Callback Function   
Hey guys,

This regards my rich edit control. I send it a large string (on the
order of a few thousand characters) with the function:

void ForumExportClass::FillExampleExportBox()
 {
 EDITSTREAM Stream;
 string Description;
 string rtfPrefix = "{\\rtf1\\ansi\\deff0\\deftab720{\\fonttbl{\\f0\
\froman "
   "Courier;}}\n{\\colortbl\\red255\\green255\\blue255;\\red255\
\green165\\blue0;"
   "\\red192\\green192\\blue192;\\red255\\green250\\blue205;"
   "\\red255\\green192\\blue203;\\red245\\green222\\blue179;"
   "\\red173\\green216\\blue230;\\red152\\green251\\blue152;}\n"
   "\\deflang1033\\pard\\plain\\f3\\fs22\\cf0 ";
 string rtfPostfix = "\n\\par }";

 Description.reserve(50000);

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

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

So far so good, as far as I can tell, Description always contains what
it is supposed to. Then it goes to the callback function. 9 times out
of 10, this function returns exactly what it is supposed to, but from
time to time it will cut off the text prematurely or put in extra text
at the end. Somewhere I have a bug in my callback function. Does
anyone see what I'm doing wrong?

DWORD CALLBACK ExportExampleStreamCallback(DWORD dwCookie, LPBYTE
pbBuff, LONG cb, LONG FAR *pcb)
 {
 string &text = *(string*)dwCookie;

 //String smaller than buffer
 if( text.length() < (unsigned int)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;
 }
date: Sun, 8 Jun 2008 03:52:39 -0700 (PDT)   author:   Ron Hiler

Re: Rich Editbox Callback Function   
I think both string::length and the cb parameter do not include the 
terminating null and you seem to assume they do.


"Ron Hiler"  wrote in message 
news:4efe7ec4-7cb8-4f79-a2f6-0698e82b1bd6@u6g2000prc.googlegroups.com...
> Hey guys,
>
> This regards my rich edit control. I send it a large string (on the
> order of a few thousand characters) with the function:
>
> void ForumExportClass::FillExampleExportBox()
> {
> EDITSTREAM Stream;
> string Description;
> string rtfPrefix = "{\\rtf1\\ansi\\deff0\\deftab720{\\fonttbl{\\f0\
> \froman "
>   "Courier;}}\n{\\colortbl\\red255\\green255\\blue255;\\red255\
> \green165\\blue0;"
>   "\\red192\\green192\\blue192;\\red255\\green250\\blue205;"
>   "\\red255\\green192\\blue203;\\red245\\green222\\blue179;"
>   "\\red173\\green216\\blue230;\\red152\\green251\\blue152;}\n"
>   "\\deflang1033\\pard\\plain\\f3\\fs22\\cf0 ";
> string rtfPostfix = "\n\\par }";
>
> Description.reserve(50000);
>
> Description = rtfPrefix;
> Description += FillExampleExportBoxHeader();
> Description += FillExampleExportBoxTitle();
> Description += FillExampleExportBoxAbilities();
> Description += FillExampleExportBoxSkills();
> Description += FillExampleExportBoxNotableEquipment();
> Description += FillExampleExportBoxLevelBreakdown();
> Description += rtfPostfix;
>
> Stream.dwCookie = (DWORD)&Description;
> Stream.dwError = false;
> Stream.pfnCallback = ExportExampleStreamCallback;
> SendMessage(ExampleOutputBox, EM_STREAMIN, SF_RTF, (LPARAM)&Stream);
> }
>
> So far so good, as far as I can tell, Description always contains what
> it is supposed to. Then it goes to the callback function. 9 times out
> of 10, this function returns exactly what it is supposed to, but from
> time to time it will cut off the text prematurely or put in extra text
> at the end. Somewhere I have a bug in my callback function. Does
> anyone see what I'm doing wrong?
>
> DWORD CALLBACK ExportExampleStreamCallback(DWORD dwCookie, LPBYTE
> pbBuff, LONG cb, LONG FAR *pcb)
> {
> string &text = *(string*)dwCookie;
>
> //String smaller than buffer
> if( text.length() < (unsigned int)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;
> }
>
date: Sun, 8 Jun 2008 11:16:46 -0700   author:   Sam Hobbs _change_social_to_socal

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us