⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tapierr.cpp

📁 串口调试助手的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Written by JHCC, 1997

#include "stdafx.h"

#include "TAPIErr.h"
#include "tapix.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#if !defined(_CHINESE_)
LPCTSTR	CTAPIError::m_lpStrError = _T("Error");
LPCTSTR	CTAPIError::m_lpStrWarning = _T("Warning");
#else
LPCTSTR	CTAPIError::m_lpStrError = _T("错误");
LPCTSTR	CTAPIError::m_lpStrWarning = _T("警告");
#endif	// _CHINESE_

LPCTSTR	CTAPIError::m_plpStrErrorWarning[] =
{
	_T(""),	// TAPI_OK

	_T("lLineErr is really an async request ID, not an error.\n"),	// TAPI_ASYNC_REQUEST

	_T("Unhandled errors fail.\n"),	// TAPI_ERROR_UNHANDLE

	_T("Configuration information relating to Telephony services appears to be corrupt.\n"
		"This could be the first time you have used the Telephony services.\n"
		"Would you like to configure the Telephony services?"),	// TAPI_ERROR_INIFILECORRUPT

#if !defined(_CHINESE_)
	_T("One of the components of the Telephony device driver is missing.\n"
		"Use the Control Panel to set up the driver properly."),	// TAPI_ERROR_NODRIVER
#else
	_T("缺少电话设备驱动程序的一个部件,\n使用控制面板来设置正确的驱动程序"),	// TAPI_ERROR_NODRIVER
#endif	// _CHINESE_

#if !defined(_CHINESE_)
	_T("You have two copies of the same Telephony driver installed.\n"
		"Use the Control Panel to remove one of the copies."),
#else
	_T("你安装了同一个电话驱动程序的两份拷贝,\n使用控制面板来删除一份拷贝"),	// TAPI_ERROR_NOMULTIPLEINSTANCE
#endif	// _CHINESE_

	_T("Handle LINEERR_REINIT !\n"),	// TAPI_ERROR_REINIT

#if !defined(_CHINESE_)
	_T("Out of Memory error, canceling action."),	// TAPI_ERROR_NOMEM
#else
	_T("内存溢出, 取消操作"),	// TAPI_ERROR_NOMEM
#endif	// _CHINESE_

#if !defined(_CHINESE_)
	_T("TAPI Operation Failed for unknown reasons."),	// TAPI_ERROR_OPERATIONFAILED
#else
	_T("由于未知的原因导致TAPI操作失败."),	// TAPI_ERROR_OPERATIONFAILED
#endif	// _CHINESE_

#if !defined(_CHINESE_)
	_T("A Telephony resource is temporarily unavaiable.  "
		"This could mean a short wait is necessary or "
		"that a non-TAPI application is using the line."),	// TAPI_ERROR_RESOURCEUNAVAIL
#else
	_T("一个电话资源暂时失效. 这可能意味必须有一个短时间的等待"
		"或者一个非TAPI的应用程序正在使用线路."),	// TAPI_ERROR_RESOURCEUNAVAIL
#endif	// _CHINESE_
};

// Handle several standard LINEERR errors
//    This is the main error handler for all TAPI line APIs.
//    It handles (by correcting or just notifying the user)
//    most of the errors that can occur while using TAPI line APIs.
//
//    Note that many errors still return FALSE (unhandled) even
//    if a dialog is displayed.  Often, the dialog is just notifying
//    the user why the action was canceled.
BOOL	CTAPIError::HandleLineErr(long  lLineErr)
{	                
	if (lLineErr == TAPISUCCESS)
		return  TRUE;

	// All we do is dispatch the correct error handler.
	switch (lLineErr)
	{
	case LINEERR_INVALCARD:
	case LINEERR_INVALLOCATION:
	case LINEERR_INIFILECORRUPT:
		return  HandleIniFileCorrupt();

	case LINEERR_NODRIVER:
		return  HandleNoDriver();

	case LINEERR_REINIT:
		return  HandleReInit();

	case LINEERR_NOMULTIPLEINSTANCE:
		return  HandleNoMultipleInstance();

	case LINEERR_NOMEM:
		return  HandleNoMem();

	case LINEERR_OPERATIONFAILED:
		return  HandleOperationFailed();

	case LINEERR_RESOURCEUNAVAIL:
		return  HandleResourceUnavail();

	default:
		if (lLineErr > TAPISUCCESS)
		{
			TRACE0(m_plpStrErrorWarning[TAPI_ASYNC_REQUEST]);
		}
		else
		{
			TRACE0(m_plpStrErrorWarning[TAPI_ERROR_UNHANDLE]);
		}
	}
	return  FALSE;
}

// Handle INIFILECORRUPT error.
// This error shouldn't happen under Windows 95 anymore.
// The TAPI.DLL takes care of correcting this problem.
// If it does happen, just notify the user.
BOOL	CTAPIError::HandleIniFileCorrupt(void)
{
	if (::MessageBox(NULL, m_plpStrErrorWarning[TAPI_ERROR_INIFILECORRUPT],
		m_lpStrWarning, MB_OKCANCEL) == IDCANCEL);
		return  FALSE;

//		::lineTranslateDialog(m_hLineApp, 0, SAMPLE_TAPI_VERSION,
//			g_hDlgParentWindow, NULL);
  

	return  TRUE;
}

// Handle NODRIVER error.
BOOL	CTAPIError::HandleNoDriver(void)
{
	::MessageBox(NULL, m_plpStrErrorWarning[TAPI_ERROR_NODRIVER],
		m_lpStrWarning, MB_OK);
	return  FALSE;
}

// Handle NOMULTIPLEINSTANCE error.
BOOL	CTAPIError::HandleNoMultipleInstance(void)
{
	::MessageBox(NULL, m_plpStrErrorWarning[TAPI_ERROR_NOMULTIPLEINSTANCE],
		m_lpStrWarning, MB_OK);

	return  FALSE;
}

// Handle REINIT error.
BOOL	CTAPIError::HandleReInit(void)
{
	TRACE0(m_plpStrErrorWarning[TAPI_ERROR_REINIT]);
	CTAPIConnection::ShutdownTAPI();
	return  FALSE;
}

// Handle NOMEM error.
BOOL	CTAPIError::HandleNoMem(void)
{
	::MessageBox(NULL, m_plpStrErrorWarning[TAPI_ERROR_NOMEM], m_lpStrError, MB_OK);
	return  FALSE;
}

// Handle OPERATIONFAILED error.
BOOL	CTAPIError::HandleOperationFailed(void)
{
	::MessageBox(NULL, m_plpStrErrorWarning[TAPI_ERROR_OPERATIONFAILED],
		m_lpStrError, MB_OK);
    return  FALSE;
}

// Handle RESOURCEUNAVAIL error.
BOOL	CTAPIError::HandleResourceUnavail(void)
{
	return  (::MessageBox(NULL, m_plpStrErrorWarning[TAPI_ERROR_RESOURCEUNAVAIL],
		m_lpStrWarning, MB_RETRYCANCEL) == IDRETRY);
}

// Handle cases when we know NODEVICE error
// is returned because there are no devices installed.

// This function is not part of standard error handling
// but is only used when we know that the NODEVICE error
// means that no devices are installed.
BOOL	CTAPIError::HandleNoDevicesInstalled(void)
{
	if (::MessageBox(NULL, 
		"There are no devices configured for Telephony use.\n"
		"Would you like to run the Modem Control Panel to add a modem driver?",
		"Warning", MB_YESNO) == IDYES)
	{
		if (LaunchModemControlPanelAdd())
			return  TRUE;
	}        
	return  FALSE;
}

