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

📄 mytapi_.c

📁 支持XMODEM,YMODEM,FAX协议的串口通信软件包的下一个:基于TAPI应用的通信应用
💻 C
📖 第 1 页 / 共 4 页
字号:
	mytapi.bLineaddresscapsalloced = TRUE;
	// set structure size
	mytapi.pLineaddresscaps->dwTotalSize = sizeof(LINEADDRESSCAPS);

	// check each address supported by the line device for one 
	// that allows calls to be answered
	i = 0;
	do {
		// get information into structure
		lrc = lineGetAddressCaps(mytapi.hTAPI, mytapi.dwLine, i,
					   mytapi.dwVersionToUse,
 					   0, mytapi.pLineaddresscaps);
		// bomb out if error
		if (lrc) {
			free (mytapi.pLineaddresscaps);
			mytapi.bLineaddresscapsalloced = FALSE;
			return lrc;
		}

		// make sure address can answer calls
		if (!(mytapi.pLineaddresscaps->dwCallFeatures & LINECALLFEATURE_ANSWER)) {
			i++;
			continue;
		}

		// reallocate and try again
		dwsize = mytapi.pLineaddresscaps->dwNeededSize;
		if (mytapi.pLineaddresscaps->dwTotalSize < dwsize) {
			free (mytapi.pLineaddresscaps);
			mytapi.bLineaddresscapsalloced = FALSE;
			mytapi.pLineaddresscaps = (LINEADDRESSCAPS *) calloc(1, dwsize);
			if (!mytapi.pLineaddresscaps)
				return LINEERR_NOMEM;
			mytapi.bLineaddresscapsalloced = TRUE;
			mytapi.pLineaddresscaps->dwTotalSize = dwsize;
			continue;
		}
		break;
	} while ((unsigned)i < mytapi.pLinedevcaps->dwNumAddresses);

	// if no address was found to answer calls, bomb out
	if ((unsigned)i == mytapi.pLinedevcaps->dwNumAddresses) {
		free (mytapi.pLineaddresscaps);
		mytapi.bLineaddresscapsalloced = FALSE;
		return -1;
	}

	// set address id to use
	mytapi.dwAddress = i;

	
	// now get address translate caps

	// if space already allocated for structure, free it up
	if (mytapi.bLinetranslatecapsalloced) {
		free (mytapi.pLinetranslatecaps);
		mytapi.bLinetranslatecapsalloced = FALSE;
	}

	// allocate memory for structure
	mytapi.pLinetranslatecaps = (LINETRANSLATECAPS *) calloc(1, sizeof(LINETRANSLATECAPS));
	if (!mytapi.pLinetranslatecaps)
		return LINEERR_NOMEM;
	mytapi.bLinetranslatecapsalloced = TRUE;
	// set structure size
	mytapi.pLinetranslatecaps->dwTotalSize = sizeof(LINETRANSLATECAPS);

	do {
		// get information into structure
		lrc = lineGetTranslateCaps(mytapi.hTAPI, 
								   mytapi.dwVersionToUse,
								   mytapi.pLinetranslatecaps);
		// bomb out if error
		if (lrc) {
			free (mytapi.pLinetranslatecaps);
			mytapi.bLinetranslatecapsalloced = FALSE;
			return lrc;
		}

		// reallocate and try again
		dwsize = mytapi.pLinetranslatecaps->dwNeededSize;
		if (mytapi.pLinetranslatecaps->dwTotalSize < dwsize) {
			free (mytapi.pLinetranslatecaps);
			mytapi.bLinetranslatecapsalloced = FALSE;
			mytapi.pLinetranslatecaps = (LINETRANSLATECAPS *) calloc(1, dwsize);
			if (!mytapi.pLinetranslatecaps)
				return LINEERR_NOMEM;
			mytapi.bLinetranslatecapsalloced = TRUE;
			mytapi.pLinetranslatecaps->dwTotalSize = dwsize;
			continue;
		}
		break;
	} while (TRUE);


	// get line device status
	lrc = mylineGetLineDevStatus();
	if (lrc)
		return lrc;

	// get address status
	lrc = mylineGetAddressStatus();
	if (lrc)
		return lrc;

	return lrc;

}

////////////////////////////////////////////////////////////////////
//	mylineGetAddressStatus - get LINEADDRESSSTATUS structure
////////////////////////////////////////////////////////////////////
LONG mylineGetAddressStatus()
{
	LONG lrc;
	DWORD dwsize;

	// if space already allocated for structure, free it up
	if (mytapi.bLineaddressstatusalloced) {
		free (mytapi.pLineaddressstatus);
		mytapi.bLineaddressstatusalloced = FALSE;
	}

	// allocate memory for structure
	mytapi.pLineaddressstatus = (LINEADDRESSSTATUS *) calloc(1, sizeof(LINEADDRESSSTATUS));
	if (!mytapi.pLineaddressstatus)
		return LINEERR_NOMEM;
	mytapi.bLineaddressstatusalloced = TRUE;
	// set structure size
	mytapi.pLineaddressstatus->dwTotalSize = sizeof(LINEADDRESSSTATUS);

	do {
		// get information into structure
		lrc = lineGetAddressStatus(mytapi.hLine, mytapi.dwAddress,
				mytapi.pLineaddressstatus);
		// bomb out if error
		if (lrc) {
			free (mytapi.pLineaddressstatus);
			mytapi.bLineaddressstatusalloced = FALSE;
			return lrc;
		}

		// reallocate and try again
		dwsize = mytapi.pLineaddressstatus->dwNeededSize;
		if (mytapi.pLineaddressstatus->dwTotalSize < dwsize) {
			free (mytapi.pLineaddressstatus);
			mytapi.bLineaddressstatusalloced = FALSE;
			mytapi.pLineaddressstatus = (LINEADDRESSSTATUS *) calloc(1, dwsize);
			if (!mytapi.pLineaddressstatus)
				return LINEERR_NOMEM;
			mytapi.bLineaddressstatusalloced = TRUE;
			mytapi.pLineaddressstatus->dwTotalSize = dwsize;
			continue;
		}
		break;
	} while (TRUE);

	return lrc;

}

////////////////////////////////////////////////////////////////////
//	mylineGetLineDevStatus - get LINEDEVSTATUS structure
////////////////////////////////////////////////////////////////////
LONG mylineGetLineDevStatus()
{
	LONG lrc;
	DWORD dwsize;

	// if space already allocated for structure, free it up
	if (mytapi.bLinedevstatusalloced) {
		free (mytapi.pLinedevstatus);
		mytapi.bLinedevstatusalloced = FALSE;
	}

	// allocate memory for structure
	mytapi.pLinedevstatus = (LINEDEVSTATUS *) calloc(1, sizeof(LINEDEVSTATUS));
	if (!mytapi.pLinedevstatus)
		return LINEERR_NOMEM;
	mytapi.bLinedevstatusalloced = TRUE;
	// set structure size
	mytapi.pLinedevstatus->dwTotalSize = sizeof(LINEDEVSTATUS);

	do {
		// get information into structure
		lrc = lineGetLineDevStatus(mytapi.hLine, mytapi.pLinedevstatus);
		// bomb out if error
		if (lrc) {
			free (mytapi.pLinedevstatus);
			mytapi.bLinedevstatusalloced = FALSE;
			return lrc;
		}

		// reallocate and try again
		dwsize = mytapi.pLinedevstatus->dwNeededSize;
		if (mytapi.pLinedevstatus->dwTotalSize < dwsize) {
			free (mytapi.pLinedevstatus);
			mytapi.bLinedevstatusalloced = FALSE;
			mytapi.pLinedevstatus = (LINEDEVSTATUS *) calloc(1, dwsize);
			if (!mytapi.pLinedevstatus)
				return LINEERR_NOMEM;
			mytapi.bLinedevstatusalloced = TRUE;
			mytapi.pLinedevstatus->dwTotalSize = dwsize;
			continue;
		}
		break;
	} while (TRUE);

	return lrc;
}

