📄 tapis.cpp
字号:
#include "stdafx.h"
#include "..\\include\\SmarFaxh.h"
#include "tapifax.h"
time_t g_tInitTime;
DWORD g_dwNumDevs;
DWORD g_dwTAPIVer= 0x00020000;
LINEINITIALIZEEXPARAMS lineInitializeExParams;
#define TAPI_MAX_VERSION 0x0FFF0FFF
// Public available define
HANDLE hIOCP; /* handle for IO Completion port */
HLINEAPP g_hLineApp = NULL;
BOOL g_bShuttingDown = FALSE;
BOOL g_bStoppingCall = FALSE;
BOOL g_bInitializing = FALSE;
// This sample only supports one call in progress at a time.
BOOL g_bTapiInUse = FALSE;
// Data needed per call. This sample only supports one call.
HCALL g_hCall = NULL;
HLINE g_hLine = NULL;
BOOL g_bConnected = FALSE;
DWORD dwAPIVersion;
#pragma comment(lib, "Tapi32.lib")
BOOL InitializeTAPI(DWORD dwDeviceID)
{
long lReturn;
BOOL bTryReInit = TRUE;
HINSTANCE hInstance;
// If we're already initialized, then initialization succeeds.
if (g_hLineApp)
return TRUE;
if(g_bTapiInUse)
return TRUE;
// If we're in the middle of initializing, then fail, we're not done.
if (g_bInitializing)
return FALSE;
g_bInitializing = TRUE;
hInstance = GetModuleHandle(NULL);
LPLINEDEVCAPS lpDevCaps = NULL;
// Initialize TAPI
do
{
#if TAPI_CURRENT_VERSION >= 0x00020000
memset(&lineInitializeExParams, 0, sizeof(LINEINITIALIZEEXPARAMS));
// Populate the options...
lineInitializeExParams.dwTotalSize = sizeof(LINEINITIALIZEEXPARAMS);
lineInitializeExParams.dwOptions = LINEINITIALIZEEXOPTION_USEHIDDENWINDOW;
dwAPIVersion = TAPI_CURRENT_VERSION;
lReturn = lineInitializeEx(&g_hLineApp, hInstance, lineCallbackFunc,
"SmartFaxSample", &g_dwNumDevs,
&dwAPIVersion, &lineInitializeExParams);
#else
// Note that you can't use this function and be UNICODE
lReturn = lineInitialize(&g_hLineApp, hInstance,
lineCallbackFunc, "SmartFaxSample", &g_dwNumDevs);
#endif
// If we get this error, its because some other app has yet
// to respond to the REINIT message. Wait 5 seconds and try
// again. If it still doesn't respond, tell the user.
if (lReturn == LINEERR_REINIT)
{
if (bTryReInit)
{
MSG msg;
DWORD dwTimeStarted;
dwTimeStarted = GetTickCount();
while(GetTickCount() - dwTimeStarted < 5000)
{
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
bTryReInit = FALSE;
continue;
}
else
{
AfxMessageBox("A change to the system configuration requires that "
"all Telephony applications relinquish their use of "
"Telephony before any can progress. "
"Some have not yet done so.");
g_bInitializing = FALSE;
return FALSE;
}
}
if (lReturn == LINEERR_NODEVICE)
{
AfxMessageBox("No devices installed.\n");
g_bInitializing = FALSE;
return FALSE;
}
else if(lReturn != SUCCESS)
{
AfxMessageBox("lineInitialize error: ");
g_bInitializing = FALSE;
return FALSE;
}
} while(lReturn != SUCCESS);
LINEEXTENSIONID LineExtensionID;
if (lReturn = lineNegotiateAPIVersion(g_hLineApp, dwDeviceID,
0x00010004, TAPI_MAX_VERSION, &dwAPIVersion, &LineExtensionID))
{
TRACE(TEXT("lineNegotiateAPIVersion failed: %s.\r\n"), FormatTapiError(lReturn));
g_bInitializing = FALSE;
return FALSE;
}
lpDevCaps = (LINEDEVCAPS *)malloc(sizeof(LINEDEVCAPS)+1000); // Allocate a little extra memory...
if(!lpDevCaps)
{
TRACE("Out of memory \n");
g_bInitializing = FALSE;
return FALSE;
}
memset(lpDevCaps, 0, sizeof(LINEDEVCAPS)+1000);
lpDevCaps->dwTotalSize = sizeof(LINEDEVCAPS)+1000;
if( (lReturn = lineGetDevCaps(g_hLineApp, dwDeviceID, dwAPIVersion,0,lpDevCaps)) != SUCCESS)
{
TRACE(TEXT("lineGetDevCaps failed: %s.\r\n"), FormatTapiError(lReturn));
free(lpDevCaps);
g_bInitializing = FALSE;
return FALSE;
}
if (!(lpDevCaps->dwMediaModes & LINEMEDIAMODE_DATAMODEM))
{
TRACE("The selected line doesn't support DATAMODEM capabilities\n");
free(lpDevCaps);
g_bInitializing = FALSE;
return FALSE;
}
free(lpDevCaps);
g_tInitTime = time(NULL);
if (lReturn = lineOpen(g_hLineApp, dwDeviceID, &g_hLine, dwAPIVersion, 0, g_tInitTime,
LINECALLPRIVILEGE_OWNER,LINEMEDIAMODE_DATAMODEM, NULL))
{
TRACE(TEXT("lineOpen failed: %s.\r\n"), FormatTapiError(lReturn));
if(0x80000048)
{
AfxMessageBox("TAPI modem is not accessiable,Modem may be in user.");
}
g_bInitializing = FALSE;
return FALSE;
}
if( (lReturn = lineSetStatusMessages(g_hLine, 0x1ffffff, 0) ) )
{
TRACE(TEXT("lineOpen failed: %s.\r\n"), FormatTapiError(lReturn));
g_bInitializing = FALSE;
return FALSE;
}
g_bInitializing = FALSE;
g_bTapiInUse = TRUE;
return TRUE;
}
//
// FUNCTION: BOOL ShutdownTAPI()
//
// PURPOSE: Shuts down all use of TAPI
//
// PARAMETERS:
// None
//
// RETURN VALUE:
// True if TAPI successfully shut down.
//
// COMMENTS:
//
// If ShutdownTAPI fails, then its likely either a problem
// with the service provider (and might require a system
// reboot to correct) or the application ran out of memory.
//
//
BOOL ShutdownTAPI()
{
long lReturn;
// If we aren't initialized, then Shutdown is unnecessary.
if (g_hLineApp == NULL)
return TRUE;
// Prevent ShutdownTAPI re-entrancy problems.
if (g_bShuttingDown)
return TRUE;
g_bShuttingDown = TRUE;
lineDrop(g_hCall, NULL, 0);
//lineDeallocateCall(hCall);
lineClose(g_hLine);
do
{
lReturn = lineShutdown(g_hLineApp);
if(lReturn != SUCCESS )
TRACE("lineShutdown unhandled error: ");
} while(lReturn != SUCCESS);
g_bTapiInUse = FALSE;
g_bConnected = FALSE;
g_hLineApp = NULL;
g_hCall = NULL;
g_hLine = NULL;
g_bShuttingDown = FALSE;
TRACE("TAPI uninitialized.\n");
return TRUE;
}
#define CHAN_DEBUG_PRINT TRACE
VOID FAR PASCAL lineCallbackFunc(DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance, DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
{
TRACE(" get the dwDevice %d \n",dwDevice);
TRACE(" get the dwMessageID %d \n",dwMsg);
TRACE(" get the dwCallbackInstance %d \n",dwCallbackInstance);
TRACE(" get the dwParam1 %d \n",dwParam1);
TRACE(" get the dwParam2 %d \n",dwParam2);
TRACE(" get the dwParam3 %d \n",dwParam3);
TRACE("----------------------------------------------\n");
static int n_RingTimes = 0 ;
if(g_tInitTime !=(time_t)dwCallbackInstance)
return ;
switch(dwMsg)
{
case LINE_ADDRESSSTATE:
{
CHAN_DEBUG_PRINT("get Tapi msg LINE_ADDRESSSTATE\n");
break;
}
case LINE_CALLINFO:
{
CHAN_DEBUG_PRINT("get Tapi msg LINE_CALLINFO");
break;
}
case LINE_CALLSTATE:
{
CHAN_DEBUG_PRINT("get Tapi msg -------------LINE_CALLSTATE----------\n");
switch(dwParam1)
{
case LINECALLSTATE_DIALTONE:
{
break;
}
case LINECALLSTATE_BUSY:
{
break;
}
case LINECALLSTATE_SPECIALINFO:
{
break;
}
case LINECALLSTATE_IDLE:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -