Udostępnij przez


Rejestrowanie na wydarzenia dotyczące podłączalnych terminali

Proces rejestracji zdarzeń odbywa się, gdy terminal zostanie wybrany przez strumień. W sposobie implementacji aplikacji terminalowej metody SelectTerminal można użyć interfejsu ITTerminal terminalu przypisanego do strumienia i wywołać QueryInterface, aby znaleźć ITPluggableTerminalEventSinkRegistration.

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

Jeśli wywołanie QueryInterface powiedzie się, możemy wywołać metodę RegisterSink. W tym celu należy utworzyć obiekt, który implementuje interfejs ITPluggableTerminalEventSink. Przekazujemy ten interfejs jako parametr metody 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. 

Terminal implementujący wywołanie ITPluggableTerminalEventSinkRegistration przechowa interfejs. Wskaźnik będzie używany, gdy terminal uruchomi zdarzenie.

Ujście zdarzeń można wyrejestrować przy użyciu UnregisterSink.

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