Home > Blockchain >  Calling SendMessage returns 32 bit result in a 64 bit environment
Calling SendMessage returns 32 bit result in a 64 bit environment

Time:03-29

I am converting a Delphi Windows program to 64 bit. When I use SendMessage to send a EM_LINEINDEX message to a component it should return -1 if the WPARAM parameter is greater than the number of lines of text in the component. But it returns $FFFFFFFF (-1 in 32 bit format). So a comparison with -1 fails.

It is easy to demonstrate, just build a VCL app with a form containing a TMemo and a TButton Add the following buttonclick code:

procedure TForm1.Button1Click(Sender: TObject);
var  x: int64;
begin
   x:=SendMessage(Memo1.Handle, EM_LINEINDEX, WPARAM(5), 0);
   ShowMessage(Format('%d  %X',[x,x]));
end;

The string displayed is: 4294967295 FFFFFFFF

Stepping through the assembly code I see it returns 00000000FFFFFFF in rax.

If change the variable x to be an integer, it works, but if range checking is turned on (using {$R }) it throws a range error exception which is how I found it in the first place.

Should I expect 32 bit results from all Windows messages in a 64 bit environment?

CodePudding user response:

The Edit/RichEdit controls probably use a 32-bit length value internally.

You probably just have to accept this quirk and treat the return value as a 32-bit integer. This should not be a problem unless you expect to store more than 4gb of text in these controls.

  • Related