TOOLS.BAS

Attribute VB_Name = "Tools" 

'
'Tools.bas
'

Option Explicit

'
'declarations needed for using win32 api MessageBox
'
Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Public Const MB_OK = &H0&
'add a new constant, that Or-ed with MB_OK will avoid the beep
Public Const MB_USERICON = &H80&


Public Sub PrintError(strTitle As String, Error As ErrObject)
Dim strMsg
strMsg = strTitle & ": run time error " & _
Error.Number & " Description: " & Error.Description

Debug.Print (strMsg)
End Sub

Public Function MTGuidToName(guidMediaType As String) As String

Select Case guidMediaType
Case TAPIMEDIATYPE_String_AudioIn
MTGuidToName = "AudioIn"
Case TAPIMEDIATYPE_String_AudioOut
MTGuidToName = "AudioOut"
Case TAPIMEDIATYPE_String_DataModem
MTGuidToName = "DataModem"
Case TAPIMEDIATYPE_String_G3Fax
MTGuidToName = "G3Fax"
Case TAPIMEDIATYPE_String_VideoIn
MTGuidToName = "VideoIn"
Case TAPIMEDIATYPE_String_VideoOut
MTGuidToName = "VideoOut"
Case Else
MTGuidToName = ""
Debug.Print ("Error: MTGuidToName: unknown Media Type!")
End Select

Debug.Assert (MTGuidToName <> "")

End Function

Private Function TerminalClassToName(guidTermClass As String) As String

Select Case guidTermClass
Case CLSID_String_FileTerminal
TerminalClassToName = "File"
Case CLSID_String_HandsetTerminal
TerminalClassToName = "Handset"
Case CLSID_String_HeadsetTerminal
TerminalClassToName = "Headset"
Case CLSID_String_MicrophoneTerminal
TerminalClassToName = "Microphone"
Case CLSID_String_SpeakerphoneTerminal
TerminalClassToName = "Speakerphone"
Case CLSID_String_SpeakersTerminal
TerminalClassToName = "Speakers"
Case CLSID_String_VideoInputTerminal
TerminalClassToName = "VideoInput"
Case CLSID_String_VideoWindowTerm
TerminalClassToName = "VideoWindow"
Case Else
TerminalClassToName = "Unknown Class"
Debug.Print ("Error: TerminalClassToName: unknown Terminal Class!")
End Select

Debug.Assert (TerminalClassToName <> "")

End Function

'This function creates the "complete" name of the terminal, by
'concatenating its name and its class. It is usefull for the cases
'when terminal names are not unique (i.e. the same name SoundBlaster
'can appear twice, once for the microphone device, once for the
'speakers device)
Public Function TerminalToCompleteName(objTerminal As Terminal) As String
On Error GoTo ErrHandle

Dim strTerminalName As String
Dim strTerminalClass As String

'the received terminal can be a valid terminal or the Null terminal
'the Null terminal is considered valid too, but I need to create its name

If objTerminal Is Nothing Then
strTerminalName = "No Terminal"
strTerminalClass = ""
Else
strTerminalName = objTerminal.Name
strTerminalClass = TerminalClassToName(objTerminal.TerminalClass)
End If

cleanup:
'append terminal name and terminal class name and return it
TerminalToCompleteName = strTerminalName & " - " & strTerminalClass
Exit Function

ErrHandle:
'I resume next, because I want to retrieve as much information
'as possible about the terminal's name. Maybe I end up only with
'its name without the class, but it's more than nothing

Call PrintError("TerminalToCompleteName", Err)
Resume Next
End Function