Click here to Skip to main content
Licence CPOL
First Posted 6 Aug 2005
Views 190,956
Downloads 3,602
Bookmarked 67 times

Working with TAPI 3.x from .NET

By Bishoy Ghaly | 6 Aug 2005
It's about time to Use Advanced Telephony features in your code? Right!
12 votes, 31.6%
1
2 votes, 5.3%
2
3 votes, 7.9%
3
4 votes, 10.5%
4
17 votes, 44.7%
5
2.88/5 - 38 votes
μ 2.88, σa 3.13 [?]

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 ' will hold our TAPI object 
        ' will hold our selected address (you can hold many addresses in an array)
        Private oAddress As ITAddress 
        Private RegCookie As Integer 

        Sub New() 
            Try 
                ' creating a new instance to first initialize TAPI 
                ' before attaching the events 
                Dim m_TAPI As New TAPIClass 
                ' a variable to hold supported media types for the address 
                Dim MediaTypes As Integer 
                ' initializing TAPI 
                m_TAPI.Initialize() 
                ' attaching event sink 
                oTAPI = m_TAPI 
                ' getting rid of the private instance as we have another 
                ' global instance (oTAPI) 
                m_TAPI = Nothing 
                Dim AddressCollection As ITCollection = oTAPI.Addresses() 
                ' looping through address collection
                For Each Address As ITAddress In AddressCollection  
                    ' checking if address is working
                    If Address.State = ADDRESS_STATE.AS_INSERVICE Then  
                        ' extracting media support interface from the address 
                        Dim MediaSupport As ITMediaSupport = Address 
                        ' extracting media types supporting 
                        MediaTypes = MediaSupport.MediaTypes 
                        MediaSupport = Nothing ' dispose of the object 
                        If (MediaTypes And MediaModem) = MediaModem Then 
                            ' the address is a data Modem 
                            If (MediaTypes And MediaAudio) = MediaAudio Then 
                                ' Select the address since it supports Audio 
                                ' and is a FAX/Modem 
                                oAddress = Address ' select this address 
                                ' show the selected address name
                                MsgBox("we have selected this address: " + _
                                       oAddress.AddressName)  
                                Exit For 
                            End If 
                        End If 
                    End If 
                Next Address 
                If Not (oAddress Is Nothing) Then 
                    ' registering notifications for the selected address 
                    RegCookie = oTAPI.RegisterCallNotifications_
                                (oAddress, True, False, MediaTypes, 1) 
                    ' Note: this registration can be done on 
                    ' as many addresses as you want 
                    ' we will not receive notifications unless we specify 
                    ' which type of events we are interested in 
                    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 
            ' by now we are done for the initialization and registration 
            ' and the events should fire 
            ' Note: you must dispose of TAPI before you destroy the class 
            ' and I will leave this for now 
        End Sub 
        
        Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, _
                        ByVal pEvent As Object) Handles oTAPI.Event 
            ' making a thread asynchronously process the event 
            Dim thAsyncCall As System.Threading.Thread 
            Select Case TapiEvent 
            
                Case TAPI_EVENT.TE_CALLNOTIFICATION 'Call Notification Arrived 
                    ' assigning our sub's delegate to the thread 
                    thAsyncCall = New Threading.Thread(AddressOf CallNotificationEvent) 
                    ' passing the variable for the thread 
                    CallNotificationObject = CType(pEvent, ITCallNotificationEvent) 
                    ' starting the thread 
                    thAsyncCall.Start() 
                    
                Case TAPI_EVENT.TE_CALLSTATE 'Call State Changes 
                    ' assigning our sub's delegate to the thread 
                    thAsyncCall = New Threading.Thread(AddressOf CallStateEvent) 
                    ' passing the variable for the thread 
                    CallStateObject = CType(pEvent, ITCallStateEvent) 
                    ' starting the thread 
                    thAsyncCall.Start() 
                    
                Case TAPI_EVENT.TE_CALLINFOCHANGE 'Call Info Changes 
                    ' assigning our sub's delegate to the thread 
                    thAsyncCall = New Threading.Thread(AddressOf CallInfoEvent) 
                    ' passing the variable for the thread 
                    CallInfoObject = CType(pEvent, ITCallInfoChangeEvent) 
                    ' starting the thread 
                    thAsyncCall.Start() 
                    
            End Select 
        End Sub 
        
        Private CallNotificationObject As ITCallNotificationEvent 
        Private Sub CallNotificationEvent() 
            ' here we should check to see various notifications of new and ended calls 
            Select Case CallNotificationObject.Event 
            
                Case CALL_NOTIFICATION_EVENT.CNE_MONITOR 
                    ' the notification is for a monitored call 
                Case CALL_NOTIFICATION_EVENT.CNE_OWNER 
                    ' the notification is for an owned call 
            
            End Select 
        End Sub 

        Private CallStateObject As ITCallStateEvent 
        Private Sub CallStateEvent() 
            ' here we should check to see call state and handle connects and disconnects 
            Select Case CallStateObject.State 
            
                Case CALL_STATE.CS_IDLE 
                Case CALL_STATE.CS_INPROGRESS 
                Case CALL_STATE.CS_OFFERING 
                    ' a call is offering so if you don't want it then pass it 
                    ' The code to pass the call is the following 
                    ' Dim CallControl As ITBasicCallControl = CallStateObject.Call 
                    ' CallControl.HandoffIndirect (CallStateObject.Call.CallInfoLong_
                                            (CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE) 
                Case CALL_STATE.CS_CONNECTED 
                    ' call is connected 
                Case CALL_STATE.CS_QUEUED 
                    ' call is being queued 
                Case CALL_STATE.CS_HOLD 
                    ' call is on hold 
                Case CALL_STATE.CS_DISCONNECTED 
                    ' call is disconnected 
            
            End Select 
        End Sub 

        Private CallInfoObject As ITCallInfoChangeEvent 
        Private Sub CallInfoEvent() 
            ' here you can extract information from the call 
            ' the code to extract the caller ID 
            ' >>> put the following code in a try block and 
            ' swallow the exception if it gives errors 
            Dim CallerID As String 
            CallerID = CallInfoObject.Call.CallInfoString_
                    (CALLINFO_STRING.CIS_CALLERIDNAME) 
        End Sub 

    End Class 
