简体   繁体   English

RichEdit 控件 EM_POSFROMCHAR 访问冲突

[英]RichEdit Control EM_POSFROMCHAR Access Violation

I don't get it.我不明白。

I sent:我发了:

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

and pos=0x69 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. wParam Rich Edit 1.0 和 3.0:指向接收角色客户区坐标的 POINTL 结构的指针。 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.编辑控件和 Rich Edit 2.0:字符的从零开始的索引。

lParam Rich Edit 1.0 and 3.0: The zero-based index of the character. lParam Rich Edit 1.0 和 3.0:字符的从零开始的索引。

Edit controls and Rich Edit 2.0: This parameter is not used.编辑控件和 Rich Edit 2.0:不使用此参数。

I'm pretty sure I'm using a Rich Edit 2.0 control and got the following:我很确定我正在使用 Rich Edit 2.0 控件并获得以下内容:

Exception thrown at 0x00007FFE6A0121C6 ( riched20.dll ) in my.exe: 0xC0000005: Access violation writing location 0x0000000000000069 .在 my.exe 中的 0x00007FFE6A0121C6 ( riched20.dll ) 抛出异常:0xC0000005:访问冲突写入位置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 .我还确认查看了 CPU 反汇编,它正在尝试写入pos传递的值的地址。

What is going on?到底是怎么回事?

I also thought maybe it wasn't 2.0.. but GetClassName() returns RichEdit20W我还认为它可能不是 2.0.. 但GetClassName()返回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. Rich Edit 3.0 及更高版本:为了向后兼容,Microsoft Rich Edit 3.0 支持 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.如果 Microsoft Rich Edit 3.0 检测到 wParam 不是有效的 POINTL 指针,它会假定消息是使用 Microsoft Rich Edit 2.0 语法发送的。 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.答案是即使会出现 Visual Studio 异常,异常也会由rich20.dll处理并正确返回信息,就像使用 RichEdit V2 控件一样。 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).看来Win2K是在V3开始的时候,所以如果你只需要处理Win2K或更高版本,你可以使用V3格式,如果需要NT4支持,你可以使用V2格式并且可以使用V3(也是rich20.dll的一部分).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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