Public Sub Modem_stuff()
Dim myTapiClass As New clsTAPI
myTapiClass.InitializeTAPI
myTapiClass.SelectAnAddress
myTapiClass.RegisterEvents
myTapiClass.ReceiveACall
myTapiClass.SelectATerminal
'MsgBox ("Modem Stuff Done")
End Sub
<here's the class clsTAPI that I declared as myTapiClass>
'Usually declared globally
Dim WithEvents gobjTapiWithEvents As TAPI
Dim glRegistrationToken As Long
'Usually declared globally
Dim gobjTapi As TAPI
Dim gobjAddress As ITAddress2
'Usually performed at the same time
'as TAPI initialization
Const TAPI3_CALL_EVENTS = _
TE_CALLMEDIA Or _
TE_CALLNOTIFICATION Or _
TE_CALLSTATE
Sub InitializeTAPI()
' Set error handling routine
' On Error GoTo MyErrorRoutine
'Usually performed during form load
'Create the tapi object.
Set gobjTapi = New TAPI
'Call Initialize before calling any other TAPI function.
Call gobjTapi.Initialize
End Sub
Sub SelectAnAddress()
'On Error GoTo MyErrorRoutine
'pick up the collection of Address objects
Dim objCollAddresses As ITCollection
Set objCollAddresses = gobjTapi.Addresses
'find address that supports the desired type, nSelectedType
bFound = False
For indexAddr = 1 To objCollAddresses.Count
Set objCrtAddress = objCollAddresses.Item(indexAddr)
Set objMediaSupport = objCrtAddress
Set objAddressCapabilities = objCrtAddress
If objMediaSupport.QueryMediaType(TAPIMEDIATYPE_AUDIO) Then
bFound = True
End If
Set objAddressCapabilities = Nothing
Set objMediaSupport = Nothing
Set objCrtAddress = Nothing
If bFound = True Then Exit For
Next indexAddr
Set gobjAddress = objCollAddresses.Item(indexAddr)
End Sub
Sub RegisterEvents()
'Set the EventFilter to accept all defined TAPI events.
gobjTapi.EventFilter = TAPI3_CALL_EVENTS
'Register the outgoing interface (the one that will actually
'receive and process the events).
Set gobjTapiWithEvents = gobjTapi
Dim fOwner As Boolean, fMonitor As Boolean
Dim lMediaTypes As Long, lCallbackInstance As Long
'fOwner = True ensures that the application receives incoming calls
'and their call state events.
fOwner = True
fMonitor = False
lMediaTypes = TAPIMEDIATYPE_AUDIO
lCallbackInstance = 1
glRegistrationToken = gobjTapi.RegisterCallNotifications( _
gobjAddress, _
fMonitor, _
fOwner, _
lMediaTypes, _
lCallbackInstance)
End Sub
Sub SelectATerminal()
' Set error handling routine
' On Error GoTo MyErrorRoutine
'query for ITBasicCallControl, the call control interface
Dim objCallControl As ITBasicCallControl
Set objCallControl = gobjReceivedCallInfo
'query ITTerminalSupport from Address object
Dim objTerminalSupport As ITTerminalSupport
Set objTerminalSupport = gobjAddress
Dim objTerminal As ITTerminal
Set objTerminal = objTerminalSupport.GetDefaultStaticTerminal( _
lMediaType, Dir)
'release not needed objects
Set objTerminalSupport = Nothing
'Select the terminal before answering
'we'll need the ITStreamControl interface for doing this.
Dim objStreamControl As ITStreamControl
Set objStreamControl = objCallControl
If Not (objStreamControl Is Nothing) Then
Dim objITCollStreams As ITCollection
Set objITCollStreams = objStreamControl.Streams
Dim nIndex As Long, objCrtStream As ITStream
For nIndex = 1 To objITCollStreams.Count
Set objCrtStream = objITCollStreams.Item(nIndex)
If objCrtStream.MediaType = lMediaType Then
If objCrtStream.Direction = Dir Then
Call objCrtStream.SelectTerminal(objTerminal)
End If
End If
Set objCrtStream = Nothing
Next nIndex
Set objITCollStreams = Nothing
Set objStreamControl = Nothing
End If
End Sub
Sub ReceiveACall()
If TapiEvent = TE_CALLNOTIFICATION Then
' Get the ITCallNotification interface.
Dim objCallNotificationEvent As ITCallNotificationEvent
Set objCallNotificationEvent = pEvent
'query ITCallInfo interface for the new call, and store it
Dim gobjReceivedCallInfo As ITCallInfo
Set gobjReceivedCallInfo = objCallNotificationEvent.Call
' Get the ITBasicCallControl interface.
Dim objCallControl As ITBasicCallControl
Set objCallControl = gobjReceivedCallInfo
' Create the required terminals for this call.
' See the Select a Terminal code example.
'Answer
objCallControl.answer
End If
End Sub