-2

I'm new to Delphi and I try to write an experimental plugin for a program in Lazarus. I found a free source code from a different plugin and I try to base on it. My plugin should received the message sent by the program and insert a string into an edit line. So far I have managed to implement a handler to the program. However, I stuck with CopyDataStruct, which works with a message sent by the main program.

UPDATE I think the feedback from Marco van de Voort might explain the source of the problem. I did some research after finding a tutorial and it seems that those messages are simply lost.

So that I rewrite my code including:

 function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LRESULT; stdcall;

 begin
   case uMsg of WM_COPYDATA:
     begin
       Result := TForm1.WMCopyData();
       exit;
       end;
      else
      Result := CallWindowProc(PrevWndProc, Ahwnd, uMsg, WParam, LParam);
     end;

 end; 

as well as

PrevWndProc:=Windows.WNDPROC(SetWindowLongPtr(Self.Handle,GWL_WNDPROC,PtrInt(@WndCallback)));  

in FormCreate section.

Now, I got an error with Result := TForm1.WMCopyData(); I'm not sure what parameters should be passed into this function. It is declared as: TForm1.WMCopyData(var Msg: TCopyDataStruct); but neither 'Msg' nor 'TCopyDataStruct' works. Could you help me with it?

Krzychu
  • 121
  • 7
  • Have a look how TWMCopyData is defined in Lazarus. You can Ctrl+click on it and Lazarus should open the corresponding source file. – Ondrej Kelle Jul 27 '15 at 09:41
  • Very useful hint. I will check it. Thanks – Krzychu Jul 27 '15 at 09:47
  • 1
    You declare the parameter as `var TWMCopyData:Msg` what means parameter with name `TWMCopyData` and type `Msg`. I guess that You have to swap them: `var Msg: TWMCopyData`. – Abelisto Jul 27 '15 at 10:38
  • Please show the real code – David Heffernan Jul 27 '15 at 10:51
  • Please don't provide links to offsite code. Please rewrite the question completely to present a minimal example. – David Heffernan Jul 27 '15 at 11:52
  • Searching through FPC source can give the solution: 1) use TMessage instead of TWMCopyData; 2) to access to specific data use `PCopyDataStruct(Msg.Lparam)^.dwData` for example. If you have FPC sources then you can find usage example in the `packages\fcl-process\src\win\simpleipc.inc` file, `procedure TWinMsgServerComm.ReadMsgData` method. Good luck. – Abelisto Jul 27 '15 at 15:59
  • Thanks Abelisto, I'll check it later this week. – Krzychu Jul 28 '15 at 06:31

1 Answers1

1

Note that only a portable subset of (GDI) messages is copied into the Lazarus LCL message queue.

See http://wiki.freepascal.org/Win32/64_Interface#Processing_non-user_messages_in_your_window

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89