End Namespace

History

  • 7th August, 2005: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Bishoy Ghaly

Chief Technology Officer
DashSoft
Egypt Egypt

Member

Follow on Twitter Follow on Twitter
Dreamer, Technology Evangelist, have a passion for software architecture and design patterns an hope everyone does so.
 
I've been working in this field for many years and still expect to learn more and do more in my career and would love to see others do too.
 
I live in Cairo, Egypt and work for a leading International Company developing strategic decisions and executing them with many teams to achieve company goals in Software market, and use my favorite programming language C# and .NET framework sometimes to research and create hobby projects.
 
Wish you enjoyed knowing about me Wink | ;)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberTechnorodent11:41 9 Feb '11  
GeneralMy vote of 1 PinmemberBenJamming16:53 2 Jan '11  
GeneralHelp me profeor PinmemberAshkanJami22:50 20 Oct '10  
Generalcall center system develop help needed PinmemberChesterAV10:28 12 Oct '10  
GeneralTAPI "BlindTransfer" Problem Pinmemberzendehdel0:03 22 Jun '10  
GeneralVisual Basic 2008 / .NET 3.5 / TAPI3 - INCOMMING CALL [EXAMPLE CODE] PinmemberTomGermany20101:14 31 Mar '10  
GeneralRe: Visual Basic 2008 / .NET 3.5 / TAPI3 - INCOMMING CALL [EXAMPLE CODE] Pinmemberwiswalld9:02 9 Dec '10  
GeneralMy vote of 1 PinmemberTomGermany20101:08 18 Mar '10  
GeneralRe: My vote of 1 PinmemberBishoy Ghaly7:12 18 Mar '10  
GeneralVisual Basic 2008 - frustration PinmemberTomGermany20101:01 17 Mar '10  
GeneralRe: Visual Basic 2008 - frustration PinmemberBishoy Ghaly7:09 18 Mar '10  
GeneralRe: Visual Basic 2008 - frustration PinmemberTomGermany20100:31 30 Mar '10  
GeneralVB .NET PinmemberOppVen5:30 3 Jun '11  
GeneralQuestion using windows XP built in dialer.exe to initiate calls PinmemberMegrim036:33 26 Nov '09  
GeneralMy vote of 1 Pinmemberalbert_cook22:54 11 Aug '09  
GeneralNeed help Pinmemberkshirsagar20:27 15 Jun '09  
Hi Bishoy,
 
I am working mobile application, which will block call. I have code to block outgoing call but it is having one ring delay.
 
can we write code to block outgoing call without any notification and one ring delay.
 
Thanks in advance.
 
I am prashant working with Aurasoft Technologies solution Pvt. Ltd.
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Prashant.

Generalplease explain this code, surely it is an error Pinmemberedt12310:35 11 May '09  
AnswerRe: please explain this code, surely it is an error PinmemberThe Code Guru6:53 15 May '09  
General[Message Deleted] Pinmemberit.ragester6:37 28 Mar '09  
Questionhow do i use this Pinmembertheboytony9:50 20 Feb '09  
GeneralNeed a Code to Receive Calls Using External Fax Model Pinmembershirin.102:43 5 Dec '08  
Generaltapi events stop reciving events... Pinmemberaltarribage7:23 29 Oct '08  
GeneralRe: tapi events stop reciving events... PinmemberThe Code Guru20:58 1 Nov '08  
GeneralTTERMINAL namespace Pinmemberjoshi aniruddha20:08 25 Sep '08  
GeneralNo incoming calls are notifed Pinmembervbnetskywalker10:20 22 Sep '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 7 Aug 2005
Article Copyright 2005 by Bishoy Ghaly
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid