Introduction
Here I will post a class containing the event handling part in TAPI 3.0 and VB.NET.
I will also include the full project as a download.
The code is self explaining and well commented and if you need any further information, please drop me a PM.
All comments are welcome and please vote for the article.
Here is the full commented source code in VB.NET and I will be posting more in-depth tutorials about TAPI.
Imports TAPI3Lib
Namespace VBCity.TAPI
Public Class VBTAPI
Private Const MediaAudio As Integer = 8
Private Const MediaModem As Integer = 16
Private Const MediaFax As Integer = 32
Private Const MediaVideo As Integer = 32768
Private WithEvents oTAPI As TAPI3Lib.TAPI
Private oAddress As ITAddress
Private RegCookie As Integer
Sub New()
Try
Dim m_TAPI As New TAPIClass
Dim MediaTypes As Integer
m_TAPI.Initialize()
oTAPI = m_TAPI
m_TAPI = Nothing
Dim AddressCollection As ITCollection = oTAPI.Addresses()
For Each Address As ITAddress In AddressCollection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then
Dim MediaSupport As ITMediaSupport = Address
MediaTypes = MediaSupport.MediaTypes
MediaSupport = Nothing
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
oAddress = Address
MsgBox("we have selected this address: " + _
oAddress.AddressName)
Exit For
End If
End If
End If
Next Address
If Not (oAddress Is Nothing) Then
RegCookie = oTAPI.RegisterCallNotifications_
(oAddress, True, False, MediaTypes, 1)
oTAPI.EventFilter = (TAPI_EVENT.TE_CALLNOTIFICATION Or _
TAPI_EVENT.TE_CALLSTATE Or TAPI_EVENT.TE_CALLINFOCHANGE)
Else
MsgBox("no address selected")
End If
Catch ex As Exception
MsgBox("Error occurred:" & vbCrLf & ex.Message, _
MsgBoxStyle.Critical, "VBCITY.VBTAPI")
End Try
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, _
ByVal pEvent As Object) Handles oTAPI.Event
Dim thAsyncCall As System.Threading.Thread
Select Case TapiEvent
Case TAPI_EVENT.TE_CALLNOTIFICATION
thAsyncCall = New Threading.Thread(AddressOf CallNotificationEvent)
CallNotificationObject = CType(pEvent, ITCallNotificationEvent)
thAsyncCall.Start()
Case TAPI_EVENT.TE_CALLSTATE
thAsyncCall = New Threading.Thread(AddressOf CallStateEvent)
CallStateObject = CType(pEvent, ITCallStateEvent)
thAsyncCall.Start()
Case TAPI_EVENT.TE_CALLINFOCHANGE
thAsyncCall = New Threading.Thread(AddressOf CallInfoEvent)
CallInfoObject = CType(pEvent, ITCallInfoChangeEvent)
thAsyncCall.Start()
End Select
End Sub
Private CallNotificationObject As ITCallNotificationEvent
Private Sub CallNotificationEvent()
Select Case CallNotificationObject.Event
Case CALL_NOTIFICATION_EVENT.CNE_MONITOR
Case CALL_NOTIFICATION_EVENT.CNE_OWNER
End Select
End Sub
Private CallStateObject As ITCallStateEvent
Private Sub CallStateEvent()
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE
Case CALL_STATE.CS_INPROGRESS
Case CALL_STATE.CS_OFFERING
(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED
Case CALL_STATE.CS_QUEUED
Case CALL_STATE.CS_HOLD
Case CALL_STATE.CS_DISCONNECTED
End Select
End Sub
Private CallInfoObject As ITCallInfoChangeEvent
Private Sub CallInfoEvent()
Dim CallerID As String
CallerID = CallInfoObject.Call.CallInfoString_
(CALLINFO_STRING.CIS_CALLERIDNAME)
End Sub
End Class
End Namespace
History
- 7th August, 2005: Initial post