⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tapiline.cls

📁 用VB进行TAPI开发的源程.没有太详细的说明.有兴趣的同志得仔细看了.
💻 CLS
📖 第 1 页 / 共 2 页
字号:


Public Function OpenLine(Optional ByVal privileges As Long = LINECALLPRIVILEGE_NONE, _
                        Optional ByVal mediamodes As Long = LINEMEDIAMODE_INTERACTIVEVOICE) As Boolean
    'returns false on error or if a line is already open
    'if a TAPI error occurs the error number will be stored in m_LastTAPIerror
    If m_hLine <> 0 Then
        Debug.Print "OpenLine called recursively!"
        Exit Function
    End If
    Dim rc As Long
    
    'open the line for outgoing call
    '(passes a reference to itself in the dwCallbackinstance parameter
    'tapi will pass that reference back to the callback procedure and
    'we will use the ITapiCallbackSink interface to call back to this
    'class instance)
    rc = lineOpen(m_hLineApp, _
                    m_CurLineID, _
                    m_hLine, _
                    m_APIversions(m_CurLineID), _
                    0&, _
                    ByVal ObjPtr(Me), _
                    privileges, _
                    mediamodes, _
                    ByVal 0&)
    If rc <> TAPI_SUCCESS Then
        m_LastTAPIError = rc
        Debug.Print ErrorString(rc)
        Exit Function
    End If
    Debug.Assert m_hLine
    OpenLine = True

End Function
Public Function MakeCallAsynch(Optional ByVal phonenumber As String = "") As Boolean
    'returns false on error or if m_hLine has not been initialized(by calling OpenLine)
    'if a TAPI error occurs the error number will be stored in m_LastTAPIerror
    Dim rc As Long
    'Dim callParams As LINECALLPARAMS
    
    If 0 = m_hLine Then
        Debug.Print "MakeCallAsynch entered recursively!"
        Exit Function
    End If
    Debug.Print "MakeCallAsynch entered"
    
    'callParams.dwTotalSize = Len(callParams)
    If phonenumber = "" Then 'just get dialtone
        rc = lineMakeCall(m_hLine, m_hCall, vbNullString, 0&, ByVal 0&)
    Else 'dial a number
        rc = lineMakeCall(m_hLine, m_hCall, phonenumber, 0&, ByVal 0&)
    End If
    If rc > 0 Then
        'now placing call - completion will be signalled by a LINE_REPLY event in the callback
        'store positive request identifier in class member variable for use in the callback handler
        m_RequestingCall = rc
    Else
        m_LastTAPIError = rc
        Debug.Print "MakeCallAsynch error"
        Exit Function
    End If
    Debug.Print "MakeCallAsynch successful"
    MakeCallAsynch = True
    
End Function

Public Function DropCallAsynch() As Boolean
    'returns false on error or if m_hLine has not been initialized(by calling OpenLine)
    'if a TAPI error occurs the error number will be stored in m_LastTAPIerror
    Dim rc As Long
    
    If m_hCall = 0 Then
        Debug.Print "Can't drop call - no hCall!"
        Exit Function
    End If
    
    rc = lineDrop(m_hCall, vbNullString, 0&)
    If rc > 0 Then
        'dropping call
        m_DroppingCall = rc
    Else
        m_LastTAPIError = rc
        Exit Function
    End If
    DropCallAsynch = True
    
End Function

Public Function CloseLine() As Boolean
    'returns false on error or if a line is already closed
    'if a TAPI error occurs the error number will be stored in m_LastTAPIerror
    Dim rc As Long
    
    If 0 = m_hLine Then
        Debug.Print "No hLine to close!"
        Exit Function
    End If
    
    rc = lineClose(m_hLine)
    'line handle is now invalid
    Debug.Print "Line Closed"
    m_hLine = 0
    'store errors
    If rc <> TAPI_SUCCESS Then
        m_LastTAPIError = rc
        Exit Function
    End If
    
    CloseLine = True
    
End Function

Public Function ConfigDialog(Optional ByVal OwnerHwnd As Long = 0&, Optional ByVal DeviceClass As String = "") As Boolean
    Dim rc As Long
    
    If DeviceClass = "" Then
        rc = lineConfigDialog(m_CurLineID, OwnerHwnd, vbNullString)
    Else
        rc = lineConfigDialog(m_CurLineID, OwnerHwnd, DeviceClass)
    End If
    If rc <> TAPI_SUCCESS Then
       m_LastTAPIError = rc
       Exit Function
    End If
    'indicate success
    ConfigDialog = True
    
End Function

Public Function DialingPropertiesDialog(Optional ByVal OwnerHwnd As Long = 0&, Optional ByVal phonenumber As String = "") As Boolean
    Dim rc As Long
    If phonenumber = "" Then
        rc = lineTranslateDialog(m_hLineApp, m_CurLineID, m_ApplicationVersion, OwnerHwnd, vbNullString)
    Else
        rc = lineTranslateDialog(m_hLineApp, m_CurLineID, m_ApplicationVersion, OwnerHwnd, phonenumber)
    End If
    If rc <> TAPI_SUCCESS Then
        m_LastTAPIError = rc
        Exit Function
    End If
    'indicate success
    DialingPropertiesDialog = True
