none
How to use TAPI3.0 to make a call ?

    Question

  • Operating environment:
     windows xp sp2
     CCME-TSP 

    I want use VB.net to write a simple make call program. I follow the SDK example, write it like below. but I get the error:"
    COMException was unhandled
    Can't enumerate any more, because the associated data is missing (Exception from HRESULT: 0x80040002 (OLE_E_ENUM_NOMORE)) "  when I step to " objTerminal = objTerminalSupport.GetDefaultStaticTerminal(TAPIMEDIATYPE_AUDIO, TERMINAL_DIRECTION.TD_CAPTURE)" . I am a newbie. Could anyone give me some help or an example, thanks~

    Code Snippet

    Imports TAPI3Lib

    Module Module1

        Public Const TAPIMEDIATYPE_AUDIO As Integer = &H8
        Public Const LINEADDRESSTYPE_PHONENUMBER As Integer = &H1

        Sub Main()
            'initialize
            Dim gobjTapi As TAPI = New TAPI
            gobjTapi.Initialize()

            'select address
            Dim gobjAddress As ITAddress
            Dim objCollAddress As ITCollection
            objCollAddress = gobjTapi.Addresses

            Dim bFound As Boolean
            bFound = False
            Dim objCtrAddress As ITAddress
            Dim objMediaSupport As ITMediaSupport

            Dim index As Integer
            For indexAddr As Integer = 1 To objCollAddress.Count
                objCtrAddress = objCollAddress.Item(indexAddr)
                objMediaSupport = objCtrAddress

                If objMediaSupport.QueryMediaType(TAPIMEDIATYPE_AUDIO) Then
                    bFound = True
                End If

                If bFound = True Then
                    index = indexAddr
                    Exit For
                End If

                objMediaSupport = Nothing
                objCtrAddress = Nothing
            Next

            gobjAddress = objCollAddress.Item(index)

            'make a call
            Dim gobjCall As ITBasicCallControl
            gobjCall = gobjAddress.CreateCall("172015727", LINEADDRESSTYPE_PHONENUMBER, TAPIMEDIATYPE_AUDIO)

            'select the terminal
            Dim objCallControl As ITBasicCallControl
            objCallControl = gobjCall

            Dim objTerminalSupport As ITTerminalSupport
            objTerminalSupport = gobjAddress

            Dim objTerminal As ITTerminal
            objTerminal = objTerminalSupport.GetDefaultStaticTerminal(TAPIMEDIATYPE_AUDIO, TERMINAL_DIRECTION.TD_CAPTURE)

            objTerminalSupport = Nothing

            Dim objStreamControl As ITStreamControl
            objStreamControl = objCallControl

            If Not (objStreamControl Is Nothing) Then

                Dim objITCollStreams As ITCollection
                objITCollStreams = objStreamControl.Streams

                Dim nIndex As Long, objCrtStream As ITStream
                For nIndex = 1 To objITCollStreams.Count
                    objCrtStream = objITCollStreams.Item(nIndex)
                    If objCrtStream.MediaType = TAPIMEDIATYPE_AUDIO Then
                        If objCrtStream.Direction = TERMINAL_DIRECTION.TD_CAPTURE Then
                            objCrtStream.SelectTerminal(objTerminal)
                        End If
                    End If
                    objCrtStream = Nothing
                Next

                objITCollStreams = Nothing
                objStreamControl = Nothing
            End If
            'end  select terminal

            gobjCall.Connect(False)

            gobjTapi.Shutdown()

        End Sub

    End Module



    Wednesday, March 12, 2008 12:59 PM

All replies

  • I change the codes, delete the portion"       
    'select the terminal
            Dim objCallControl As ITBasicCallControl
            objCallControl = gobjCall
    ".

    But, when it run at "objTerminalSupport = objAddressCapabilities", get the error message:
    InvalidCastException was unhandled
    Unable to cast COM object of type 'System.__ComObject' to interface type 'TAPI3Lib.ITTerminalSupport'. This operation failed because the QueryInterface call on the COM component for the interface with IID .


    I guess differents between interface ITAddress and interface ITTerminalSupport cause this issue. How should I fix this issue ?

    Code Snippet

    Imports TAPI3Lib
    Imports System.Threading

    Module Module1

        Public Const TAPIMEDIATYPE_AUDIO As Integer = &H8
        Public Const LINEADDRESSTYPE_PHONENUMBER As Integer = &H1

        Sub Main()
            'initialize
            Dim gobjTapi As TAPI = New TAPI
            gobjTapi.Initialize()

            'select address
            Dim gobjAddress As ITAddress
            Dim objCollAddress As ITCollection
            objCollAddress = gobjTapi.Addresses

            Dim bFound As Boolean
            bFound = False
            Dim objCtrAddress As ITAddress
            Dim objMediaSupport As ITMediaSupport
            Dim objAddressCapabilities As ITAddressCapabilities

            Dim index As Integer
            For indexAddr As Integer = 1 To objCollAddress.Count
                objCtrAddress = objCollAddress.Item(indexAddr)
                objMediaSupport = objCtrAddress
                objAddressCapabilities = objCtrAddress

                If objMediaSupport.QueryMediaType(TAPIMEDIATYPE_AUDIO) And objCtrAddress.ServiceProviderName = "CiscoTSP001.tsp" Then
                    bFound = True
                End If

                If bFound = True Then
                    index = indexAddr
                    Exit For
                End If

                objAddressCapabilities = Nothing
                objMediaSupport = Nothing
                objCtrAddress = Nothing
            Next

            gobjAddress = objCollAddress.Item(index)

            'make a call
            Dim gobjCall As ITBasicCallControl
            gobjCall = gobjAddress.CreateCall("172015727", LINEADDRESSTYPE_PHONENUMBER, TAPIMEDIATYPE_AUDIO)

            'select the terminal

            Dim objTerminalSupport As ITTerminalSupport
            objTerminalSupport = objAddressCapabilities

            Dim objTerminal As ITTerminal
            objTerminal = objTerminalSupport.GetDefaultStaticTerminal(TAPIMEDIATYPE_AUDIO, TERMINAL_DIRECTION.TD_CAPTURE)

            objTerminal = Nothing

            Dim objStreamControl As ITStreamControl

            objStreamControl = gobjCall

            If Not (objStreamControl Is Nothing) Then

                Dim objITCollStreams As ITCollection
                objITCollStreams = objStreamControl.Streams

                Dim nIndex As Long, objCrtStream As ITStream
                For nIndex = 1 To objITCollStreams.Count
                    objCrtStream = objITCollStreams.Item(nIndex)
                    If objCrtStream.MediaType = TAPIMEDIATYPE_AUDIO Then
                        If objCrtStream.Direction = TERMINAL_DIRECTION.TD_CAPTURE Then
                            objCrtStream.SelectTerminal(objTerminal)
                        End If
                    End If
                    objCrtStream = Nothing
                Next

                objITCollStreams = Nothing
                objStreamControl = Nothing
            End If
            'end  select terminal

            gobjCall.Connect(False)

            Thread.Sleep(3000)
            gobjCall.Disconnect(DISCONNECT_CODE.DC_NORMAL)

            gobjTapi.Shutdown()

        End Sub

    End Module



    Thursday, March 13, 2008 3:56 AM