简体   繁体   中英

RichEdit Control EM_POSFROMCHAR Access Violation

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM