Author Topic: RichEd20.DLL bugs  (Read 118 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
RichEd20.DLL bugs
« on: September 24, 2017, 08:14:04 PM »
Searching the forum, I just realised that we do not yet have a dedicated thread on bugs in Microsoft's RichEdit control. So I hope we can collect observations here, and I kindly ask you for real contributions, not philosophical observations.

If you have a bug to report, please modify the title of the post, and try to be very brief and to the point.
« Last Edit: September 24, 2017, 11:34:06 PM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
RichEd20.DLL tables
« Reply #1 on: September 24, 2017, 11:31:14 PM »
Let's start with a really exotic bug: The way the RichEdit control stores tables. I stumbled over this one when trying to create a "serial letter" application. It uses a template wirh tags:
Code: [Select]
This file was created on #date#
#column1# #column2# #column3#
#value11# #value12# #value13#
#value21# #value22# #value23#

In the RTF file (attached), it is a nice table. You can read the whole file into a string, replace the tags with appropriate values, save the result, and voilà, there is a RTF file ready for printing. Code:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Let esi=FileRead$("TemplateHashes.rtf")       ; read a template into a buffer
  Let esi=Replace$(esi, "#date#", Date$)        ; replace tags
  Let esi=Replace$(esi, "#column1#", "First column")
  Let esi=Replace$(esi, "#column2#", "Second column")
  Let esi=Replace$(esi, "#column3#", "Third column")
  FileWrite "LetterHashes.rtf", esi             ; save result
  ShEx "LetterHashes.rtf"                       ; and open it in the default editor
EndOfCode


The line "This file was created on #date#" works fine. Always.

The table works fine if your template was saved with certain versions of RichEd20.dll, but it fails miserably if the template was saved with others :(

Code: [Select]
System32 ; OK (but C:\Windows\System32\RichEd20.dll is utterly slow and lacks many features)
Office15 ; OK (but has some other bugs)
Office14 ; bad
Office12 ; bad
Office11 ; OK

Why this?

A line of a table gets typically saved as follows:
Code: [Select]
\pard\intbl\nowidctlpar\cf2\i0 #column1#\cell #column2#\cell #column3#\cell\row\trowd\trgaph70\trleft-30\trpaddl70\trpaddr70\trpaddfl3\trpaddfr3
The interesting part is
Code: [Select]
\cell #column2#\cell #column3#After the replacing of tags, it becomes
Code: [Select]
\cell Second column\cell Third column
Perfect :t

But it fails with the Office12 and Office14 versions of RichEd20.dll because these DLLs save the template as follows:
Code: [Select]
[code]\cell#column2#\cell#column3#
No blank after the RTF tag! It's probably a feature 8), and it will hit you as a bug only in very exotic situations like the one outlined above: words starting with # in cells of a table. Same for words starting with $, btw, and maybe others.

Workaround: Use + instead of # or $.

Here is a list of tested delimiters. OK means even the buggy DLLs insert a space after the rtf tag, bad means they don't.

OK   +/-:@[^?
bad   $\#§*"'&|