// Launch Add Modem Control Panel applet.
BOOL	CTAPIError::LaunchModemControlPanelAdd(void)
{
	PROCESS_INFORMATION	piProcInfo;
	STARTUPINFO	siStartupInfo;

	siStartupInfo.cb = sizeof(STARTUPINFO);
	siStartupInfo.lpReserved = NULL;
	siStartupInfo.lpDesktop = NULL;
	siStartupInfo.lpTitle = NULL;
	siStartupInfo.dwFlags = STARTF_USESHOWWINDOW;
	siStartupInfo.wShowWindow = SW_SHOWNORMAL;
	siStartupInfo.cbReserved2 = 0;
	siStartupInfo.lpReserved2 = NULL;
    
	// The string to launch the modem control panel is *VERY* likely
	// to change on NT. If nothing else, this is 'contrl32' on NT
	// instead of 'control'.
	if (::CreateProcess(
		NULL,
		"CONTROL.EXE MODEM.CPL,,ADD",
		NULL, NULL, FALSE, 
		NORMAL_PRIORITY_CLASS,
		NULL, NULL, 
		&siStartupInfo, 
		&piProcInfo))
	{
		::CloseHandle(piProcInfo.hThread);

		// Control panel 'Add New Modem' has been launched.
		// Now we should wait for it to go away before continueing.

		// If we WaitForSingleObject for the control panel to exit, then we
		// get into a deadlock situation if we need to respond to any messages
		// from the control panel.
        
		// If we use a PeekMessage loop to wait, we run into
		// message re-entrancy problems. (The user can get back to our UI
		// and click 'dial' again).

		// Instead, we take the easy way out and return FALSE to abort
		// the current operation.
		::CloseHandle(piProcInfo.hProcess);
	}
	else
	{
		TRACE1("Unable to LaunchModemControlPanelAdd: %lu\n", ::GetLastError());
		::MessageBox(NULL, 
			"Unable to launch the Modem Control Panel",
			"Warning", MB_OK);
	}
	return  FALSE;
}

// Prints a warning box when conditions remove a line in use.
// If there is a call in progress on the line removed, then display a message
// specifying why the line was removed and that the call is being canceled.
void	CTAPIError::WarningBox(LPCSTR  lpszMessage)
{
	CString	strMsg = lpszMessage;

	// If there is a call open, tell user we're going to close it.
//	if (m_hCall)
//		strMsg += _T("\nClosing existing call.");

	::MessageBox(NULL, strMsg, "Warning", MB_OK);

	strMsg += _T('\n');
	TRACE0(strMsg);
}

//*****************************************
// Global arrays for interpreting TAPI constants.
//*****************************************
LPCTSTR	pszLineErrorNameArray[] = 
{
	_T(""),
	_T("LINEERR_ALLOCATED"),
	_T("LINEERR_BADDEVICEID"),
	_T("LINEERR_BEARERMODEUNAVAIL"),
	_T("LINEERR Unused constant, ERROR!!"),
	_T("LINEERR_CALLUNAVAIL"),
	_T("LINEERR_COMPLETIONOVERRUN"),
	_T("LINEERR_CONFERENCEFULL"),
	_T("LINEERR_DIALBILLING"),
	_T("LINEERR_DIALDIALTONE"),
	_T("LINEERR_DIALPROMPT"),
	_T("LINEERR_DIALQUIET"),
	_T("LINEERR_INCOMPATIBLEAPIVERSION"),
	_T("LINEERR_INCOMPATIBLEEXTVERSION"),
	_T("LINEERR_INIFILECORRUPT"),
	_T("LINEERR_INUSE"),
	_T("LINEERR_INVALADDRESS"),
	_T("LINEERR_INVALADDRESSID"),
	_T("LINEERR_INVALADDRESSMODE"),
	_T("LINEERR_INVALADDRESSSTATE"),
	_T("LINEERR_INVALAPPHANDLE"),
	_T("LINEERR_INVALAPPNAME"),
	_T("LINEERR_INVALBEARERMODE"),
	_T("LINEERR_INVALCALLCOMPLMODE"),
	_T("LINEERR_INVALCALLHANDLE"),
	_T("LINEERR_INVALCALLPARAMS"),
	_T("LINEERR_INVALCALLPRIVILEGE"),
	_T("LINEERR_INVALCALLSELECT"),
	_T("LINEERR_INVALCALLSTATE"),
	_T("LINEERR_INVALCALLSTATELIST"),
	_T("LINEERR_INVALCARD"),
	_T("LINEERR_INVALCOMPLETIONID"),
	_T("LINEERR_INVALCONFCALLHANDLE"),
	_T("LINEERR_INVALCONSULTCALLHANDLE"),
	_T("LINEERR_INVALCOUNTRYCODE"),
	_T("LINEERR_INVALDEVICECLASS"),
	_T("LINEERR_INVALDEVICEHANDLE"),
	_T("LINEERR_INVALDIALPARAMS"),
	_T("LINEERR_INVALDIGITLIST"),
	_T("LINEERR_INVALDIGITMODE"),
	_T("LINEERR_INVALDIGITS"),
	_T("LINEERR_INVALEXTVERSION"),
	_T("LINEERR_INVALGROUPID"),
	_T("LINEERR_INVALLINEHANDLE"),
	_T("LINEERR_INVALLINESTATE"),
	_T("LINEERR_INVALLOCATION"),
	_T("LINEERR_INVALMEDIALIST"),
	_T("LINEERR_INVALMEDIAMODE"),
	_T("LINEERR_INVALMESSAGEID"),
	_T("LINEERR Unused constant, ERROR!!"),
	_T("LINEERR_INVALPARAM"),
	_T("LINEERR_INVALPARKID"),
	_T("LINEERR_INVALPARKMODE"),
	_T("LINEERR_INVALPOINTER"),
	_T("LINEERR_INVALPRIVSELECT"),
	_T("LINEERR_INVALRATE"),
	_T("LINEERR_INVALREQUESTMODE"),
	_T("LINEERR_INVALTERMINALID"),
	_T("LINEERR_INVALTERMINALMODE"),
	_T("LINEERR_INVALTIMEOUT"),
	_T("LINEERR_INVALTONE"),
	_T("LINEERR_INVALTONELIST"),
	_T("LINEERR_INVALTONEMODE"),
	_T("LINEERR_INVALTRANSFERMODE"),
	_T("LINEERR_LINEMAPPERFAILED"),
	_T("LINEERR_NOCONFERENCE"),
	_T("LINEERR_NODEVICE"),
	_T("LINEERR_NODRIVER"),
	_T("LINEERR_NOMEM"),
	_T("LINEERR_NOREQUEST"),
	_T("LINEERR_NOTOWNER"),
	_T("LINEERR_NOTREGISTERED"),
	_T("LINEERR_OPERATIONFAILED"),
	_T("LINEERR_OPERATIONUNAVAIL"),
	_T("LINEERR_RATEUNAVAIL"),
	_T("LINEERR_RESOURCEUNAVAIL"),
	_T("LINEERR_REQUESTOVERRUN"),
	_T("LINEERR_STRUCTURETOOSMALL"),
	_T("LINEERR_TARGETNOTFOUND"),
	_T("LINEERR_TARGETSELF"),
	_T("LINEERR_UNINITIALIZED"),
	_T("LINEERR_USERUSERINFOTOOBIG"),
	_T("LINEERR_REINIT"),
	_T("LINEERR_ADDRESSBLOCKED"),
	_T("LINEERR_BILLINGREJECTED"),
	_T("LINEERR_INVALFEATURE"),
	_T("LINEERR_NOMULTIPLEINSTANCE")
};


LPCTSTR	psz_dwMsg[] =
{
	_T("LINE_ADDRESSSTATE"),
	_T("LINE_CALLINFO"),
	_T("LINE_CALLSTATE"),
	_T("LINE_CLOSE"),
	_T("LINE_DEVSPECIFIC"),
	_T("LINE_DEVSPECIFICFEATURE"),
	_T("LINE_GATHERDIGITS"),
	_T("LINE_GENERATE"),
	_T("LINE_LINEDEVSTATE"),
	_T("LINE_MONITORDIGITS"),
	_T("LINE_MONITORMEDIA"),
	_T("LINE_MONITORTONE"),
	_T("LINE_REPLY"),
	_T("LINE_REQUEST"),
	_T("PHONE_BUTTON"),
	_T("PHONE_CLOSE"),
	_T("PHONE_DEVSPECIFIC"),
	_T("PHONE_REPLY"),
	_T("PHONE_STATE"),
	_T("LINE_CREATE"),
	_T("PHONE_CREATE")
};


LPCTSTR	pszfLINEADDRESSSTATE[] = 
{
	_T("Unknown LINEADDRESSSTATE information"),
	_T("LINEADDRESSSTATE_OTHER"),
	_T("LINEADDRESSSTATE_DEVSPECIFIC"),
	_T("LINEADDRESSSTATE_INUSEZERO"),
	_T("LINEADDRESSSTATE_INUSEONE"),
	_T("LINEADDRESSSTATE_INUSEMANY"),
	_T("LINEADDRESSSTATE_NUMCALLS"),
	_T("LINEADDRESSSTATE_FORWARD"),
	_T("LINEADDRESSSTATE_TERMINALS"),
	_T("LINEADDRESSSTATE_CAPSCHANGE")
};


LPCTSTR	pszfLINECALLINFOSTATE[] = 
{
	_T("Unknown LINECALLINFOSTATE state"),
	_T("LINECALLINFOSTATE_OTHER"),
	_T("LINECALLINFOSTATE_DEVSPECIFIC"),
	_T("LINECALLINFOSTATE_BEARERMODE"),
	_T("LINECALLINFOSTATE_RATE"),
	_T("LINECALLINFOSTATE_MEDIAMODE"),
	_T("LINECALLINFOSTATE_APPSPECIFIC"),
	_T("LINECALLINFOSTATE_CALLID"),
	_T("LINECALLINFOSTATE_RELATEDCALLID"),
	_T("LINECALLINFOSTATE_ORIGIN"),
	_T("LINECALLINFOSTATE_REASON"),
	_T("LINECALLINFOSTATE_COMPLETIONID"),
	_T("LINECALLINFOSTATE_NUMOWNERINCR"),
	_T("LINECALLINFOSTATE_NUMOWNERDECR"),
	_T("LINECALLINFOSTATE_NUMMONITORS"),
	_T("LINECALLINFOSTATE_TRUNK"),
	_T("LINECALLINFOSTATE_CALLERID"),
	_T("LINECALLINFOSTATE_CALLEDID"),
	_T("LINECALLINFOSTATE_CONNECTEDID"),
	_T("LINECALLINFOSTATE_REDIRECTIONID"),
	_T("LINECALLINFOSTATE_REDIRECTINGID"),
	_T("LINECALLINFOSTATE_DISPLAY"),
	_T("LINECALLINFOSTATE_USERUSERINFO"),
	_T("LINECALLINFOSTATE_HIGHLEVELCOMP"),
	_T("LINECALLINFOSTATE_LOWLEVELCOMP"),
	_T("LINECALLINFOSTATE_CHARGINGINFO"),
	_T("LINECALLINFOSTATE_TERMINAL"),
	_T("LINECALLINFOSTATE_DIALPARAMS"),
	_T("LINECALLINFOSTATE_MONITORMODES")
};

LPCTSTR	pszfLINECALLSTATE[] = 
{
	_T("Unknown LINECALLSTATE state"),
	_T("LINECALLSTATE_IDLE"),
	_T("LINECALLSTATE_OFFERING"),
	_T("LINECALLSTATE_ACCEPTED"),
	_T("LINECALLSTATE_DIALTONE"),
	_T("LINECALLSTATE_DIALING"),
	_T("LINECALLSTATE_RINGBACK"),
	_T("LINECALLSTATE_BUSY"),
	_T("LINECALLSTATE_SPECIALINFO"),
	_T("LINECALLSTATE_CONNECTED"),
	_T("LINECALLSTATE_PROCEEDING"),
	_T("LINECALLSTATE_ONHOLD"),
	_T("LINECALLSTATE_CONFERENCED"),
	_T("LINECALLSTATE_ONHOLDPENDCONF"),
	_T("LINECALLSTATE_ONHOLDPENDTRANSFER"),
	_T("LINECALLSTATE_DISCONNECTED"),
	_T("LINECALLSTATE_UNKNOWN")
};

LPCTSTR	pszfLINEDIALTONEMODE[] =
{
	_T("Unknown LINEDIALTONE information"),
	_T("LINEDIALTONEMODE_NORMAL"),
	_T("LINEDIALTONEMODE_SPECIAL"),
	_T("LINEDIALTONEMODE_INTERNAL"),
	_T("LINEDIALTONEMODE_EXTERNAL"),
	_T("LINEDIALTONEMODE_UNKNOWN"),
	_T("LINEDIALTONEMODE_UNAVAIL")
};

LPCTSTR	pszfLINEBUSYMODE[] =
{
	_T("Unknown LINEBUSYMODE information"),
	_T("LINEBUSYMODE_STATION"),
	_T("LINEBUSYMODE_TRUNK"),
	_T("LINEBUSYMODE_UNKNOWN"),
	_T("LINEBUSYMODE_UNAVAIL")
};

LPCTSTR	pszfLINESPECIALINFO[] =
{
	_T("Unknown LINESPECIALINFO information"),
	_T("LINESPECIALINFO_NOCIRCUIT"),
	_T("LINESPECIALINFO_CUSTIRREG"),
	_T("LINESPECIALINFO_REORDER"),
	_T("LINESPECIALINFO_UNKNOWN"),
	_T("LINESPECIALINFO_UNAVAIL")
};

LPCTSTR	pszfLINEDISCONNECTED[] =

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -