Introduction
This is a complete example how to use ITAPI library in VB.NET, showing the code for incoming call through an audio modem to answer and show the caller ID.
Background
Take a look at the website and download the package from http://itapi3.codeplex.com/downloads/get/104950.
Inside you will find a chm file with a guide.
Using the code
Before you use this class you have to add a project reference. In this case I've used Visual Studio 2008.
Project -> Add Reference -> Browse and choose ITapi3.dll. Choose the correct one (x32 or x64) and then instantiate the class.
The code will work listening to the hardware events. If you have x64 platform use the attached x64 file.
x32 file on x64 systems will not work. Once you have instantiated the class the code will run alone and will listen to the events.
Before you run it, ensure your TAPI service on your machine is running. The code has been tested on Windows7 and works fine.
Imports JulMar.Tapi3
Public Class VBITAPI
Private hwAddress As TAddress = Nothing
Private mediaTypes As Integer
Private WithEvents tapiCls As TTapi
Private Const mediaAudio = JulMar.Tapi3.TAPIMEDIATYPES.AUDIO
Private Const mediaData = JulMar.Tapi3.TAPIMEDIATYPES.DATAMODEM
Private Const mediaVideo = JulMar.Tapi3.TAPIMEDIATYPES.VIDEO
Private Const mediaFax = JulMar.Tapi3.TAPIMEDIATYPES.G3FAX
Private Const mediaMultitrack = JulMar.Tapi3.TAPIMEDIATYPES.MULTITRACK
Private offeringCall As Boolean = False
Private connectedCall As Boolean = False
Private inProgressCall As Boolean = False
Private incomingCall As TCall
Public Sub New()
tapiCls = New TTapi
tapiCls.Initialize()
For Each address In tapiCls.Addresses
If address.State = ADDRESS_STATE.AS_INSERVICE Then
mediaTypes = address.MediaTypes
If (mediaTypes And mediaAudio) = mediaAudio Then
hwAddress = address
hwAddress.Open(mediaAudio)
End If
End If
Next
If hwAddress Is Nothing Then
End If
End Sub
Public Sub openLine()
Try
If hwAddress.State = ADDRESS_STATE.AS_INSERVICE Then
hwAddress.Open(mediaAudio)
End If
Catch ex As Exception
End Try
End Sub
Public Sub closeLine()
Try
If hwAddress.State = ADDRESS_STATE.AS_INSERVICE Then
hwAddress.Close()
End If
Catch ex As Exception
End Try
End Sub
Public Sub answerCall()
If offeringCall = True Then
incomingCall.Answer()
End If
End Sub
Public Sub hungup()
If connectedCall = True Then
incomingCall.Disconnect(DISCONNECT_CODE.DC_REJECTED)
End If
End Sub
Private Sub tapiCallNotification_Event(ByVal sender As Object, _
ByVal e As TapiCallNotificationEventArgs) Handles tapiCls.TE_CALLNOTIFICATION
Select Case e.Event
Case CALL_NOTIFICATION_EVENT.CNE_MONITOR
Case CALL_NOTIFICATION_EVENT.CNE_OWNER
End Select
End Sub
Private Sub tapiInfoChange_Event(ByVal sender As Object, _
ByVal e As TapiCallInfoChangeEventArgs) Handles tapiCls.TE_CALLINFOCHANGE
Dim callerNumber As String = ""
Try
callerNumber = e.Call.CallInfo(CALLINFO_STRING.CIS_CALLERIDNUMBER).ToString
If callerNumber.Length = 0 Then
Else
End If
Catch ex As Exception
End Try
End Sub
Private Sub tapiGeneral_Event(ByVal sender As Object, _
ByVal e As TapiCallStateEventArgs) Handles tapiCls.TE_CALLSTATE
Select Case e.State
Case CALL_STATE.CS_UNKNOWN
Case CALL_STATE.CS_OFFERING
offeringCall = True
Case CALL_STATE.CS_CONNECTED
connectedCall = True
offeringCall = False
Case CALL_STATE.CS_HOLD
Case CALL_STATE.CS_IDLE
Case CALL_STATE.CS_INPROGRESS
Case CALL_STATE.CS_QUEUED
Case CALL_STATE.CS_DISCONNECTED
connectedCall = False
End Select
End Sub
Private Sub tapiGenerate_Event(ByVal sender As Object, _
ByVal e As TapiDigitGenerationEventArgs) Handles tapiCls.TE_GENERATEEVENT
End Sub
Private Sub tapiSpecific_Event(ByVal sender As Object, _
ByVal e As TapiAddressDeviceSpecificEventArgs) Handles tapiCls.TE_ADDRESSDEVSPECIFIC
End Sub
Private Sub tapiObject_Event(ByVal sender As Object, _
ByVal e As TapiObjectEventArgs) Handles tapiCls.TE_TAPIOBJECT
End Sub
Private Sub tapiPhone_Event(ByVal sender As Object, _
ByVal e As TapiPhoneEventArgs) Handles tapiCls.TE_PHONEEVENT
End Sub
Private Sub tapiDigit_Event(ByVal sender As Object, _
ByVal e As TapiDigitDetectionEventArgs) Handles tapiCls.TE_DIGITEVENT
End Sub
End Class