MsgHandler doesn't work

delphi package - madRes, madTools, madStrings, ...

MsgHandler doesn't work

Postby Tibo » Thu Dec 15, 2011 7:19 am

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.
Tibo
 
Posts: 3
Joined: Wed Dec 14, 2011 10:43 am

Re: MsgHandler doesn't work

Postby madshi » Thu Dec 15, 2011 8:07 am

Does SendMessage return true or false? If it returns false, what does GetLastError say?
madshi
Site Admin
 
Posts: 9273
Joined: Sun Mar 21, 2004 5:25 pm

Re: MsgHandler doesn't work

Postby Tibo » Thu Dec 15, 2011 8:52 am

SendMessage return False and the GetLastError says 0...
Tibo
 
Posts: 3
Joined: Wed Dec 14, 2011 10:43 am

Re: MsgHandler doesn't work

Postby madshi » Thu Dec 15, 2011 9:45 am

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.
madshi
Site Admin
 
Posts: 9273
Joined: Sun Mar 21, 2004 5:25 pm

Re: MsgHandler doesn't work

Postby Tibo » Thu Dec 15, 2011 9:48 am

Thanks for the answer!
Tibo
 
Posts: 3
Joined: Wed Dec 14, 2011 10:43 am


Return to madBasic

Who is online

Users browsing this forum: No registered users and 2 guests