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

📄 phone.c

📁 使用tapi实现的用语音modem进行接电话并播放wav文件的程序
💻 C
字号:

#include "comdial.h"
#include "resource.h"


extern MYTAPI mytapi;
extern HWND hTTYWnd;

/////////////////////////////////////////////////////////////////////
//	myphoneInitialize - mega function to retrieve all 
//		configuration information needed for initializing the 
//		phone device.
////////////////////////////////////////////////////////////////////
int myphoneInitialize(HWND hWnd, HINSTANCE hInst)
{
	LONG lrc;
	PHONEEXTENSIONID extensions;

	// initialize application use of phone device
	while (phoneInitialize(&mytapi.hTAPIPhone, hInst, 
			mytapi.PhoneCallbackProc = (LINECALLBACK)MakeProcInstance((FARPROC)PhoneCallBackProc, hInst),
			"TAPIProcess", &mytapi.dwNumPhones) == PHONEERR_REINIT) {
		Sleep (5);			// sleep for five seconds
		if (MessageBox(hWnd, "Telephony system is reinitializing - Click \
Cancel to abort", "Error", MB_RETRYCANCEL) ==IDCANCEL)
			goto done;
	} // end while (TAPI reinitializing)

	// bool indicates lineInitialize called successfully
	mytapi.bPhoneInitialized = TRUE;

	// negotiate version of TAPI to use
	lrc = phoneNegotiateAPIVersion(mytapi.hTAPIPhone, 0, WIN95TAPIVERSION, 
			WIN95TAPIVERSION, &mytapi.dwPhoneVersionToUse, &extensions);
	if (lrc)
		goto done;
	
	// get phone device caps
	lrc = myphoneGetDevCaps ();
	if (lrc)
		goto done;

	return 0;

done:
	// error!  clean up and return error code

	myphoneShutdown();

	return lrc;

} //end function (myphoneInitialize)
/////////////////////////////////////////////////////////////////////
//	myphoneOpen - open phone device
////////////////////////////////////////////////////////////////////
int myphoneOpen(HWND hWnd, HINSTANCE hInst)
{
	LONG lrc;

	// open the phone device
	lrc = phoneOpen(mytapi.hTAPIPhone, mytapi.dwPhone, &mytapi.hPhone,
					mytapi.dwPhoneVersionToUse, 0, 0, 
					PHONEPRIVILEGE_OWNER);
	if (lrc)
		goto done;

	// bool indicates lineOpen called successfully
	mytapi.bPhoneopen = TRUE;

	// success

	return 0;

done:
	// error!  clean up and return error code

	myphoneShutdown();

	return lrc;

} // end procedure (telephony initialize)
/////////////////////////////////////////////////////////////////////
//	myphoneGetDevCaps - get PHONECAPS structure
////////////////////////////////////////////////////////////////////
LONG myphoneGetDevCaps()
{
	LONG lrc;	
	DWORD dwsize;

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

	// allocate memory for structure
	mytapi.pPhonedevcaps = (PHONECAPS *) calloc(1, sizeof(PHONECAPS));
	if (!mytapi.pPhonedevcaps)
		return PHONEERR_NOMEM;
	mytapi.bPhonedevcapsalloced = TRUE;
	// set structure size
	mytapi.pPhonedevcaps->dwTotalSize = sizeof(PHONECAPS);
	do {
		// get information into structure
		lrc = phoneGetDevCaps(mytapi.hTAPIPhone, mytapi.dwPhone, mytapi.dwPhoneVersionToUse,
					   0, mytapi.pPhonedevcaps);
		// bomb out if error
		if (lrc) {
			free (mytapi.pPhonedevcaps);
			mytapi.bPhonedevcapsalloced = FALSE;
			return lrc;
		}
		dwsize = mytapi.pPhonedevcaps->dwNeededSize;
		// reallocate and try again
		if (mytapi.pPhonedevcaps->dwTotalSize < dwsize) {
			free (mytapi.pPhonedevcaps);
			mytapi.bPhonedevcapsalloced = FALSE;
			mytapi.pPhonedevcaps = (PHONECAPS *) calloc(1, dwsize);
			if (!mytapi.pPhonedevcaps)
				return PHONEERR_NOMEM;
			mytapi.bPhonedevcapsalloced = TRUE;
			mytapi.pPhonedevcaps->dwTotalSize = dwsize;
			continue;
		}
		break;
	} while (TRUE);

	return lrc;
}
/////////////////////////////////////////////////////////////////////
//	phoneShutdown - mega functions to shut down use of phone device
////////////////////////////////////////////////////////////////////
void myphoneShutdown()
{

	// close line if open
	if (mytapi.bPhoneopen)
		phoneClose(mytapi.hPhone);
	if (mytapi.bPhoneInitialized)
		phoneShutdown(mytapi.hTAPIPhone);

	// free up various structures if allocated
	if (mytapi.bPhonedevcapsalloced)
		free (mytapi.pPhonedevcaps);
	// set flags to indicate that the structures are no longer
	// allocated
	mytapi.bLinedevcapsalloced = FALSE;
	mytapi.bPhoneopen = FALSE;
	mytapi.bPhoneInitialized = FALSE;

} // end function (phoneShutdown)
/////////////////////////////////////////////////////////////////////
//	PhoneCallBackProc - message function for TAPI phone events
////////////////////////////////////////////////////////////////////
void FAR PASCAL PhoneCallBackProc(DWORD dwDevice,DWORD dwMessage,
           DWORD dwInstance,DWORD dwParam1,DWORD dwParam2,DWORD dwParam3)
{



}


⌨️ 快捷键说明

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