📄 ch26.htm
字号:
'<br>
Dim cMsg As String<br>
'<br>
Select Case dwMessage<br>
Case LINE_ADDRESSSTATE '(= 0&)<br>
cMsg = "MSG:
Line_AddressState"<br>
cMsg = cMsg &
"..."<br>
cMsg = cMsg &
"AddressID=" & CStr(dwParam1)<br>
cMsg = cMsg &
", State=" & LineAddressStateMsg(dwParam2) <br>
Case LINE_CALLINFO '(= 1&)<br>
cMsg = "MSG:
Line_CallInfo"<br>
Case LINE_CALLSTATE '(= 2&)<br>
cMsg = "MSG:
Line_CallState"<br>
cMsg = cMsg &
"..."<br>
cMsg = cMsg &
"CallState=" & LineCallStateMsg(dwParam1) <br>
' <br>
Select Case
dwParam1<br>
Case
LINECALLSTATE_BUSY<br>
cMsg
= cMsg & ", StateDependent=" & <font FACE="ZAPFDINGBATS">Â</font>LineCallStateBusyMsg(dwParam2)
<br>
Case
LINECALLSTATE_DIALTONE<br>
cMsg
= cMsg & ", StateDependent=" & <font FACE="ZAPFDINGBATS">Â</font>LineCallStateDialtoneMsg(dwParam2)
<br>
Case
LINECALLSTATE_DISCONNECTED<br>
cMsg
= cMsg & ", StateDependent=" & <font FACE="ZAPFDINGBATS">Â</font>LineCallStateDisconnectedMsg(dwParam2)
<br>
Case
Else<br>
cMsg
= cMsg & ", StateDependent=" & CStr(dwParam2) <br>
End Select<br>
' <br>
cMsg = cMsg &
", Privilege=" & CStr(dwParam3)<br>
Case LINE_CLOSE '(= 3&)<br>
cMsg = "MSG:
Line_Close"<br>
Case LINE_DEVSPECIFIC '(= 4&)<br>
cMsg = "MSG:
Line_DevSpecific"<br>
Case LINE_DEVSPECIFICFEATURE '(= 5&)<br>
cMsg = "MSG:
Line_DevSpecificFeature"<br>
Case LINE_GATHERDIGITS '(= 6&)<br>
cMsg = "MSG:
Line_GatherDigits"<br>
Case LINE_GENERATE '(= 7&)<br>
cMsg = "MSG:
Line_Generate"<br>
Case LINE_LINEDEVSTATE '(= 8&)<br>
cMsg = "MSG:
Line_LineDevState"<br>
Case LINE_MONITORDIGITS '(= 9&)<br>
cMsg = "MSG:
Line_MonitorDigits"<br>
Case LINE_MONITORMEDIA '(= 10&)<br>
cMsg = "MSG:
Line_MonitorMedia"<br>
Case LINE_MONITORTONE '(= 11&)<br>
cMsg = "MSG:
Line_MonitorTone"<br>
Case LINE_REPLY '(= 12&)<br>
cMsg = "MSG:
Line_Reply...idRequest=" & CStr(dwParam1) & " - Status = " <font
FACE="ZAPFDINGBATS">Â</font>& LineErr(dwParam2) <br>
Case LINE_REQUEST '(= 13&)<br>
cMsg = "MSG:
Line_Request"<br>
Case Else<br>
cMsg = "MSG:
Unknown Message..." + CStr(dwMessage)<br>
End Select<br>
'<br>
TapiCallBackHandler = cMsg<br>
'<br>
End Function</font></tt> </p>
</blockquote>
<hr>
<p>This routine is designed to turn the callback <tt><font FACE="Courier">MessageID</font></tt>
value and other parameters into a meaningful message to display in a status box on a form.
In production applications, you could use this same <tt><font FACE="Courier">SELECT CASE</font></tt>
structure to enclose calls to subroutines and functions that fire appropriate Visual Basic
code based on the messages received. </p>
<p>You'll also notice that there are several calls to other support routines that
translate parameters into meaningful strings for extended messages. These routines could
be replaced by Visual Basic code that performs other tasks based on the parameters passed
by TAPI into the <tt><font FACE="Courier">TAPICallBack</font></tt> event. </p>
<h3><a NAME="ASampleCallStateMessageFunction">A Sample <tt><font SIZE="4" FACE="Courier">CallState</font></tt><font
SIZE="4"> Message Function</font></a></h3>
<p>There are several functions that convert call-state parameters into messages. These
routines could be used to fire off Visual Basic code based on the state of the current
call. Listing 26.9 shows one of these routines. </p>
<hr>
<blockquote>
<b><p>Listing 26.9. A sample <tt><font FACE="Courier">CallState</font></tt> message
function.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Public Function LineCallStateDisconnectedMsg(dwParam As Long)
As String<br>
'<br>
' handle message values<br>
'<br>
Dim cReturn As String<br>
'<br>
Select Case dwParam<br>
Case LINEDISCONNECTMODE_NORMAL '
&H1&<br>
cReturn =
"Normal"<br>
Case LINEDISCONNECTMODE_UNKNOWN '
&H2&<br>
cReturn =
"Unknown"<br>
Case LINEDISCONNECTMODE_REJECT '
&H4&<br>
cReturn =
"Rejected"<br>
Case LINEDISCONNECTMODE_PICKUP '
&H8&<br>
cReturn =
"Picked Up"<br>
Case LINEDISCONNECTMODE_FORWARDED '
&H10&<br>
cReturn =
"Forwarded"<br>
Case LINEDISCONNECTMODE_BUSY '
&H20&<br>
cReturn =
"Busy"<br>
Case LINEDISCONNECTMODE_NOANSWER '
&H40&<br>
cReturn = "No
Answer"<br>
Case LINEDISCONNECTMODE_BADADDRESS '
&H80&<br>
cReturn =
"Invalid Address"<br>
Case LINEDISCONNECTMODE_UNREAchABLE '
&H100&<br>
cReturn =
"Unreachable"<br>
Case LINEDISCONNECTMODE_CONGESTION '
&H200&<br>
cReturn =
"Congested Network"<br>
Case LINEDISCONNECTMODE_IncOMPATIBLE '
&H400&<br>
cReturn =
"Incompatible Equipment"<br>
Case LINEDISCONNECTMODE_UNAVAIL '
&H800&<br>
cReturn =
"Reason Unavailable"<br>
Case Else<br>
cReturn =
"Unknown LineCallStateDisconnected Msg [" & CStr(dwParam) & <font
FACE="ZAPFDINGBATS">Â</font>"]"<br>
End Select<br>
'<br>
LineCallStateDisconnectedMsg = cReturn <br>
'<br>
End Function</font></tt> </p>
</blockquote>
<hr>
<p>This routine handles one of the parameters returned from a line disconnect event. </p>
<h3><a NAME="TheCleanandOffSetFunctions">The <tt><font SIZE="4" FACE="Courier">Clean</font></tt><font
SIZE="4"> and </font><tt><font SIZE="4" FACE="Courier">OffSet</font></tt><font SIZE="4">
Functions</font></a></h3>
<p>Some of the TAPI functions return data in variable-length strings. These data strings
usually contain several items, separated by zeros. You need two routines to help read the
data in these strings. First, you need a routine to clean out the zero character (0)
values in a returned string. Second, you need a routine that can pick a block of
characters out of the data string based on an offset and a string size. This offset and
size are returned as part of the fixed-size data structure. </p>
<p>The <tt><font FACE="Courier">Clean</font></tt> function removes all character string 0
values from the returned data. Listing 26.10 shows how this is done. </p>
<hr>
<blockquote>
<b><p>Listing 26.10. The <tt><font FACE="Courier">Clean</font></tt> function.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Function Clean(c As String) As String <br>
'<br>
' strip 0s from string<br>
'<br>
Dim l As Integer<br>
Dim x As Integer<br>
Dim s As String<br>
Dim n As Integer<br>
'<br>
l = Len<br>
s = ""<br>
For x = 1 To Len<br>
If Mid(c, x, 1) <> Chr(0) Then<br>
s = s + Mid(c, x,
1)<br>
Else<br>
s = s + "
"<br>
End If<br>
Next<br>
'<br>
Clean = s<br>
End Function</font></tt> </p>
</blockquote>
<hr>
<p>You'll notice that the routine replaces all character zeros with character 32 (space).
This maintains the original size of the string, but prevents Visual Basic from
encountering errors when it tries to read a string that contains character 0 values. </p>
<p>The second routine needed to handle the variable strings is one that picks out a
substring based on the offset and size values found in the fixed data structure. Listing
26.11 shows how the <tt><font FACE="Courier">GetOffset</font></tt> function works. </p>
<hr>
<blockquote>
<b><p>Listing 26.11. The <tt><font FACE="Courier">GetOffset</font></tt> function.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Public Function GetOffset(lLenStru As Long, lOffset As Long,
lSize As Long, <font FACE="ZAPFDINGBATS">Â</font>cExtraData As String) As String<br>
'<br>
' return the data at the offset<br>
'<br>
GetOffset = Mid(cExtraData, (lOffset - lLenStru) + 1, lSize)<br>
'<br>
End Function</font></tt> </p>
</blockquote>
<hr>
<p>TAPI returns an offset value computed from the start of the original data structure.
For this reason, the length of the data structure is passed as a first parameter into the
function. This length is the size of the fixed portion of the data structure. The <tt><font
FACE="Courier">GetOffset</font></tt> routine subtracts the fixed-length amount to get the
starting position in the <tt><font FACE="Courier">cExtraData</font></tt> string space.
This position is used to pick out a data string that is the length of <tt><font
FACE="Courier">lSize</font></tt>. The resulting string is then returned to the calling
program. </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -