Page 1 of 1

MsgHandler doesn't work

Posted: Thu Dec 15, 2011 7:19 am
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.

Re: MsgHandler doesn't work

Posted: Thu Dec 15, 2011 8:07 am
by madshi
Does SendMessage return true or false? If it returns false, what does GetLastError say?

Re: MsgHandler doesn't work

Posted: Thu Dec 15, 2011 8:52 am
by Tibo
SendMessage return False and the GetLastError says 0...

Re: MsgHandler doesn't work

Posted: Thu Dec 15, 2011 9:45 am
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.

Re: MsgHandler doesn't work

Posted: Thu Dec 15, 2011 9:48 am
by Tibo
Thanks for the answer!