////////////////////////////////////////////////////////////////////
//	mylineGetCallStatus - get LINECALLSTATUS structure
////////////////////////////////////////////////////////////////////
LONG mylineGetCallStatus()
{
	LONG lrc;
	DWORD dwsize;

	// if space already allocated for structure, free it up
	if (mytapi.bLinecallstatusalloced) {
		free (mytapi.pLinecallstatus);
		mytapi.bLinecallstatusalloced = FALSE;
	}

	// allocate memory for structure
	mytapi.pLinecallstatus = (LINECALLSTATUS *) calloc(1, sizeof(LINECALLSTATUS));
	if (!mytapi.pLinecallstatus)
		return LINEERR_NOMEM;
	mytapi.bLinecallstatusalloced = TRUE;
	// set structure size
	mytapi.pLinecallstatus->dwTotalSize = sizeof(LINECALLSTATUS);

	do {
		// get information into structure
		lrc = lineGetCallStatus(mytapi.hCall, 
								mytapi.pLinecallstatus);
		// bomb out if error
		if (lrc) {
			free (mytapi.pLinecallstatus);
			mytapi.bLinecallstatusalloced = FALSE;
			return lrc;
		}

		// reallocate and try again
		dwsize = mytapi.pLinecallstatus->dwNeededSize;
		if (mytapi.pLinecallstatus->dwTotalSize < dwsize) {
			free (mytapi.pLinecallstatus);
			mytapi.bLinecallstatusalloced = FALSE;
			mytapi.pLinecallstatus = (LINECALLSTATUS *) calloc(1, dwsize);
			if (!mytapi.pLinecallstatus)
				return LINEERR_NOMEM;
			mytapi.bLinecallstatusalloced = TRUE;
			mytapi.pLinecallstatus->dwTotalSize = dwsize;
			continue;
		}
		break;
	} while (TRUE);

	return lrc;
}

////////////////////////////////////////////////////////////////////
//	mylineGetCallInfo - get LINECALLINFO structure
////////////////////////////////////////////////////////////////////
LONG mylineGetCallInfo()
{
	LONG lrc;
	DWORD dwsize;

	// if space already allocated for structure, free it up
	if (mytapi.bLinecallinfoalloced) {
		free (mytapi.pLinecallinfo);
		mytapi.bLinecallinfoalloced = FALSE;
	}

	// allocate memory for structure
	mytapi.pLinecallinfo = (LINECALLINFO *) calloc(1, sizeof(LINECALLINFO));
	if (!mytapi.pLinecallinfo)
		return LINEERR_NOMEM;
	mytapi.bLinecallinfoalloced = TRUE;
	// set structure size
	mytapi.pLinecallinfo->dwTotalSize = sizeof(LINECALLINFO);

	do {
		// get information into structure
		lrc = lineGetCallInfo(mytapi.hCall, mytapi.pLinecallinfo);
		// bomb out if error
		if (lrc) {
			free (mytapi.pLinecallinfo);
			mytapi.bLinecallinfoalloced = FALSE;
			return lrc;
		}

		// reallocate and try again
		dwsize = mytapi.pLinecallinfo->dwNeededSize;
		if (mytapi.pLinecallinfo->dwTotalSize < dwsize) {
			free (mytapi.pLinecallinfo);
			mytapi.bLinecallinfoalloced = FALSE;
			mytapi.pLinecallinfo = (LINECALLINFO *) calloc(1, dwsize);
			if (!mytapi.pLinecallinfo)
				return LINEERR_NOMEM;
			mytapi.bLinecallinfoalloced = TRUE;
			mytapi.pLinecallinfo->dwTotalSize = dwsize;
			continue;
		}
		break;
	} while (TRUE);

	return lrc;
}

