Inscription pour les événements de terminal enfichables

Le processus d’inscription des événements a lieu lorsque le terminal est sélectionné par un flux. Dans l’implémentation de la méthode SelectTerminal de l’application Terminal, nous pouvons utiliser l’interface ITTerminal du terminal attaché au flux, puis appeler QueryInterface pour trouver ITPluggableTerminalEventSinkRegistration.

HRESULT hr = E_FAIL;
ITPluggableTerminalEventSinkRegistration* pEventRegistration = NULL;
hr = pTerminal->QueryInterface( 
    IID_ITPluggableTerminalEventSinkRegistration,
    (void**)& pEventRegistration
);

Si l’appel QueryInterface se déroule correctement, nous pouvons appeler la méthode RegisterSink . À cet effet, nous devons créer un objet qui implémente l’interface ITPluggableTerminalEventSink . Nous transmettons cette interface en tant que paramètre de la méthode RegisterSink .

ITPluggableTerminalEventSink*    pEventSink;

HRESULT hr = CreateEventSink( &pEventSink);
// If (hr != S_OK) process the error here. 

hr = pEventRegistration->RegisterSink( pEventSink );
// If (hr != S_OK) process the error here. 

Le terminal qui implémente l’appel ITPluggableTerminalEventSinkRegistration stocke l’interface. Le pointeur sera utilisé lorsque le terminal déclenchera un événement.

Le récepteur d’événements peut être désinscrit à l’aide de UnregisterSink.

hr = pEventRegistration->UnregisterSink();
// If (hr != S_OK) process the error here.