Hello,
I have a thread function on Process B that contains a switch to perform certain operations based on the results of an event sent from Process A, these are stored as two elements in an array.
I set the first element to the event which signals when Process A has data to send and I have the second element set to the event which indicates when Process A has closed.
I have began to implement the functionality for the switch statement but I'm not getting the results as I expect.
Consider the following:
//
//Thread function
DWORD WINAPI ThreadFunc(LPVOID passedHandle)
{
for(i = 0; i < 2; i++)
{
ghEvents[i] = OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("Global\\ProducerEvents"));
if(ghEvents[i] == NULL)
{
getlasterror = GetLastError();
}
}
dwProducerEventResult = WaitForMultipleObjects(
2,
ghEvents,
FALSE,
INFINITE);
switch (dwProducerEventResult)
{
case WAIT_OBJECT_0 + 0:
{
//Producer sent data
//unpackedHandle = *((HWND*)passedHandle);
MessageBox(NULL,L"Test",L"Test",MB_OK);
break;
}
case WAIT_OBJECT_0 + 1:
{
//Producer closed
ExitProcess(1);
break;
}
default:
return;
}
}
As you can see if the event in the first array is signalled Process B should display a simple message box, if the second array is signalled the application should close.
When I actually close Process A, Process B displays the message box instead.
If I leave the first case blank (Do nothing) both applications close as they should.
Furthermore Process B sends data an error is thrown (When I comment out the unpacking):
Have I implemented my switch statement incorrectly? I though I handled the unpacking of the HWND correctly too, any suggestions?
Thanks for your time.