📄 telephony.vb
字号:
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Public Class Telephony
Implements IDisposable
Private hLine As IntPtr = IntPtr.Zero
Private hLineApp As IntPtr = IntPtr.Zero
Public Sub New()
Dim numDevices As Integer = 0
Dim version As Integer = &H20000
Dim initParams As New LINEINITIALIZEEXPARAMS
initParams.dwTotalSize = Marshal.SizeOf(initParams)
initParams.dwOptions = LINEINITIALIZEEXOPTION.USEEVENT
Dim result As Integer = lineInitializeEx(Me.hLineApp, GetModuleHandle(Nothing), 0, "Chapter9", numDevices, version, initParams)
Dim cellularLineIndex As Integer = 0
Dim thisDevice As Integer = 0
Do While (thisDevice < numDevices)
Dim caps As Byte() = New Byte((Marshal.SizeOf(GetType(LINEDEVCAPS)) + &H100) - 1) {}
BitConverter.GetBytes(caps.Length).CopyTo(caps, 0)
result = Telephony.lineGetDevCaps(Me.hLineApp, thisDevice, &H20000, 0, caps)
Dim namelen As Integer = BitConverter.ToInt32(caps, &H20)
Dim nameoffset As Integer = BitConverter.ToInt32(caps, &H24)
Dim lineName As String = System.Text.Encoding.Unicode.GetString(caps, nameoffset, namelen)
Dim nullIndex As Integer = lineName.IndexOf(ChrW(0))
If (nullIndex > -1) Then
lineName = lineName.Substring(0, nullIndex)
End If
If (lineName Is "Cellular Line") Then
cellularLineIndex = thisDevice
Exit Do
End If
thisDevice += 1
Loop
result = Telephony.lineOpen(Me.hLineApp, cellularLineIndex, Me.hLine, version, 0, 0, LINECALLPRIVILEGE.NONE, LINEMEDIAMODE.INTERACTIVEVOICE, IntPtr.Zero)
End Sub
Public Sub Dispose()
Me.Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Sub Dispose(ByVal disposing As Boolean)
If (Me.hLine <> IntPtr.Zero) Then
Telephony.lineClose(Me.hLine)
Me.hLine = IntPtr.Zero
End If
If (Me.hLineApp <> IntPtr.Zero) Then
Telephony.lineShutdown(Me.hLineApp)
Me.hLineApp = IntPtr.Zero
End If
End Sub
Protected Overrides Sub Finalize()
Try
Me.Dispose(False)
Finally
MyBase.Finalize()
End Try
End Sub
<DllImport("coredll", SetLastError:=True)> _
Friend Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr
End Function
<DllImport("coredll", SetLastError:=True)> _
Friend Shared Function lineClose(ByVal hLine As IntPtr) As Integer
End Function
<DllImport("coredll", SetLastError:=True)> _
Friend Shared Function lineGetDevCaps(ByVal hLineApp As IntPtr, ByVal dwDeviceID As Integer, ByVal dwAPIVersion As Integer, ByVal dwExtVersion As Integer, ByVal lpLineDevCaps As Byte()) As Integer
End Function
<DllImport("cellcore", SetLastError:=True)> _
Friend Shared Function lineGetEquipmentState(ByVal hLine As IntPtr, <Out()> ByRef lpdwState As LINEEQUIPSTATE, <Out()> ByRef lpdwRadioSupport As LINERADIOSUPPORT) As Integer
End Function
<DllImport("coredll", SetLastError:=True)> _
Friend Shared Function lineInitializeEx(ByRef lphLineApp As IntPtr, ByVal hInstance As IntPtr, ByVal lpfnCallback As Integer, ByVal lpszFriendlyAppName As String, ByRef lpdwNumDevs As Integer, ByRef lpdwAPIVersion As Integer, ByRef lpLineInitializeExParams As LINEINITIALIZEEXPARAMS) As Integer
End Function
<DllImport("coredll", SetLastError:=True)> _
Friend Shared Function lineOpen(ByVal hLineApp As IntPtr, ByVal dwDeviceID As Integer, <Out()> ByRef lphLine As IntPtr, ByVal dwAPIVersion As Integer, ByVal dwExtVersion As Integer, ByVal dwCallbackInstance As Integer, ByVal dwPrivileges As LINECALLPRIVILEGE, ByVal dwMediaModes As LINEMEDIAMODE, ByVal lpCallParams As IntPtr) As Integer
End Function
<DllImport("cellcore", SetLastError:=True)> _
Friend Shared Function lineRegister(ByVal hLine As IntPtr, ByVal dwRegisterMode As LINEREGMODE, ByVal lpszOperator As String, ByVal dwOperatorFormat As Integer) As Integer
End Function
<DllImport("cellcore", SetLastError:=True)> _
Friend Shared Function lineSetEquipmentState(ByVal hLine As IntPtr, ByVal dwState As LINEEQUIPSTATE) As Integer
End Function
<DllImport("coredll", SetLastError:=True)> _
Friend Shared Function lineShutdown(ByVal hLineApp As IntPtr) As Integer
End Function
<DllImport("cellcore", SetLastError:=True)> _
Friend Shared Function lineUnregister(ByVal hLine As IntPtr) As Integer
End Function
Public Property PhoneEnabled() As Boolean
Get
Dim state As LINEEQUIPSTATE
Dim radio As LINERADIOSUPPORT
lineGetEquipmentState(Me.hLine, state, radio)
Return (state = LINEEQUIPSTATE.FULL)
End Get
Set(ByVal value As Boolean)
If value Then
lineSetEquipmentState(Me.hLine, LINEEQUIPSTATE.FULL)
lineRegister(Me.hLine, LINEREGMODE.AUTOMATIC, Nothing, 0)
Else
lineUnregister(Me.hLine)
lineSetEquipmentState(Me.hLine, LINEEQUIPSTATE.MINIMUM)
End If
End Set
End Property
Friend Enum LINECALLPRIVILEGE
NONE = 1
MONITOR = 2
End Enum
<StructLayout(LayoutKind.Sequential)> _
Public Structure LINEDEVCAPS
Public dwTotalSize As Integer
Public dwNeededSize As Integer
Public dwUsedSize As Integer
Public dwProviderInfoSize As Integer
Public dwProviderInfoOffset As Integer
Public dwSwitchInfoSize As Integer
Public dwSwitchInfoOffset As Integer
Public dwPermanentLineID As Integer
Public dwLineNameSize As Integer
Public dwLineNameOffset As Integer
Public dwStringFormat As Integer
Public dwAddressModes As Integer
Public dwNumAddresses As Integer
Public dwBearerModes As Integer
Public dwMaxRate As Integer
Public dwMediaModes As Integer
Public dwGenerateToneModes As Integer
Public dwGenerateToneMaxNumFreq As Integer
Public dwGenerateDigitModes As Integer
Public dwMonitorToneMaxNumFreq As Integer
Public dwMonitorToneMaxNumEntries As Integer
Public dwMonitorDigitModes As Integer
Public dwGatherDigitsMintimeout As Integer
Public dwGatherDigitsMaxTimeout As Integer
Public dwMedCtlDigitMaxListSize As Integer
Public dwMedCtlMediaMaxListSize As Integer
Public dwMedCtlToneMaxListSize As Integer
Public dwMedCtlCallStateMaxListSize As Integer
Public dwDevCapFlags As Integer
Public dwMaxNumActiveCalls As Integer
Public dwAnswerMode As Integer
Public dwRingModes As Integer
Public dwLineStates As Integer
Public dwUUIAcceptSize As Integer
Public dwUUIAnswerSize As Integer
Public dwUUIMakeCallSize As Integer
Public dwUUIDropSize As Integer
Public dwUUISendUserUserInfoSize As Integer
Public dwUUICallInfoSize As Integer
Private MinDialParams As LINEDIALPARAMS
Private MaxDialParams As LINEDIALPARAMS
Private DefaultDialParams As LINEDIALPARAMS
Public dwNumTerminals As Integer
Public dwTerminalCapsSize As Integer
Public dwTerminalCapsOffset As Integer
Public dwTerminalTextEntrySize As Integer
Public dwTerminalTextSize As Integer
Public dwTerminalTextOffset As Integer
Public dwDevSpecificSize As Integer
Public dwDevSpecificOffset As Integer
Public dwLineFeatures As Integer
Public dwSettableDevStatus As Integer
Public dwDeviceClassesSize As Integer
Public dwDeviceClassesOffset As Integer
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure LINEDIALPARAMS
' Fields
Public dwDialPause As Integer
Public dwDialSpeed As Integer
Public dwDigitDuration As Integer
Public dwWaitForDialtone As Integer
End Structure
Friend Enum LINEEQUIPSTATE
' Fields
FULL = 5
MINIMUM = 1
NOTXRX = 4
RXONLY = 2
TXONLY = 3
End Enum
Public Enum LINEINITIALIZEEXOPTION
' Fields
USECOMPLETIONPORT = 3
USEEVENT = 2
USEHIDDENWINDOW = 1
End Enum
<StructLayout(LayoutKind.Sequential)> _
Public Structure LINEINITIALIZEEXPARAMS
Public dwTotalSize As Integer
Public dwNeededSize As Integer
Public dwUsedSize As Integer
Public dwOptions As LINEINITIALIZEEXOPTION
Public handle As IntPtr
Public dwCompletionKey As Integer
End Structure
<Flags()> _
Friend Enum LINEMEDIAMODE
INTERACTIVEVOICE = 4
End Enum
Friend Enum LINERADIOSUPPORT
[OFF] = 1
[ON] = 2
UNKNOWN = 3
End Enum
Friend Enum LINEREGMODE
AUTOMATIC = 1
End Enum
Public Sub Dispose1() Implements System.IDisposable.Dispose
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -