Aaron
Aaron

Reputation: 2863

COM event notification

Without:

Note:

Question:

Illustration below:

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

//result handling omitted


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

//result handling omitted

Upvotes: 1

Views: 462

Answers (2)

Aidan Ryan
Aidan Ryan

Reputation: 11589

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.

Upvotes: 0

peterchen
peterchen

Reputation: 41096

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.

Upvotes: 1

Related Questions