End Function
Public Function PaintDevIcon(ByVal hdc As Long, _
                                Optional ByVal left As Long = 0, _
                                Optional ByVal top As Long = 0, _
                                Optional ByVal width As Long = 0, _
                                Optional ByVal height As Long = 0) As Boolean
    Dim hIcon As Long
    Dim rc As Long
    
    rc = lineGetIcon(m_CurLineID, 0&, hIcon)
    If rc <> TAPI_SUCCESS Then
        m_LastTAPIError = rc
        Exit Function
    End If
    rc = DrawIconEx(hdc, left, top, hIcon, width, height, 0&, 0&, DI_NORMAL)
    '(function succeeds even when there is no icon in the TSP)
    If 0 = hIcon Then  'function failed (check actual hIcon instead of return value)
        Exit Function
    End If
    Call DestroyIcon(hIcon)
    
    PaintDevIcon = True
    
End Function


Private Function GetTAPIStructString(ByVal ptrTapistruct As Long, ByVal offset As Long, ByVal length As Long) As String
'ugly C-hacker way to deal with ugly C-hacker TAPI structs (UDTs)
Dim buffer() As Byte

If length < 1 Then Exit Function 'handle erroneous input

If offset Then '
    ReDim buffer(0 To length - 1)
    CopyMemory buffer(0), ByVal ptrTapistruct + offset, length
    GetTAPIStructString = StrConv(buffer, vbUnicode)
End If

End Function

Private Sub Class_Terminate()
    Debug.Print "class term"
    If m_hCall <> 0 Then
        Call lineDeallocateCall(m_hCall)
        m_hCall = 0
    End If
    If m_hLine <> 0 Then
        Call CloseLine
    End If
    If m_hLineApp <> 0 Then
        Call lineShutdown(m_hLineApp)
        m_hLineApp = 0
    End If
End Sub

Friend Sub LineProcHandler(ByVal hDevice As Long, _
                                        ByVal dwMsg As Long, _
                                        ByVal dwParam1 As Long, _
                                        ByVal dwParam2 As Long, _
                                        ByVal dwParam3 As Long)
'Handle callbacks here in the class itself via ITapiCallbackSink
    Debug.Print "Entering LineProcHandler"
    Select Case dwMsg
        Case LINE_REPLY
            If dwParam1 = m_RequestingCall Then
                Debug.Print "LINE_REPLY-CALL REQUEST RETURNS"
                '(earlier we called the asynch lineMakeCall() function from the
                'MakeCallAsynch method and stored the requester in m_RequestingCall
                'now we can see that this is the asynchronous reply to that call)
                'don't need ID anymore - it matched
                m_RequestingCall = 0
                
                'if it was an error make sure the line is closed
                If dwParam2 <> 0 Then Call CloseLine
                'send result to parent via event
                RaiseEvent MakeCallResult(dwParam2)
                
            ElseIf dwParam1 = m_DroppingCall Then
                Debug.Print "LINE_REPLY-CALL DROP RETURNS"
                'asynch reply to lineDrop() call
                m_DroppingCall = 0
                RaiseEvent DropCallResult(dwParam2)
                
            End If
        Case LINE_CALLSTATE
            Select Case dwParam1
                Case LINECALLSTATE_DISCONNECTED
                    'remote party has disconnected from the call
                    Debug.Print "LINECALLSTATE_DISCONNECTED"
                    Call DropCallAsynch
                    RaiseEvent Disconnected
                                    
                Case LINECALLSTATE_IDLE
                    'no call exists - the line is idle
                    Debug.Print "LINECALLSTATE_IDLE"
                    If m_hCall <> 0 Then
                        Debug.Print "Deallocating Call"
                        Call lineDeallocateCall(m_hCall)
                        Debug.Print "Closing Line"
                        Call CloseLine
                    End If
                    RaiseEvent Idle
                Case LINECALLSTATE_CONNECTED
                    Debug.Print "LINECALLSTATE_CONNECTED"
                    RaiseEvent Connected
                                       
                Case LINECALLSTATE_BUSY
                    Debug.Print "LINECALLSTATE_BUSY"
                    'nuff said
                
                Case LINECALLSTATE_DIALTONE
                    'switch is ready to receive a dialed number
                    Debug.Print "LINECALLSTATE_DIALTONE"
                
                Case LINECALLSTATE_RINGBACK
                    'the other station has been reached and is being alerted (ringing)
                    Debug.Print "LINECALLSTATE_RINGBACK"
                
                Case LINECALLSTATE_DIALING
                    Debug.Print "LINECALLSTATE_DIALING"
                
                Case LINECALLSTATE_PROCEEDING
                    Debug.Print "LINECALLSTATE_PROCEEDING"
                
                Case LINECALLSTATE_SPECIALINFO
                    'network error occured
                    Debug.Print "LINECALLSTATE_SPECIALINFO"
                    
                Case Else
                    Debug.Print "CallSTATE: " & Hex(dwParam1)
            End Select
        Case Else
    End Select

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -