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

📄 tapiconn._h

📁 串口调试助手的源代码
💻 _H
字号:
// Modify by FangHong, 1997

#ifndef _TAPICONNECTION__HPP
#define _TAPICONNECTION__HPP

// This is the message posted to the WriteThread
// When we have something to write.
#define PWM_COMMWRITE   WM_USER+1

// Default size of the Input Buffer used by this code.
#define INPUTBUFFERSIZE 2048

// All TAPI line functions return 0 for SUCCESS, so define it.
#define TAPISUCCESS 0

// TAPI version that this sample is designed to use.
#define SAMPLE_TAPI_VERSION 0x00010004

// Early TAPI version
#define EARLY_TAPI_VERSION 0x00010003


//
// TAPIUTILS.H
//
#include <tapi.h>

class	CTapiConnection
{
public:
// this area contains the protected members of the CTapiConnection class
	DWORD	m_dwNumDevs;	// the number of line devices available
	DWORD	m_dwDeviceID;	// the device ID
	static DWORD	m_dwRequestedID;
	static LONG	m_lAsyncReply;

	// BOOLEANS to handle reentrancy
	BOOL	m_bShuttingDown;
	BOOL	m_bStoppingCall;
	BOOL	m_bInitializing;
	static BOOL	m_bReplyRecieved;
    
	static BOOL	m_bTapiInUse;	// whether TAPI is in use or not
	BOOL	m_bInitialized;	// whether TAPI has been initialized

	static CTapiConnection*	m_this;


public:
	// this area contains the public members of the CTapiConnection class
	HLINEAPP	m_hLineApp;	// the usage handle of this application for TAPI
	HCALL	m_hCall;	// handle to the call
	HLINE	m_hLine;	// handle to the open line
	DWORD	m_dwAPIVersion;	// the API version
	char	m_szPhoneNumber[64];	// the phone number to call

	DWORD	m_dwSizeDeviceConfig;

public:
	BOOL	StartComm(HANDLE  hNewCommFile);
	void	StopComm();
	BOOL	WriteCommString(LPCSTR lpszStringToWrite, DWORD dwSizeofStringToWrite);
	void	CloseReadThread();
	void	CloseWriteThread();

	static DWORD	StartWriteThreadProc(LPVOID  lpvParam);
	BOOL	HandleWriteData(LPOVERLAPPED  lpOverlappedWrite,
		LPCSTR  lpszStringToWrite, DWORD  dwNumberOfBytesToWrite);
	static DWORD	StartReadThreadProc(LPVOID  lpvParam);
	BOOL	SetupReadEvent(LPOVERLAPPED  lpOverlappedRead,
		LPSTR  lpszInputBuffer, DWORD  dwSizeofBuffer,
		LPDWORD  lpnNumberOfBytesRead);

	BOOL	HandleReadEvent(LPOVERLAPPED  lpOverlappedRead,
		LPSTR  lpszInputBuffer, DWORD  dwSizeofBuffer,
		LPDWORD  lpnNumberOfBytesRead);

	BOOL	HandleReadData(LPCSTR lpszInputBuffer, DWORD  dwSizeofBuffer);

	BOOL	SetupCommEvent(LPOVERLAPPED  lpOverlappedCommEvent,
		LPDWORD  lpfdwEvtMask);

	BOOL	HandleCommEvent(LPOVERLAPPED  lpOverlappedCommEvent,
		LPDWORD  lpfdwEvtMask, BOOL  bRetrieveEvent);

	void	PostHangupCall(void);
	BOOL	HandleNoDevicesInstalled(void);
	BOOL	LaunchModemControlPanelAdd(void);

public:
	// Comm Ctrls !
	BOOL	m_bConnected;

	CWnd*	m_pNotifyWnd;
	HANDLE	m_hCommFile;
	DWORD	m_dwReadThreadID;
	DWORD	m_dwWriteThreadID;
	HANDLE	m_hReadThread;
	HANDLE	m_hWriteThread;
	HANDLE	m_hCloseEvent;

public:
	// Here is where I put the protected (internal) functions
	BOOL	ShutdownTAPI();
	BOOL	HandleLineErr(long lLineErr);
	LPLINEDEVCAPS	GetDeviceLine(DWORD *dwAPIVersion, LPLINEDEVCAPS lpLineDevCaps);
	LPLINEDEVCAPS	I_lineGetDevCaps(LPLINEDEVCAPS lpLineDevCaps,
		DWORD dwDeviceID, DWORD dwAPIVersion);
	static LPVOID	CheckAndReAllocBuffer(LPVOID lpBuffer, size_t sizeBufferMinimum);
	LPLINEADDRESSCAPS	I_lineGetAddressCaps(LPLINEADDRESSCAPS lpLineAddressCaps,
		DWORD dwDeviceID, DWORD dwAddressID,DWORD dwAPIVersion, DWORD dwExtVersion);
//	BOOL	MakeTheCall(LPLINEDEVCAPS lpLineDevCaps,LPCSTR lpszAddress);
	LPLINECALLPARAMS	CreateCallParams(LPLINECALLPARAMS lpCallParams, LPCSTR lpszDisplayableAddress);
	long	WaitForReply(long  lRequestID);
	static void	DoLineCallState(DWORD  dwDevice, DWORD  dwMessage, DWORD  dwCallbackInstance,
		DWORD  dwParam1, DWORD  dwParam2, DWORD  dwParam3);

