Platform SDK: TAPI |
The following code snippets demonstrate implementation of a simple event handler, registration of the main TAPI event interface, setting of the event filter, and registration for call notifications.
Before using this code snippet, you must perform the operations in Initialize TAPI and Select an Address.
Note This snippet does not have the error checking and releases appropriate for real code.
// // Snippet 1: Implement a simple event handler. // HRESULT STDMETHODCALLTYPE CTAPIEventNotification::Event( TAPI_EVENT TapiEvent, IDispatch * pEvent ) { // AddRef the event so it doesn't go away. pEvent->AddRef(); // Post a message to our own UI thread. PostMessage( ghDlg, WM_PRIVATETAPIEVENT, (WPARAM) TapiEvent, (LPARAM) pEvent ); return S_OK; } // // Snippet 2: Register the event interface. // ULONG gulAdvise; // Globally declared IConnectionPointContainer * pCPC; IConnectionPoint * pCP; ITTAPIEventNotification * gpTAPIEventNotification; gpTapi->QueryInterface( IID_IConnectionPointContainer, (void **)&pCPC ); pCPC->FindConnectionPoint( IID_ITTAPIEventNotification, &pCP ); pCPC->Release(); // Retain gulAdvise for future use pCP->Advise( gpTAPIEventNotification, &gulAdvise ); pCP->Release(); // // Snippet 3: Set the event filter. // // Assume we are interested // only in call-related events. gpTapi->put_EventFilter( TE_CALLNOTIFICATION | TE_CALLSTATE | TE_CALLMEDIA ); // // Snippet 4: Register an address with TAPI // for call notifications. Assume we are interested // in video and audio calls, and that pAddress // is a pointer to the ITAddress interface of // an address that can handle both media types. long glRegister; // Globally declared gpTapi->RegisterCallNotifications( pAddress, VARIANT_TRUE, // monitor privileges VARIANT_TRUE, // owner privileges TAPIMEDIATYPE_AUDIO|TAPIMEDIATYPE_VIDEO, gulAdvise, // As returned by Advise &glRegister );
'Usually declared globally Dim WithEvents gobjTapiWithEvents As TAPI Attribute gobjTapiWithEvents.VB_VarHelpID = -1 Dim glRegistrationToken As Long 'Usually performed at the same time 'as TAPI initialization Const TAPI3_CALL_EVENTS = _ TE_CALLMEDIA Or _ TE_CALLNOTIFICATION Or _ TE_CALLSTATE 'Set the EventFilter to accept all defined TAPI events. gobjTapi.EventFilter = TAPI3_CALL_EVENTS 'Register the outgoing interface (the one that will actually 'receive and process the events). Set gobjTapiWithEvents = gobjTapi Dim fOwner As Boolean, fMonitor As Boolean Dim lMediaTypes As Long, lCallbackInstance As Long 'fOwner = True ensures that the application receives incoming calls 'and their call state events. fOwner = True fMonitor = False lMediaTypes = TAPIMEDIATYPE_AUDIO lCallbackInstance = 1 glRegistrationToken = gobjTapi.RegisterCallNotifications( _ gobjAddress, _ fMonitor, _ fOwner, _ lMediaTypes, _ lCallbackInstance )
ITTAPIEventNotification::Event, TAPI_EVENT, ITTAPI::put_EventFilter, TAPIMEDIATYPE_ Constants, ITTAPI::RegisterCallNotifications