Problem with DLLs and Application.OnMessage - Event
From: Ladidadi (ladidadi_at_onlinehome.de)
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
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 tool works in the following way:
TForm1 = class(TForm)
procedure AppOnMessage(Var Msg: TMSg; Var Handled: Boolean);
Procedure ProgStart(); stdcall; //Procedure called by the main
Application.CreateHandle; // else the handle of the dll would be
Application.OnMessage := Form1.AppOnMessage;
Procedure TForm1.AppOnMessage(var Msg: TMsg; var Handled: Boolean);
Case msg.message Of
WM_USER + 123:
WM_USER + 456:
I also tried to create event handlers like...
TForm1 = class(TForm)
procedure WMUSER1(var Msg: TMessage); message WM_USER + 123;
procedure WMUSER2(var Msg: TMessage); message WM_USER + 456;
procedure TForm1.WMUSER1(var Msg: TMessage);
procedure TForm1.WMUSER2(var Msg: TMessage);
...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?