The Following code used to work, but now EnumWindows never finishes / returns.
function AllWindows(hW: THandle; List: Integer): Boolean; stdcall;
var
l: LongInt;
found: Boolean = false;
wCaption: String[255];
begin
Result := True;
l := SendMessage(hW, WM_GETTEXT, 254, LongInt(@wCaption[1]));
if l > 0 then begin
wCaption[0] := char(l);
FormEnum.cb1.Items.add(wCaption);
end;
showMessage(IntToHex(hW, 8) + ' ' + IntToStr(l));
end;
procedure TFormEnum.FormCreate(Sender: TObject);
begin
ShowMessage('Enum Windows');
enumWindows(@AllWindows, 0);
showmessage('Pause');
end;
EnumW calls the AllWindows Function many times, but after it is done, the system is left in a loop and ShowMessage('Pause') is never executed.
This is a Function I have in a working program and the above was created to isolate/demonstrate the problem I'm having.
One thing different, is that the working program is compiled with
{$mode Objfpc}{$H+} but to compile the above I had to change to: {$mode Delphi}{$H+} which I dont understand why.
I assume I have done something silly, but I cant see it. Any help would be appreciated.