	DWORD	I_lineNegotiateLegacyAPIVersion(DWORD  dwDeviceID);
	DWORD	I_lineNegotiateAPIVersion(DWORD  dwDeviceID);
	LPLINEADDRESSSTATUS	I_lineGetAddressStatus(
		LPLINEADDRESSSTATUS lpLineAddressStatus,
		HLINE hLine, DWORD dwAddressID);

	BOOL	DialCallInParts(LPLINEDEVCAPS lpLineDevCaps,
		LPCSTR lpszAddress, LPCSTR lpszDisplayableAddress);

	BOOL	HandleNoMem(void);

	LPLINECALLSTATUS	I_lineGetCallStatus(
		LPLINECALLSTATUS lpLineCallStatus, HCALL hCall);
	long	WaitForCallState(DWORD  dwDesiredCallState);

private:
	// This section is for private functions

public:
	// Public functions
	CTapiConnection();   
	~CTapiConnection();
	BOOL	Create(LPCTSTR  szPhoneNumber = NULL);
	BOOL	DialCall(LPCTSTR  szPhoneNumber = NULL);
	BOOL	HangupCall();
	static void CALLBACK	lineCallbackFunc(
		DWORD  dwDevice, DWORD  dwMsg, DWORD  dwCallbackInstance,
		DWORD  dwParam1, DWORD  dwParam2, DWORD  dwParam3);

	static void	DoLineReply(
		DWORD  dwDevice, DWORD  dwMessage, DWORD  dwCallbackInstance,
		DWORD  dwParam1, DWORD  dwParam2, DWORD  dwParam3);

	static void	DoLineClose(
		DWORD  dwDevice, DWORD  dwMessage, DWORD  dwCallbackInstance,
		DWORD  dwParam1, DWORD  dwParam2, DWORD  dwParam3);

	static void	DoLineDevState(
		DWORD  dwDevice, DWORD  dwMessage, DWORD  dwCallbackInstance,
		DWORD  dwParam1, DWORD  dwParam2, DWORD  dwParam3);

	void	WarningBox(LPCSTR  lpszMessage);

	static void	DoLineCreate(
		DWORD  dwDevice, DWORD  dwMessage, DWORD  dwCallbackInstance,
		DWORD  dwParam1, DWORD  dwParam2, DWORD  dwParam3);
};


// 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 (C) 1995  Microsoft Corporation.  All Rights Reserved.
//
// PURPOSE:
//    Contains public declarations for the TapiInfo module.
//

#define OutputDebugLineError(lLineError, pszPrefix) \
    OutputDebugLineErrorFileLine(lLineError, pszPrefix,\
        __FILE__, __LINE__)

#define OutputDebugLastError(dwLastError, pszPrefix) \
    OutputDebugLastErrorFileLine(dwLastError, pszPrefix,\
        __FILE__, __LINE__)

void OutputDebugLineErrorFileLine(
    long lLineError, LPSTR szPrefix, 
    LPSTR szFileName, DWORD nLineNumber);

void OutputDebugLastErrorFileLine(
    DWORD dwLastError, LPSTR szPrefix, 
    LPSTR szFileName, DWORD nLineNumber);

void OutputDebugLineCallback(
    DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance, 
    DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);

void __cdecl OutputDebugPrintf(LPCSTR lpszFormat, ...);

LPSTR FormatLineError(long  dwLineError,
    LPSTR szOutputBuffer, DWORD dwSizeofOutputBuffer);

LPSTR FormatLastError(DWORD dwLastError,
    LPSTR szOutputBuffer, DWORD dwSizeofOutputBuffer);

LPSTR FormatLineCallback(LPSTR pszOutputBuffer,
    DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance, 
    DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);


#endif	// _TAPICONNECTION__HPP

⌨️ 快捷键说明

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