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

📄 win32_modem.h

📁 基于单片机的 snmp协议解析的一些原代码 给有用的 同行
💻 H
字号:
//---------------------------------------------------------------------------
#ifndef Win32_modemH
#define Win32_modemH
//#include <string>
#define CURRENT_TAPI_VERSION 0x00010004
#define TAPI_CURRENT_VERSION CURRENT_TAPI_VERSION
#define SAMPLE_TAPI_VERSION CURRENT_TAPI_VERSION
#include <tapi.h>
#include "resource.h"
#include "SP_Exception.h"
#include "UtilTime.h"
#include "io_port.h"
#include "api.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
#define g_sizeofNonDialable (sizeof(g_sNonDialable)/sizeof(g_sNonDialable[0]))
//#define TAPI_CURRENT_VERSION 0x00010004
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
};
const char *INVALID_COMM_NAME = "BAD_COMM";
//---------------------------------------------------------------------------
class Win32_Modem
{
	public:
		Win32_Modem();
		~Win32_Modem();
        bool Init();
		bool GetModemConfig(COMMCONFIG *modemConfig);
		bool SetModemConfig(COMMCONFIG modemConfig);
        bool GetModemProperties(COMMPROP *modemProp);
        void SetBaudRate(long theBaudRate);
        void SetPhoneNumber(char * thePhoneNumber);
        void GetBaudRate(long *theBaudRate);
        void GetPhoneNumber(char ** thePhoneNumber);
        void GetPhoneNumber(string &thePhoneNumber);
        bool CheckForDataAccess();
        bool Connect();
		bool InitializeTAPI(HWND hParentWnd);
		bool DialCall();
		void PostHangupCall();
        HWND GetMainWindow();   // Apps main window.
        void SetMainWindow(HWND theMainWindow);
		bool WaitForConnection(char ** connectName);
		void Open(char *theCommName, short theBaudRate, short theDataBits, char theParity, short theStopBits);
    	void Open(char *theCommName);
		void Close();
		void WriteBuffer(unsigned char *theBuffer, long theBufferLength);
	//	void ReadBuffer(unsigned char *theBuffer, long *theBytesRead, char *theOpenTime, char *theCloseTime, bool newRead);
		bool SetupReadEvent(OVERLAPPED *overlappedRead, unsigned char *theBuffer, long theBufferSize, unsigned long *theBytesRead, char *theOpenTime, char *theCloseTime);
		bool HandleReadEvent(OVERLAPPED *overlapped, unsigned char *theBuffer, long theBufferSize, unsigned long *theBytesRead, char *theOpenTime, char *theCloseTime);
        void SetTimeouts();
	private :
     	HANDLE Comm;
		COMMPROP modemCommProperties;
		COMMCONFIG modemConfigSettings;
        long baudRate;
        bool connectState;
        bool isInited;
        string phoneNumber;
        HLINEAPP tapiHandle;
        HANDLE tapiEventHandle;
        HLINE phLine;
        HCALL phCall;
        HANDLE commFile;
		static bool ShutdownTAPI();
		static void StopComm();
		static LPVOID CheckAndReAllocBuffer(LPVOID lpBuffer, size_t sizeBufferMinimum,LPCSTR szApiPhrase);
		static void CALLBACK lineCallbackFunc(DWORD hDevice, DWORD dwMsg, DWORD dwCallbackInstance,DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
		static void DoLineReply(DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance, DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
		static void DoLineClose(DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance,DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
		static void DoLineDevState(DWORD dwDevice, DWORD dwsg, DWORD dwCallbackInstance,DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
		static void DoLineCallState(DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance,DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
		static void DoLineCreate(DWORD dwDevice, DWORD dwMessage, DWORD dwCallbackInstance, DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
		static bool HandleLineErr(long lLineErr);
		static bool HandleIniFileCorrupt();
		static bool HandleNoDriver();
		static bool HandleNoDevicesInstalled();
		static bool HandleReInit();
		static bool HandleNoMultipleInstance();
		static bool HandleNoMem();
		static bool HandleOperationFailed();
		static bool HandleResourceUnavail();
		static bool LaunchModemControlPanelAdd();
		static void WarningBox(LPCSTR lpszMessage);
		static bool CALLBACK DialDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
		static bool GetAddressToDial();
		static DWORD I_lineNegotiateLegacyAPIVersion(DWORD dwDeviceID);
		static long VerifyUsableLine(DWORD dwDeviceID);
		static void FillTAPILine(HWND hwndDlg);
		static bool VerifyAndWarnUsableLine(HWND hwndDlg);
		static void FillCountryCodeList(HWND hwndDlg, DWORD dwDefaultCountryID);
		static void FillLocationInfo(HWND hwndDlg, LPSTR lpszCurrentLocation,LPDWORD lpdwCountryID, LPSTR lpszAreaCode);
		static void UseDialingRules(HWND hwndDlg);
		static void DisplayPhoneNumber(HWND hwndDlg);
		static void PreConfigureDevice(HWND hwndDlg, DWORD dwDeviceID);
		static bool DialCallInParts (LPLINEDEVCAPS lpLineDevCaps,LPCSTR lpszAddress, LPCSTR lpszDisplayableAddress);
		static LPLINECALLPARAMS CreateCallParams (LPLINECALLPARAMS lpCallParams,LPCSTR lpszDisplayableAddress);
		static DWORD I_lineNegotiateAPIVersion (DWORD dwDeviceID);
		static LPLINEDEVCAPS I_lineGetDevCaps (LPLINEDEVCAPS lpLineDevCaps, DWORD dwDeviceID, DWORD dwAPIVersion);
		static LPLINEADDRESSSTATUS I_lineGetAddressStatus (LPLINEADDRESSSTATUS lpLineAddressStatus,HLINE hLine, DWORD dwAddressID);
		static LPLINETRANSLATEOUTPUT I_lineTranslateAddress (LPLINETRANSLATEOUTPUT lpLineTranslateOutput,DWORD dwDeviceID, DWORD dwAPIVersion, LPCSTR lpszDialAddress);
		static LPLINECALLSTATUS I_lineGetCallStatus (LPLINECALLSTATUS lpLineCallStatus, HCALL hCall);
		static LPLINEADDRESSCAPS I_lineGetAddressCaps (LPLINEADDRESSCAPS lpLineAddressCaps,DWORD dwDeviceID, DWORD dwAddressID, DWORD dwAPIVersion, DWORD dwExtVersion);
		static bool HangupCall();
		static long WaitForCallState (DWORD dwNewCallState);
		static long WaitForReply (long lRequestID);
};
#endif

⌨️ 快捷键说明

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