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
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.
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.
链接地址: http://www.djcxy.com/p/81300.html上一篇: 接收COM事件
下一篇: COM事件通知