📄 dial.cpp
字号:
}
exit :
if (lpCallParams)
LocalFree (lpCallParams);
if (lpTransOutput)
LocalFree (lpTransOutput);
// If the make call did not succeed but the line was opened,
// then close it.
if ((g_MakeCallRequestID <= 0) && (g_CurrentLineInfo.hLine))
CurrentLineClose ();
return;
}
/***********************************************************************
FUNCTION:
CurrentLineClose
PURPOSE:
This function closes the opened line device.
***********************************************************************/
VOID CurrentLineClose ()
{
Sleep(2000); // Time delay to provide message display.
// If lineMakeCall succeeded, then drop the call.
if (g_hCall)
{
g_DropCallRequestID = lineDrop (g_hCall, NULL, 0);
Sleep(5000);
lineDeallocateCall (g_hCall); // Deallocate call handle.
}
// Close the current line.
if (g_CurrentLineInfo.hLine)
lineClose (g_CurrentLineInfo.hLine);
// Reinitialize the variables.
g_CurrentLineInfo.hLine = NULL;
g_bCurrentLineAvail = TRUE;
g_hCall = NULL;
}
/***********************************************************************
FUNCTION:
InitializeTAPI
PURPOSE:
Initialize the application's use of Tapi.dll.
***********************************************************************/
DWORD InitializeTAPI ()
{
DWORD dwLineID,
dwReturn,
dwTimeCount = GetTickCount ();
TCHAR szWarning[] = TEXT("Cannot initialize tapi.dll.")
TEXT("\nQuit all other telephony")
TEXT("\nprograms, and try again.");
// Initialize the application's use of Tapi.dll. Keep trying until the
// user cancels or stops getting LINEERR_REINIT.
while ( (dwReturn = lineInitialize (&g_hLineApp,
g_hInst,
(LINECALLBACK) lineCallbackFunc,
g_szAppName,
&g_dwNumDevs)) == LINEERR_REINIT)
{
// Bring up the message box if 5 seconds have passed.
if (GetTickCount () > 5000 + dwTimeCount)
{
if (MessageBox (g_hwndMain, szWarning, TEXT("Warning"),
MB_OKCANCEL) == IDOK)
break;
// Reset the time counter.
dwTimeCount = GetTickCount ();
}
}
// If function "lineInitialize" fails, then return.
if (dwReturn)
{
MessageBox(g_hwndMain, L"lineInitialize fails", L"Message", MB_OK);
return dwReturn;
}
// If there is no device, then return.
if (g_dwNumDevs == 0)
{
MessageBox(g_hwndMain, L"There are no line devices available.", L"Message", MB_OK);
return LINEERR_NODEVICE;
}
// Allocate buffer for storing LINEINFO for all the available lines.
if (! (g_lpLineInfo = (LPLINEINFO) LocalAlloc (
LPTR,
sizeof (LINEINFO) * g_dwNumDevs)))
{
MessageBox(g_hwndMain, L"return LINEERR_NOMEM;", L"Message", MB_OK);
return LINEERR_NOMEM;
}
// Fill lpLineInfo[] for every line.
for (dwLineID = 0; dwLineID < g_dwNumDevs; ++dwLineID)
{
GetLineInfo (dwLineID, &g_lpLineInfo [dwLineID]);
}
return ERR_NONE;
}
/***********************************************************************
FUNCTION:
lineCallbackFunc
PURPOSE:
This is a callback function invoked to determine status and events on
the line device, addresses, or calls.
***********************************************************************/
VOID CALLBACK lineCallbackFunc (
DWORD hDevice,
DWORD dwMsg,
DWORD dwCallbackInstance,
DWORD dwParam1,
DWORD dwParam2,
DWORD dwParam3
)
{
BOOL bCloseLine = FALSE;
LPTSTR lpszStatus;
lpszStatus = TEXT(" ");
switch (dwMsg)
{
case LINE_CALLSTATE: // Sent after change of call state
// dwParam1 is the specific CALLSTATE change that is occurring.
switch (dwParam1)
{
case LINECALLSTATE_DIALTONE:
lpszStatus = TEXT("Dial tone");
break;
case LINECALLSTATE_DIALING:
lpszStatus = TEXT("Dialing...");
break;
case LINECALLSTATE_PROCEEDING:
lpszStatus = TEXT("Dialing completed, call proceeding.");
break;
case LINECALLSTATE_RINGBACK:
lpszStatus = TEXT("Ring back");
break;
case LINECALLSTATE_CONNECTED:
lpszStatus = TEXT("Connected");
break;
case LINECALLSTATE_BUSY:
lpszStatus = TEXT("Line busy, shutting down.");
bCloseLine = TRUE;
break;
case LINECALLSTATE_IDLE:
lpszStatus = TEXT("Line is idle");
break;
case LINECALLSTATE_SPECIALINFO:
lpszStatus =TEXT("Special Information, couldn't dial number");
bCloseLine = TRUE;
break;
case LINECALLSTATE_DISCONNECTED:
{
LPTSTR lpszDisconnected;
lpszDisconnected = TEXT(" ");
switch (dwParam2)
{
case LINEDISCONNECTMODE_NORMAL:
lpszDisconnected = TEXT("Remote party disconnected");
break;
case LINEDISCONNECTMODE_UNKNOWN:
lpszDisconnected = TEXT("Disconnected: Unknown reason");
break;
case LINEDISCONNECTMODE_REJECT:
lpszDisconnected = TEXT("Remote Party rejected call");
break;
case LINEDISCONNECTMODE_PICKUP:
lpszDisconnected =
TEXT("Disconnected: Local phone picked up");
break;
case LINEDISCONNECTMODE_FORWARDED:
lpszDisconnected = TEXT("Disconnected: Forwarded");
break;
case LINEDISCONNECTMODE_BUSY:
lpszDisconnected = TEXT("Disconnected: Busy");
break;
case LINEDISCONNECTMODE_NOANSWER:
lpszDisconnected = TEXT("Disconnected: No Answer");
break;
case LINEDISCONNECTMODE_BADADDRESS:
lpszDisconnected = TEXT("Disconnected: Bad address");
break;
case LINEDISCONNECTMODE_UNREACHABLE:
lpszDisconnected = TEXT("Disconnected: Unreachable");
break;
case LINEDISCONNECTMODE_CONGESTION:
lpszDisconnected = TEXT("Disconnected: Congestion");
break;
case LINEDISCONNECTMODE_INCOMPATIBLE:
lpszDisconnected = TEXT("Disconnected: Incompatible");
break;
case LINEDISCONNECTMODE_UNAVAIL:
lpszDisconnected = TEXT("Disconnected: Unavailable");
break;
case LINEDISCONNECTMODE_NODIALTONE:
lpszDisconnected = TEXT("Disconnected: No dial tone");
break;
default:
lpszDisconnected = TEXT("Disconnected: Unknown reason");
break;
} // end switch (dwParam2)
bCloseLine = TRUE;
lpszStatus = lpszDisconnected;
break;
} // end case LINECALLSTATE_DISCONNECTED:
} // end switch (dwParam1)
if (g_hwndDial)
MessageBox(g_hwndMain, lpszStatus, L"Message", MB_OK);
if (bCloseLine)
{
CurrentLineClose ();
if (g_hwndDial)
SendMessage (g_hwndDial, WM_COMMAND, MAKEWPARAM(IDOK,0), 0);
}
break;
case LINE_LINEDEVSTATE:
switch (dwParam1)
{
case LINEDEVSTATE_RINGING:
lpszStatus = TEXT("Ringing");
break;
case LINEDEVSTATE_OUTOFSERVICE:
lpszStatus = TEXT("The line selected is out of service.");
if (g_hwndDial)
MessageBox(g_hwndMain,L"The line selected is out of service.", L"Message",MB_OK);
CurrentLineClose ();
if (g_hwndDial)
SendMessage (g_hwndDial, WM_COMMAND, MAKEWPARAM(IDOK,0), 0);
break;
case LINEDEVSTATE_DISCONNECTED:
lpszStatus = TEXT("The line selected is disconnected.");
if (g_hwndDial)
MessageBox(g_hwndMain,L"The line selected is disconnected.", L"Message",MB_OK);
CurrentLineClose ();
if (g_hwndDial)
SendMessage (g_hwndDial, WM_COMMAND, MAKEWPARAM(IDOK,0), 0);
break;
case LINEDEVSTATE_MAINTENANCE:
lpszStatus = TEXT("The line selected is out for maintenance.");
if (g_hwndDial)
MessageBox(g_hwndMain,L"The line selected is out for maintenance.", L"Message",MB_OK);
CurrentLineClose ();
if (g_hwndDial)
SendMessage (g_hwndDial, WM_COMMAND, MAKEWPARAM(IDOK,0), 0);
break;
case LINEDEVSTATE_TRANSLATECHANGE:
break;
case LINEDEVSTATE_REMOVED:
MessageBox(g_hwndMain,TEXT("The Line device has been removed; no action taken."), L"Message",MB_OK);
break;
case LINEDEVSTATE_REINIT:
{
// This usually means that a service provider has changed in
// such a way that requires TAPI to REINIT. Note that there
// are both soft REINITs and hard REINITs. Soft REINITs do not
// require a full shutdown but an informational change that
// historically required a REINIT to force the application to
// deal with. TAPI API Version 1.3 applications require a
// full REINIT for both hard and soft REINITs.
switch(dwParam2)
{
// This is the hard REINIT. TAPI is waiting for everyone to
// shut down. Our response is to immediately shut down any
// calls, shut down our use of TAPI and notify the user.
case 0:
if (MessageBox (
g_hwndMain,
TEXT("Tapi line configuration has been changed. ")
TEXT("You have to shut down CeDialer to\n")
TEXT("re-initialize the use of tapi.dll. Do ")
TEXT("you want to shut down CeDialer now?"),
TEXT("Warning"),
MB_YESNO) == IDYES)
{
lineShutdown (g_hLineApp);
DestroyWindow (g_hwndMain);
}
break;
case LINE_CREATE:
lineCallbackFunc (hDevice, dwParam2, dwCallbackInstance,
dwParam3, 0, 0);
break;
case LINE_LINEDEVSTATE:
lineCallbackFunc (hDevice, dwParam2, dwCallbackInstance,
dwParam3, 0, 0);
break;
// There might be other reasons to send a soft REINIT.
// No need to shut down for these reasons.
default:
break;
}
}
default:
break;
}
break;
case LINE_REPLY:
// Reply from the lineMakeCall function.
if ((LONG)dwParam1 == g_MakeCallRequestID)
{
// If an error occurred on making the call.
if (dwParam2 != ERR_NONE)
{
lpszStatus = TEXT("Closing line");
if (dwParam2 == LINEERR_CALLUNAVAIL)
lpszStatus = TEXT("The line is not available.");
if (g_hwndDial)
MessageBox(g_hwndMain, L"The line is not available.", L"Message", MB_OK);
CurrentLineClose ();
if (g_hwndDial)
SendMessage (g_hwndDial, WM_COMMAND, MAKEWPARAM(IDOK,0), 0);
}
}
break;
case LINE_CREATE:
// dwParam1 is the device identifier of the new line.
if (dwParam1 >= g_dwNumDevs)
{
DWORD dwLineID;
LINEINFO *lpLineInfo;
g_dwNumDevs = dwParam1 + 1;
// Allocate a buffer for storing LINEINFO for all the lines.
if (!(lpLineInfo = (LPLINEINFO) LocalAlloc (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -