MsgHandler doesn't work

delphi package - madRes, madTools, madStrings, ...
Post Reply
Tibo
Posts: 3
Joined: Wed Dec 14, 2011 10:43 am

MsgHandler doesn't work

Post by Tibo »

Hello,

I work on Delphi 6 and try to make communication between 2 process with windows message. One of the process (Process1) is not a window so I use the MsgHandler to create an invisible windows. I create 2 handlers using AddMsgHandler and wait for messages from the other process (Process2).

Process2 send 2 different kinds of message, one is is a PostMessage with lparam containing an integer value (it works) but the second is a SendMessage with lparam containing TCopyDataStruct and here is the issue, Porcess1 never receive the messages.

Code: Select all

procedure SendMessage(AReceiveStringList : TStringList);
var
  LReceivedMsg : string;
  LCopyDataStruct : TCopyDataStruct;
begin
   if AReceiveStringList .Count > 0 then
  begin
    LReceivedMsg := ReceiveStringList.Strings[0];
    
    LCopyDataStruct .dwData := hdr_ComAxe;
    LCopyDataStruct .cbData := Length(LReceivedMsg ) + 1;
    LCopyDataStruct .lpData := PChar(LReceivedMsg );
    
    if (Pos('EB',ReceivedMsg) > 0) then
    begin
        Windows.SendMessage(Self.FCommunicationHandle, WM_COPYDATA, 0, Integer(@LCopyDataStruct ));
    end;
end;
Here is the method which send the unreceived message.

Code: Select all

constructor TSequencesLoader.Create(ALogger : TLogger);
begin
  inherited Create();
  // Allocation des MsgHandler pour la réception des réponses d'A_Com_Ax
  madTools.AddMsgHandler(ManageCopyDataMessage, WM_COPYDATA);
  madTools.AddMsgHandler(ManageAckNackMessage, WM_ACKNACK);
end;
Here is the creation of messages handler, note that WM_ACKNACK is a home message but it's the message I can receive...

Is someone have an idea of what's happen?

Thanks.
madshi
Site Admin
Posts: 10749
Joined: Sun Mar 21, 2004 5:25 pm

Re: MsgHandler doesn't work

Post by madshi »

Does SendMessage return true or false? If it returns false, what does GetLastError say?
Tibo
Posts: 3
Joined: Wed Dec 14, 2011 10:43 am

Re: MsgHandler doesn't work

Post by Tibo »

SendMessage return False and the GetLastError says 0...
madshi
Site Admin
Posts: 10749
Joined: Sun Mar 21, 2004 5:25 pm

Re: MsgHandler doesn't work

Post by madshi »

Argh, my fault, sorry. In madTools.pas in the function "MsgHandlerWindowProc" there's a big "if" instruction like this:

Code: Select all

if (msg in [WM_QUERYENDSESSION, WM_QUIT, ...])
Just add WM_COPYDATA to the list and it should start working. I will do that for the next madCollection build, but you can fix it on your own, so you don't have to wait.
Tibo
Posts: 3
Joined: Wed Dec 14, 2011 10:43 am

Re: MsgHandler doesn't work

Post by Tibo »

Thanks for the answer!
Post Reply