?? tapicode.c
字號:
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright 1995 - 1998 Microsoft Corporation. All Rights Reserved.
//
// MODULE: TapiCode.c
//
// PURPOSE: Handles all the TAPI routines for TapiComm.
//
//
// EXPORTED FUNCTIONS: These functions are for use by other modules.
//
// InitializeTAPI - Initialize this app with TAPI.
// ShutdownTAPI - Shutdown this app from TAPI.
// DialCall - Dial a Call.
// HangupCall - Hangup an existing Call.
// PostHangupCall - Posts a HangupCall message to the main window.
//
// INTERNAL FUNCTIONS: These functions are for this module only.
//
// DialCallInParts - Actually Dial the call.
//
// lineCallbackFunc - TAPI callback for async messages.
//
// CheckAndReAllocBuffer - Helper function for I_ wrappers functions.
//
// I_lineNegotiateAPIVersion - Wrapper for lineNegotiateAPIVersion.
// I_lineGetDevCaps - Wrapper for lineGetDevCaps.
// I_lineGetAddressStatus - Wrapper for lineGetAddressStatus.
// I_lineTranslateAddress - Wrapper for lineTranslateAddress.
// I_lineGetCallStatus - Wrapper for lineGetCallStatus.
// I_lineGetAddressCaps - Wrapper for lineGetAddressCaps.
//
// WaitForCallState - Resynchronize by Waiting for a CallState.
// WaitForReply - Resynchronize by Waiting for a LINE_REPLY.
//
// DoLineReply - Handle asynchronous LINE_REPLY.
// DoLineClose - Handle asynchronous LINE_CLOSE.
// DoLineDevState - Handle asynchronous LINE_LINEDEVSTATE.
// DoLineCallState - Handle asynchronous LINE_CALLSTATE.
// DoLineCreate - Handle asynchronous LINE_CREATE.
//
// HandleLineErr - Handler for most LINEERR errors.
//
// HandleIniFileCorrupt - LINEERR handler for INIFILECORRUPT.
// HandleNoDriver - LINEERR handler for NODRIVER.
// HandleNoDevicesInstalled - LINEERR handler for NODEVICE.
// HandleReInit - LINEERR handler for REINIT.
// HandleNoMultipleInstance - LINEERR handler for NOMULTIPLEINSTANCE.
// HandleNoMem - LINEERR handler for NOMEM.
// HandleOperationFailed - LINEERR handler for OPERATIONFAILED.
// HandleResourceUnavail - LINEERR handler for RESOURCEUNAVAIL.
//
// LaunchModemControlPanelAdd - Launches the Modem Control Panel.
//
// WarningBox - Warn user if a line in use is removed.
//
// GetAddressToDial - Launches a GetAddressToDial dialog.
// DialDialogProc - Dialog Proc for the GetAddressToDial API.
//
// I_lineNegotiateLegacyAPIVersion - Wrapper to negoitiate with legacy TSPs
// VerifyUsableLine - Verify that a line device is usable
// FillTAPILine - Fill a combobox with TAPI Device names
// VerifyAndWarnUsableLine - Verify and warn if a line device is usable
// FillCountryCodeList - Fill a combobox with country codes
// FillLocationInfo - Fill a combobox with current TAPI locations
// UseDialingRules - Enable/Disable dialing rules controls
// DisplayPhoneNumber - Create and display a valid phone number
// PreConfigureDevice - Preconfigure a device line
#include <tapi.h>
#include <windows.h>
#include <string.h>
#include "globals.h"
#include "TapiInfo.h"
#include "TapiCode.h"
#include "CommCode.h"
#include "resource.h"
#include "statbar.h"
#include "toolbar.h"
// All TAPI line functions return 0 for SUCCESS, so define it.
#define SUCCESS 0
// Possible return error for resynchronization functions.
#define WAITERR_WAITABORTED 1
#define WAITERR_WAITTIMEDOUT 2
// Reasons why a line device might not be usable by TapiComm.
#define LINENOTUSEABLE_ERROR 1
#define LINENOTUSEABLE_NOVOICE 2
#define LINENOTUSEABLE_NODATAMODEM 3
#define LINENOTUSEABLE_NOMAKECALL 4
#define LINENOTUSEABLE_ALLOCATED 5
#define LINENOTUSEABLE_INUSE 6
#define LINENOTUSEABLE_NOCOMMDATAMODEM 7
// Constant used in WaitForCallState when any new
// callstate message is acceptable.
#define I_LINECALLSTATE_ANY 0
// Wait up to 30 seconds for an async completion.
#define WAITTIMEOUT 30000
// TAPI version that this sample is designed to use.
#define SAMPLE_TAPI_VERSION 0x00010004
// Global TAPI variables.
HWND g_hWndMainWindow = NULL; // Apps main window.
HWND g_hDlgParentWindow = NULL; // This will be the parent of all dialogs.
HLINEAPP g_hLineApp = (HLINEAPP)((ULONG_PTR)NULL);
DWORD g_dwNumDevs = 0;
// Global variable that holds the handle to a TAPI dialog
// that needs to be dismissed if line conditions change.
HWND g_hDialog = NULL;
// Global flags to prevent re-entrancy problems.
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 = (HCALL)((ULONG_PTR)NULL);
HLINE g_hLine = (HLINE)((ULONG_PTR)NULL);
DWORD g_dwDeviceID = 0;
DWORD g_dwAPIVersion = 0;
DWORD g_dwCallState = 0;
char g_szDisplayableAddress[1024] = "";
char g_szDialableAddress[1024] = "";
BOOL g_bConnected = FALSE;
LPVOID g_lpDeviceConfig = NULL;
DWORD g_dwSizeDeviceConfig;
// Global variables to allow us to do various waits.
BOOL g_bReplyRecieved;
DWORD g_dwRequestedID;
long g_lAsyncReply;
BOOL g_bCallStateReceived;
// Structures needed to handle special non-dialable characters.
#define g_sizeofNonDialable (sizeof(g_sNonDialable)/sizeof(g_sNonDialable[0]))
typedef struct {
LONG lError;
DWORD dwDevCapFlag;
LPSTR szToken;
LPSTR szMsg;
} NONDIALTOKENS;
NONDIALTOKENS g_sNonDialable[] = {
{LINEERR_DIALBILLING, LINEDEVCAPFLAGS_DIALBILLING, "$",
"Wait for the credit card bong tone" },
{LINEERR_DIALDIALTONE, LINEDEVCAPFLAGS_DIALDIALTONE, "W",
"Wait for the second dial tone" },
{LINEERR_DIALDIALTONE, LINEDEVCAPFLAGS_DIALDIALTONE, "w",
"Wait for the second dial tone" },
{LINEERR_DIALQUIET, LINEDEVCAPFLAGS_DIALQUIET, "@",
"Wait for the remote end to answer" },
{LINEERR_DIALPROMPT, 0, "?",
"Press OK when you are ready to continue dialing"},
};
// "Dial" dialog controls and their associated help page IDs
DWORD g_adwSampleMenuHelpIDs[] =
{
IDC_COUNTRYCODE , IDC_COUNTRYCODE,
IDC_STATICCOUNTRYCODE , IDC_COUNTRYCODE,
IDC_AREACODE , IDC_AREACODE,
IDC_STATICAREACODE , IDC_AREACODE,
IDC_PHONENUMBER , IDC_PHONENUMBER,
IDC_STATICPHONENUMBER , IDC_PHONENUMBER,
IDC_USEDIALINGRULES , IDC_USEDIALINGRULES,
IDC_LOCATION , IDC_LOCATION,
IDC_STATICLOCATION , IDC_LOCATION,
IDC_CALLINGCARD , IDC_CALLINGCARD,
IDC_STATICCALLINGCARD , IDC_CALLINGCARD,
IDC_DIALINGPROPERTIES , IDC_DIALINGPROPERTIES,
IDC_TAPILINE , IDC_TAPILINE,
IDC_STATICTAPILINE , IDC_TAPILINE,
IDC_CONFIGURELINE , IDC_CONFIGURELINE,
IDC_CANONICALNUMBER , IDC_CANONICALNUMBER,
IDC_STATICCANONICAL , IDC_CANONICALNUMBER,
IDC_DIALABLENUMBER , IDC_DIALABLENUMBER,
IDC_STATICDIALABLE , IDC_DIALABLENUMBER,
IDC_DISPLAYABLENUMBER , IDC_DISPLAYABLENUMBER,
IDC_STATICDISPLAYABLE , IDC_DISPLAYABLENUMBER,
IDC_DIAL , IDC_DIAL,
IDC_LINEICON , IDC_LINEICON,
//IDC_STATICWHERETODIAL , IDC_STATICWHERETODIAL,
//IDC_STATICHOWTODIAL , IDC_STATICHOWTODIAL,
//IDC_STATICCONNECTUSING , IDC_STATICCONNECTUSING,
//IDC_STATICPHONENUMBER , IDC_PHONENUMBER,
0,0
};
//**************************************************
// Prototypes for functions used only in this module.
//**************************************************
BOOL DialCallInParts (
LPLINEDEVCAPS lpLineDevCaps,
LPCSTR lpszAddress,
LPCSTR lpszDisplayableAddress);
LPLINECALLPARAMS CreateCallParams (
LPLINECALLPARAMS lpCallParams,
LPCSTR lpszDisplayableAddress);
DWORD I_lineNegotiateAPIVersion (
DWORD dwDeviceID);
LPVOID CheckAndReAllocBuffer(
LPVOID lpBuffer, size_t sizeBufferMinimum,
LPCSTR szApiPhrase);
LPLINEDEVCAPS I_lineGetDevCaps (
LPLINEDEVCAPS lpLineDevCaps,
DWORD dwDeviceID,
DWORD dwAPIVersion);
LPLINEADDRESSSTATUS I_lineGetAddressStatus (
LPLINEADDRESSSTATUS lpLineAddressStatus,
HLINE hLine,
DWORD dwAddressID);
LPLINETRANSLATEOUTPUT I_lineTranslateAddress (
LPLINETRANSLATEOUTPUT lpLineTranslateOutput,
DWORD dwDeviceID,
DWORD dwAPIVersion,
LPCSTR lpszDialAddress);
LPLINECALLSTATUS I_lineGetCallStatus (
LPLINECALLSTATUS lpLineCallStatus,
HCALL hCall);
LPLINEADDRESSCAPS I_lineGetAddressCaps (
LPLINEADDRESSCAPS lpLineAddressCaps,
DWORD dwDeviceID, DWORD dwAddressID,
DWORD dwAPIVersion, DWORD dwExtVersion);
long WaitForCallState (DWORD dwNewCallState);
long WaitForReply (long lRequestID);
void CALLBACK lineCallbackFunc(
DWORD hDevice, DWORD dwMsg, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
void DoLineReply(
DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
void DoLineClose(
DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
void DoLineDevState(
DWORD dwDevice, DWORD dwsg, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
void DoLineCallState(
DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
void DoLineCreate(
DWORD dwDevice, DWORD dwMessage, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
BOOL HandleLineErr(long lLineErr);
BOOL HandleIniFileCorrupt();
BOOL HandleNoDriver();
BOOL HandleNoDevicesInstalled();
BOOL HandleReInit();
BOOL HandleNoMultipleInstance();
BOOL HandleNoMem();
BOOL HandleOperationFailed();
BOOL HandleResourceUnavail();
BOOL LaunchModemControlPanelAdd();
void WarningBox(LPCSTR lpszMessage);
INT_PTR CALLBACK DialDialogProc(
HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL GetAddressToDial();
DWORD I_lineNegotiateLegacyAPIVersion(DWORD dwDeviceID);
long VerifyUsableLine(DWORD dwDeviceID);
void FillTAPILine(HWND hwndDlg);
BOOL VerifyAndWarnUsableLine(HWND hwndDlg);
void FillCountryCodeList(HWND hwndDlg, DWORD dwDefaultCountryID);
void FillLocationInfo(HWND hwndDlg, LPSTR lpszCurrentLocation,
LPDWORD lpdwCountryID, LPSTR lpszAreaCode);
void UseDialingRules(HWND hwndDlg);
void DisplayPhoneNumber(HWND hwndDlg);
void PreConfigureDevice(HWND hwndDlg, DWORD dwDeviceID);
//**************************************************
// Entry points from the UI
//**************************************************
//
// FUNCTION: BOOL InitializeTAPI(HWND)
//
// PURPOSE: Initializes TAPI
//
// PARAMETERS:
// hWndParent - Window to use as parent of any dialogs.
//
// RETURN VALUE:
// Always returns 0 - command handled.
//
// COMMENTS:
//
// This is the API that initializes the app with TAPI.
// If NULL is passed for the hWndParent, then its assumed
// that re-initialization has occurred and the previous hWnd
// is used.
//
//
BOOL InitializeTAPI(HWND hWndParent)
{
long lReturn;
BOOL bTryReInit = TRUE;
// If we're already initialized, then initialization succeeds.
if (g_hLineApp)
return TRUE;
// If we're in the middle of initializing, then fail, we're not done.
if (g_bInitializing)
return FALSE;
g_bInitializing = TRUE;
// Initialize TAPI
do
{
lReturn = lineInitialize(&g_hLineApp, hInst,
lineCallbackFunc, "TapiComm", &g_dwNumDevs);
// 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
{
MessageBox(g_hDlgParentWindow,
"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."
,"Warning",MB_OK);
g_bInitializing = FALSE;
return FALSE;
}
}
if (lReturn == LINEERR_NODEVICE)
{
if (HandleNoDevicesInstalled())
continue;
else
{
OutputDebugString("No devices installed.\n");
g_bInitializing = FALSE;
return FALSE;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -