I have a Delphi XE4 service application under development. The service starts threads for some long-running tasks, and the threads communicate status back with a PostThreadMessage call.
The main ServiceExecute loop looks like this:
procedure TScanService.ServiceExecute(Sender: TService);
var
CurrentMessage: TMsg;
begin
LogServerEvent('ServiceExecute', 'Starting');
while not Terminated do
begin
if not PeekMessage(CurrentMessage, 0, WM_NULL, msgHigh, PM_NOREMOVE) then
begin
Sleep(1000);
Continue;
end;
GetMessage(CurrentMessage, 0, WM_NULL, msgHigh);
LogServerEvent('ServiceExecute', 'CurrentMessage.message', IntToStr(CurrentMessage.message));
LogServerEvent('ServiceExecute', 'CurrentMessage.wParam', IntToStr(CurrentMessage.wParam));
LogServerEvent('ServiceExecute', 'CurrentMessage.lParam', IntToStr(CurrentMessage.lParam));
In the thread, the message sending looks like this:
gThreadNumber: Integer;
LogThreadEvent('Execute', 'Found Notice, Thread number: ' + IntToStr(gThreadNumber));
PostThreadMessage(ParentThreadID, msgFound, gThreadNumber, 6);
The message arrives fine, and the message number is correct (msgFound = WM_USER + 1); however, I sent 0, 6 for wParam, lParam, and what I received is 4, 0. What am I missing?
Note: The code only has 2 threads running, and one is a timer that uses a different message number, and isn't sending anything when this happens.