1
votes

Without:

  • ATL
  • MFC

Note:

  • Client is executing in a different thread to that of the server

Question:

  • How do I control the behaviour of the client, once an event notification is received from the COM object (Server)?
  • How to implement an event interface from client?

Illustration below:

hresult = pis8->QueryInterface(
                __uuidof(IConnectionPointContainer),
            (void **) &pContainer);

//result handling omitted


hresult = pContainer->FindConnectionPoint(
                      __uuidof(IS8SimulationEvents),
                      &pConnection);

//result handling omitted
2

2 Answers

1
votes

The client implements the event interface (IS8SimulationEvents) This can be in a separate component, or on the client component itself. The implementation is called when the component fires an event.

After FindConnectionPoint, the client calls pConnection->Advise, passing the IS8SimulationEvents and receiving a "cookie". The cookie is required to call Unadvise, which must be called during cleanup to disconnect.

If the client runs in a different thread than server, the client needs to run a message loop to receive calls.

0
votes

If I'm understanding the question right, seems like the client needs to be running a waitloop, something like

while(!threadCancel)
{
    DWORD waitResult = WaitForMultipleObjects(actionCount, waitHandles, FALSE, 500);
    switch (waitResult)
    {
        case SERVER_COMMAND_1:
            HandleServerCommand1();
            break;
        ...etc...
        default:
           throw ...
     }
}

The client's event sinks trigger the wait handles, effectively allowing the server to tell the client what to do.