////////////////////////////////////////////////////////////////////
//	telephonyShutdown - megafunction to close line, shut down 
//		telephony, close modem handle, restore serial device 
//		configuration, and free up various allocated structures.
////////////////////////////////////////////////////////////////////
void telephonyShutdown()
{
    DWORD id;

	// close line if open
	if (mytapi.bLineopen)
		lineClose(mytapi.hLine);
	// restore serial device configuration
	if (mytapi.bOlddevconfigalloced)
		lineSetDevConfig (mytapi.dwLine, 
						  (LPVOID)((LPBYTE)mytapi.pOlddevconfig +
						  mytapi.pOlddevconfig->dwStringOffset),
						  mytapi.pOlddevconfig->dwStringSize, 
						  "comm/datamodem");
	// shutdown the read thread if it is running
	if (mytapi.bReading) {
		/* kill the read thread */
		mytapi.bReading = FALSE;
		/* wait for thread to die...  */
		while (GetExitCodeThread(mytapi.hThread, &id)) {
			if (id == STILL_ACTIVE)
				continue;
			else
				break;
		} /* end while (no error reading thread exit code) */	
		CloseHandle (mytapi.hThread);
	}
	// close modem handle if open
	if (mytapi.bGotcommhandle)
		CloseHandle (mytapi.hComm);
	// shutdown tapi if initialized
	if (mytapi.bInitialized)
		lineShutdown(mytapi.hTAPI);

	// free up various structures if allocated
	if (mytapi.bLinedevcapsalloced)
		free (mytapi.pLinedevcaps);
	if (mytapi.bLineaddresscapsalloced)
		free (mytapi.pLineaddresscaps);
	if (mytapi.bLinetranslatecapsalloced)
		free (mytapi.pLinetranslatecaps);
	if (mytapi.bLinedevstatusalloced)
		free (mytapi.pLinedevstatus);
	if (mytapi.bLineaddressstatusalloced)
		free (mytapi.pLineaddressstatus);
	if (mytapi.bDevconfigalloced)
		free (mytapi.pDevconfig);
	if (mytapi.bOlddevconfigalloced)
		free (mytapi.pOlddevconfig);
	if (mytapi.bCommpropalloced)
		free (mytapi.pCommprop);
	if (mytapi.bCommconfigalloced)
		free (mytapi.pCommconfig);
	if (mytapi.bLinecallinfoalloced)
		free(mytapi.pLinecallinfo);
	if (mytapi.bLinecallstatusalloced)
		free(mytapi.pLinecallstatus);

	// set flags to indicate that the structures are no longer
	// allocated
	mytapi.bLinedevcapsalloced = FALSE;
	mytapi.bLineaddresscapsalloced = FALSE;
	mytapi.bLinetranslatecapsalloced = FALSE;
	mytapi.bLinedevstatusalloced = FALSE;
	mytapi.bLineaddressstatusalloced = FALSE;
	mytapi.bDevconfigalloced = FALSE;
	mytapi.bGotcommhandle = FALSE;
	mytapi.bCommpropalloced = FALSE;
	mytapi.bCommconfigalloced = FALSE;
	mytapi.bLineopen = FALSE;
	mytapi.bInitialized = FALSE;
	mytapi.bLinecallinfoalloced = FALSE;
	mytapi.bLinecallstatusalloced = FALSE;
	mytapi.bReading = FALSE;
	mytapi.bWaitForCall = FALSE;

} // end function (telephonyShutdown)

/////////////////////////////////////////////////////////////////////
//	telephonySettings - change telephony settings
////////////////////////////////////////////////////////////////////
LONG telephonySettings(HWND hwnd)
{
	LONG lrc;
	LPVARSTRING vs = calloc(1, mytapi.pDevconfig->dwTotalSize + 15000);

	// update our local settings structure
	lrc = mylineGetDevConfig();
	if (lrc)
		return lrc;

	vs->dwTotalSize = mytapi.pDevconfig->dwTotalSize + 15000;
	// display dialog to change telephony settings
	lrc = lineConfigDialogEdit(mytapi.dwLine, hwnd, 
							   "comm/datamodem",
							   (LPVOID)((LPBYTE)mytapi.pDevconfig + 
							   mytapi.pDevconfig->dwStringOffset), 
							   mytapi.pDevconfig->dwStringSize, 
							   vs);
	if (lrc) {
		free (vs);
		return lrc;
	}

	// make new settings active
	lrc = lineSetDevConfig (mytapi.dwLine, (LPVOID)((LPBYTE)vs + 
							vs->dwStringOffset),
							vs->dwStringSize, "comm/datamodem");
	if (lrc) {
		free (vs);
		return lrc;
	}

	free (vs);

	// update our local settings structure
	lrc = mylineGetDevConfig();

	return lrc;
}

