Problem with DLLs and Application.OnMessage - Event

From: Ladidadi (ladidadi_at_onlinehome.de)
Date: 08/11/04


Date: 11 Aug 2004 07:41:17 -0700

I have a problem using the Application.OnMessage Event in a .dll:

I'm working in Delphi 7 on a CLX-Tool. The "Application" variables in
Clx-Tools do not have an "OnMessage"-Event (because it wouldn't be
compatible with linux). So I had to create a .dll file to interact via
messages to a second exe-file (The tool will be compiled for linux and
windows and some functions will only work in windows; that's okay, I
accepted it).

The communication with messages works fine in one way: from the dll to
the exe. But it doesn't work at all vice versa: The messages sent from
the exe to the dll seem not to be received by the OnMessage event of
the dll.

The tool works in the following way:

type
  TForm1 = class(TForm)
    procedure AppOnMessage(Var Msg: TMSg; Var Handled: Boolean);
  ...
end;
var
  Procedure ProgStart(); stdcall; //Procedure called by the main
program
  ...

implementation

procedure ProgStart();
begin
  Application.CreateHandle; // else the handle of the dll would be
0...
  Application.OnMessage := Form1.AppOnMessage;
  ...
end;

Procedure TForm1.AppOnMessage(var Msg: TMsg; var Handled: Boolean);
Begin
  Case msg.message Of
    WM_USER + 123:
      Begin
         ...
      End;

    WM_USER + 456:
      Begin
         ...
      End;

    ...

end;

I also tried to create event handlers like...

type
  TForm1 = class(TForm)
  ...
 public
  procedure WMUSER1(var Msg: TMessage); message WM_USER + 123;
  procedure WMUSER2(var Msg: TMessage); message WM_USER + 456;
end;

procedure TForm1.WMUSER1(var Msg: TMessage);
Begin
  ...
end;

procedure TForm1.WMUSER2(var Msg: TMessage);
Begin
  ...
end;

...but that didn't work, too.

The exe-file the dll communicates with cannot be the problem. It sends
its messages with the postmessage() procedure and worked well in the
old version, (where it communicated directly with the main program).
The code was the same in the older version, but it was directly in the
main program's source, not the one of the dll (as i explained this is
the only possible way now)...

I checked the dll with the debugger and realised, that the
AppOnMessage Method is not even visited. Same thing with the event
handlers: no activity in it although I'm 110% sure that there are in
fact messages sent from the exe-file to the dll, they just don't seem
to reach it...

Can anybody please help me and tell me if there is a possibility for a
dll file to receive windows messages?

Thanx!