Registering for Pluggable Terminal Events

The event registration process take place when the terminal is selected by a stream. In the terminal application's implementation of the SelectTerminal method, we can use the ITTerminal interface of the terminal that was attached to the stream, and call QueryInterface to find ITPluggableTerminalEventSinkRegistration.

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

If the QueryInterface call succeeds, we can call the RegisterSink method. For this purpose, we should create an object that implements the ITPluggableTerminalEventSink interface. We pass this interface as a parameter of the RegisterSink method.

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. 

The terminal that implements the ITPluggableTerminalEventSinkRegistration call will store the interface. The pointer will be used when the terminal will fire an event.

The event sink can be unregistered using UnregisterSink.

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