-2

I don't get it.

I sent:

SendMessage(hrichedit, EM_POSFROMCHAR, (WPARAM)pos, 0);

and pos=0x69

The documentation says:

wParam Rich Edit 1.0 and 3.0: A pointer to a POINTL structure that receives the client area coordinates of the character. The coordinates are in screen units and are relative to the upper-left corner of the control's client area.

Edit controls and Rich Edit 2.0: The zero-based index of the character.

lParam Rich Edit 1.0 and 3.0: The zero-based index of the character.

Edit controls and Rich Edit 2.0: This parameter is not used.

I'm pretty sure I'm using a Rich Edit 2.0 control and got the following:

Exception thrown at 0x00007FFE6A0121C6 (riched20.dll) in my.exe: 0xC0000005: Access violation writing location 0x0000000000000069.

I also confirmed looking at the CPU disassembly and it's trying to write to the address that is the value passed by pos.

What is going on?

I also thought maybe it wasn't 2.0 .. but GetClassName() returns RichEdit20W

The documentation also says:

Rich Edit 3.0 and later: For backward compatibility, Microsoft Rich Edit 3.0 supports the syntax used by Microsoft Rich Edit 2.0. If Microsoft Rich Edit 3.0 detects that wParam is not a valid POINTL pointer, it assumes the message was sent using the Microsoft Rich Edit 2.0 syntax. In this case, it uses the return value to return the coordinates.

But clearly that's not the case.

user3161924
  • 1,849
  • 18
  • 33
  • 1
    One of Microsoft's stranger design decisions is how the same message has incompatible parameters from one version of the control to the next. And RichEdit 2.0 and 3.0 have the same class name. See [Versions of Rich Edit](https://learn.microsoft.com/en-us/windows/win32/controls/about-rich-edit-controls). – Jonathan Potter Jun 03 '22 at 03:39
  • 4
    What is `0x69`? The `wParam` parameter should be the address of a `POINTL` structure, which you have declared, like: `POINTL point`, then wParam will be `(WPARAM)&point`. – Adrian Mole Jun 03 '22 at 04:58
  • As a *usable* address value on a Windows system, `0x69` seems highly improbable. – Adrian Mole Jun 03 '22 at 05:01
  • 1
    The fact that the RichEdit to trying to write to a memory address specified in the wParam should tell you that it is not treating the wParam as an index, thus clearly the RichEdit 2.0 notes don't apply. So you must be using RichEdit 3.0 instead. – Remy Lebeau Jun 03 '22 at 06:25
  • So the question is how to deal with it? It says if it was V3 that it would detect if the V2 parameters were used instead. The class name returns RichEdit20W. Jonathan says the 2 and 3 have the same class name. I need this to work with all windows versions (NT4 up). How do determine which method of parameters to provide so it doesn't crash? – user3161924 Jun 03 '22 at 23:24
  • @RemyLebeau I added the documentation where it says Rich Edit 3.0 and later are backwards compatible with using the 2.0 parameters. But since it crashed, it's clearly not. – user3161924 Jun 03 '22 at 23:31
  • @user3161924 you would think that with this much trouble, they would have just designed a separate `EM_EXPOSFROMCHAR` message instead. Much like they did for `EM_(GET|SET)SEL` -> `EM_EX(GET|SET)SEL`. Oh well. – Remy Lebeau Jun 04 '22 at 00:30

1 Answers1

0

The answer is that even though Visual Studio exception will occur, the exception is handled by the rich20.dll and returns the information correctly as if a RichEdit V2 control was used. It appears Win2K is when V3 started, so if you only have to deal with Win2K or later, you can use the V3 format, if needing NT4 support, you can use the V2 format and will work with V3 (also part of rich20.dll).

user3161924
  • 1,849
  • 18
  • 33