////////////////////////////////////////////////////////////////////
//	LineCallBackProc - message function for TAPI events
////////////////////////////////////////////////////////////////////
/* callback function */
void FAR PASCAL LineCallBackProc(DWORD dwDevice,
		   DWORD dwMessage,DWORD dwInstance,DWORD dwParam1,
		   DWORD dwParam2,DWORD dwParam3)
{
	HMENU hMenu;
	DWORD id;
	LONG lrc;
	
	switch (dwMessage) {
		case LINE_ADDRESSSTATE:

			mylineGetAddressStatus();

			// update menus
		    hMenu = GetMenu(hTTYWnd);
			if (mytapi.pLineaddressstatus->dwAddressFeatures & LINEADDRFEATURE_MAKECALL)
		    	EnableMenuItem( hMenu, IDM_MAKECALL, MF_ENABLED | MF_BYCOMMAND ) ;
			else
		    	EnableMenuItem( hMenu, IDM_MAKECALL, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND ) ;
			
			switch (dwParam2) {
				case LINEADDRESSSTATE_OTHER:
					break;
				case LINEADDRESSSTATE_DEVSPECIFIC:
					break;
				case LINEADDRESSSTATE_INUSEZERO:
					break;
				case LINEADDRESSSTATE_INUSEONE:
					break;
				case LINEADDRESSSTATE_INUSEMANY:
					break;
				case LINEADDRESSSTATE_NUMCALLS:
					break;
				case LINEADDRESSSTATE_FORWARD:
					break;
				case LINEADDRESSSTATE_TERMINALS:
					break;
				default:
					break;
			} //end switch
			break;
		case LINE_CALLINFO:

			mylineGetCallInfo();
			switch (dwParam1) {
				case LINECALLINFOSTATE_OTHER:
					break;
				case LINECALLINFOSTATE_DEVSPECIFIC:
					break;
				case LINECALLINFOSTATE_BEARERMODE:
					break;
				case LINECALLINFOSTATE_RATE:
					break;
				case LINECALLINFOSTATE_MEDIAMODE:
					break;
				case LINECALLINFOSTATE_APPSPECIFIC:
					break;
				case LINECALLINFOSTATE_CALLID:
					break;
				case LINECALLINFOSTATE_RELATEDCALLID:
					break;
				case LINECALLINFOSTATE_ORIGIN:
					break;
				case LINECALLINFOSTATE_REASON:
					break;
				case LINECALLINFOSTATE_COMPLETIONID:
					break;
				case LINECALLINFOSTATE_NUMOWNERINCR:
					break;
				case LINECALLINFOSTATE_NUMOWNERDECR:
					break;
				case LINECALLINFOSTATE_NUMMONITORS:
					break;
				case LINECALLINFOSTATE_TRUNK:
					break;
				case LINECALLINFOSTATE_CALLERID:
					break;
				case LINECALLINFOSTATE_CALLEDID:
					break;
				case LINECALLINFOSTATE_CONNECTEDID:
					break;
				case LINECALLINFOSTATE_REDIRECTIONID:
					break;
				case LINECALLINFOSTATE_REDIRECTINGID:
					break;
				case LINECALLINFOSTATE_DISPLAY:
					break;
				case LINECALLINFOSTATE_USERUSERINFO:
					break;
				case LINECALLINFOSTATE_HIGHLEVELCOMP:
					break;
				case LINECALLINFOSTATE_LOWLEVELCOMP:
					break;
				case LINECALLINFOSTATE_CHARGINGINFO:
					break;
				case LINECALLINFOSTATE_TERMINAL:
					break;
				case LINECALLINFOSTATE_DIALPARAMS:
					break;
				case LINECALLINFOSTATE_MONITORMODES:
					break;
				default:
					break;
			} //end switch
			break;
		case LINE_CALLSTATE:

			
			switch (dwParam3) {
				case LINECALLPRIVILEGE_MONITOR:
					
					break;
				case LINECALLPRIVILEGE_OWNER:

					// save call handle
					mytapi.hCall = (HCALL)dwDevice;

					// update local call information
					mylineGetCallStatus();
					mylineGetCallInfo();

					// update menus
				    hMenu = GetMenu(hTTYWnd);
					// enable drop call?
				    if (mytapi.pLinecallstatus->dwCallFeatures & LINECALLFEATURE_DROP)
				    	EnableMenuItem( hMenu, IDM_DISCONNECT, MF_ENABLED | MF_BYCOMMAND ) ;
					else
				    	EnableMenuItem( hMenu, IDM_DISCONNECT, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND ) ;
					// enable answer call?
				    if (mytapi.pLinecallstatus->dwCallFeatures & LINECALLFEATURE_ANSWER)
				    	EnableMenuItem( hMenu, IDM_ANSWER, MF_ENABLED | MF_BYCOMMAND ) ;
					else

⌨️ 快捷键说明

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