亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? commcode.c

?? The TapiComm sample uses both the Telephony API and the Win32 Communications API to demonstrate one
?? C
?? 第 1 頁 / 共 3 頁
字號:
// 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: CommCode.c
//
//  PURPOSE: Handles all the COMM routines for TapiComm.
//
//  EXPORTED FUNCTIONS:  These functions are for use by other modules.
//    StartComm        - Start communications.  
//    StopComm         - Stop Communications.
//    WriteCommString  - Write a string to the Comm port.
//
//  INTERNAL FUNCTION:  These functions are for this module only.
//    CloseReadThread  - Close the Read Thread.
//    CloseWriteThread - Close the Write Thread.
//
//    StartReadThreadProc    - Starting function for the Read Thread.
//    StartWriteThreadProc   - Starting function for the Write Thread.
//
//    - Write Thread helper function
//    HandleWriteData - Actually does the work of writing a string to comm.
//
//    - Read Thread helper functions
//    SetupReadEvent  - Sets up the overlapped ReadFile
//    HandleReadEvent - Gets the results from the overlapped ReadFile
//    HandleReadData  - Handles data returned from the ReadFile
//
//    HandleCommEvent - Sets up the CommEvent event.
//    SetupCommEvent  - Handles CommEvent events (if they occur).
//


#include <windows.h>
#include <string.h>
#include "TapiCode.h"
#include "CommCode.h"
#include "globals.h"
#include "TapiInfo.h"
#include "EditCtls.h"

// 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

//*****************************************
// Global variables.
//*****************************************

HANDLE g_hCommFile = NULL;

DWORD g_dwReadThreadID  = 0;
DWORD g_dwWriteThreadID = 0;
HANDLE g_hReadThread  = NULL;
HANDLE g_hWriteThread = NULL;

HANDLE g_hCloseEvent = NULL;

//*****************************************
// CommCode internal Function Prototypes
//*****************************************

void CloseReadThread();
void CloseWriteThread();

DWORD WINAPI StartReadThreadProc(LPVOID lpvParam);
DWORD WINAPI StartWriteThreadProc(LPVOID lpvParam);


BOOL HandleWriteData(LPOVERLAPPED lpOverlappedWrite,
        LPCSTR lpszStringToWrite, DWORD dwNumberOfBytesToWrite);


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 HandleCommEvent(LPOVERLAPPED lpOverlappedCommEvent,
        LPDWORD lpfdwEvtMask, BOOL fRetrieveEvent);
BOOL SetupCommEvent(LPOVERLAPPED lpOverlappedCommEvent,
        LPDWORD lpfdwEvtMask);



//*****************************************
// Functions exported for use by other modules
//*****************************************



//
//  FUNCTION: StartComm(HANDLE)
//
//  PURPOSE: Starts communications over the comm port.
//
//  PARAMETERS:
//    hNewCommFile - This is the COMM File handle to communicate with.
//                   This handle is obtained from TAPI.
//
//  RETURN VALUE:
//    TRUE if able to setup the communications.
//
//  COMMENTS:
//
//    StartComm makes sure there isn't communication in progress already,
//    the hNewCommFile is valid, and all the threads can be created.  It
//    also configures the hNewCommFile for the appropriate COMM settings.
//
//    If StartComm fails for any reason, it's up to the calling application
//    to close the Comm file handle.
//
//

BOOL StartComm(HANDLE hNewCommFile)
{
    // Is this a valid comm handle?
    if (GetFileType(hNewCommFile) != FILE_TYPE_CHAR)
    {
        OutputDebugString("File handle is not a comm handle.\n");
        return FALSE;
    }

    // Are we already doing comm?
    if (g_hCommFile != NULL)
    {
        OutputDebugString("Already have a comm file open\n");
        return FALSE;
    }

    // Its ok to continue.

    g_hCommFile = hNewCommFile;

    // Setting and querying the comm port configurations.

    { // Configure the comm settings.
        COMMTIMEOUTS commtimeouts;
        DCB dcb;
        COMMPROP commprop;
        DWORD fdwEvtMask;

        // These are here just so you can set a breakpoint
        // and see what the comm settings are.  Most Comm settings
        // are already set through TAPI.
        GetCommState(hNewCommFile, &dcb);
        GetCommProperties(hNewCommFile, &commprop);
        GetCommMask(g_hCommFile, &fdwEvtMask);
        GetCommTimeouts(g_hCommFile, &commtimeouts);


        // The CommTimeout numbers will very likely change if you are
        // coding to meet some kind of specification where
        // you need to reply within a certain amount of time after
        // recieving the last byte.  However,  If 1/4th of a second
        // goes by between recieving two characters, its a good 
        // indication that the transmitting end has finished, even
        // assuming a 1200 baud modem.

        commtimeouts.ReadIntervalTimeout         = 250;
        commtimeouts.ReadTotalTimeoutMultiplier  = 0;
        commtimeouts.ReadTotalTimeoutConstant    = 0;
        commtimeouts.WriteTotalTimeoutMultiplier = 0;
        commtimeouts.WriteTotalTimeoutConstant   = 0;

        SetCommTimeouts(g_hCommFile, &commtimeouts);

        // fAbortOnError is the only DCB dependancy in TapiComm.
        // Can't guarentee that the SP will set this to what we expect.
        dcb.fAbortOnError = FALSE;
        SetCommState(hNewCommFile, &dcb);
    }

    // Create the event that will signal the threads to close.
    g_hCloseEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    if (g_hCloseEvent == NULL)
    {
        OutputDebugLastError(GetLastError(), "Unable to CreateEvent: ");
        g_hCommFile = NULL;
        return FALSE;
    }

    // Create the Read thread.
    g_hReadThread =
        CreateThread(NULL, 0, StartReadThreadProc, 0, 0, &g_dwReadThreadID);
        
    if (g_hReadThread == NULL)
    {
        OutputDebugLastError(GetLastError(),"Unable to create Read thread");

        g_dwReadThreadID = 0;
        g_hCommFile = 0;
        return FALSE;
    }
    
    // Comm threads should to have a higher base priority than the UI thread.
    // If they don't, then any temporary priority boost the UI thread gains
    // could cause the COMM threads to loose data.
    SetThreadPriority(g_hReadThread, THREAD_PRIORITY_HIGHEST);

    // Create the Write thread.
    g_hWriteThread = 
        CreateThread(NULL, 0, StartWriteThreadProc, 0, 0, &g_dwWriteThreadID);
        
    if (g_hWriteThread == NULL)
    {
        OutputDebugLastError(GetLastError(),"Unable to create Write thread");

        CloseReadThread();
        g_dwWriteThreadID = 0;
        g_hCommFile = 0;
        return FALSE;
    }
    
    SetThreadPriority(g_hWriteThread, THREAD_PRIORITY_ABOVE_NORMAL);

    // Everything was created ok.  Ready to go!
    return TRUE;
}


//
//  FUNCTION: StopComm
//
//  PURPOSE: Stop and end all communication threads.
//
//  PARAMETERS:
//    none
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
//    Tries to gracefully signal all communication threads to
//    close, but terminates them if it has to.
//
//

void StopComm()
{
    // No need to continue if we're not communicating.
    if (g_hCommFile == NULL)
        return;

    OutputDebugString("Stopping the Comm\n");

    // Close the threads.
    CloseReadThread();
    CloseWriteThread();

    // Not needed anymore.
    CloseHandle(g_hCloseEvent);

    // Now close the comm port handle.
    CloseHandle(g_hCommFile);
    g_hCommFile = NULL;
}


//
//  FUNCTION: WriteCommString(LPCSTR, DWORD)
//
//  PURPOSE: Send a String to the Write Thread to be written to the Comm.
//
//  PARAMETERS:
//    pszStringToWrite     - String to Write to Comm port. 
//    nSizeofStringToWrite - length of pszStringToWrite.
//
//  RETURN VALUE:
//    Returns TRUE if the PostMessage is successful.
//    Returns FALSE if PostMessage fails or Write thread doesn't exist.
//
//  COMMENTS:
//
//    This is a wrapper function so that other modules don't care that
//    Comm writing is done via PostMessage to a Write thread.  Note that
//    using PostMessage speeds up response to the UI (very little delay to
//    'write' a string) and provides a natural buffer if the comm is slow
//    (ie:  the messages just pile up in the message queue).
//
//    Note that it is assumed that pszStringToWrite is allocated with
//    LocalAlloc, and that if WriteCommString succeeds, its the job of the
//    Write thread to LocalFree it.  If WriteCommString fails, then its
//    the job of the calling function to free the string.
//
//

BOOL WriteCommString(LPCSTR lpszStringToWrite, DWORD dwSizeofStringToWrite)
{
    if (g_hWriteThread)
    {
        if (PostThreadMessage(g_dwWriteThreadID, PWM_COMMWRITE, 
                (WPARAM) dwSizeofStringToWrite, (LPARAM) lpszStringToWrite))
        {
            return TRUE;
        }
        else
            OutputDebugString("Failed to Post to Write thread.\n");
    }
    else
        OutputDebugString("Write thread not created\n");

    return FALSE;
}



//*****************************************
// The rest of the functions are intended for use
// only within the CommCode module.
//*****************************************



//
//  FUNCTION: CloseReadThread
//
//  PURPOSE: Close the Read Thread.
//
//  PARAMETERS:
//    none
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
//    Closes the Read thread by signaling the CloseEvent.
//    Purges any outstanding reads on the comm port.
//
//    Note that terminating a thread leaks memory (read the docs).
//    Besides the normal leak incurred, there is an event object
//    that doesn't get closed.  This isn't worth worrying about 
//    since it shouldn't happen anyway.
//
//

void CloseReadThread()
{
    // If it exists...
    if (g_hReadThread)
    {
        OutputDebugString("Closing Read Thread\n");

        // Signal the event to close the worker threads.
        SetEvent(g_hCloseEvent);

        // Purge all outstanding reads
        PurgeComm(g_hCommFile, PURGE_RXABORT | PURGE_RXCLEAR);

        // Wait 10 seconds for it to exit.  Shouldn't happen.
        if (WaitForSingleObject(g_hReadThread, 10000) == WAIT_TIMEOUT)
        {
            OutputDebugString("Read thread not exiting.  Terminating it.\n");

            TerminateThread(g_hReadThread, 0);

            // The ReadThread cleans up these itself if it terminates
            // normally.
            CloseHandle(g_hReadThread);
            g_hReadThread = 0;
            g_dwReadThreadID = 0;
        }
    }
}


//
//  FUNCTION: CloseWriteThread
//
//  PURPOSE: Closes the Write Thread.
//
//  PARAMETERS:
//    none
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
//    Closes the write thread by signaling the CloseEvent.
//    Purges any outstanding writes on the comm port.
//
//    Note that terminating a thread leaks memory (read the docs).
//    Besides the normal leak incurred, there is an event object
//    that doesn't get closed.  This isn't worth worrying about 
//    since it shouldn't happen anyway.
//
//

void CloseWriteThread()
{
    // If it exists...
    if (g_hWriteThread)
    {
        OutputDebugString("Closing Write Thread\n");

        // Signal the event to close the worker threads.
        SetEvent(g_hCloseEvent);

        // Purge all outstanding writes.
        PurgeComm(g_hCommFile, PURGE_TXABORT | PURGE_TXCLEAR);

        // Wait 10 seconds for it to exit.  Shouldn't happen.
        if (WaitForSingleObject(g_hWriteThread, 10000) == WAIT_TIMEOUT)
        {
            OutputDebugString("Write thread not exiting.  Terminating it.\n");

            TerminateThread(g_hWriteThread, 0);

            // The WriteThread cleans up these itself if it terminates
            // normally.
            CloseHandle(g_hWriteThread);
            g_hWriteThread = 0;
            g_dwWriteThreadID = 0;

        }
    }
}


//
//  FUNCTION: StartWriteThreadProc(LPVOID)
//
//  PURPOSE: The starting point for the Write thread.
//
//  PARAMETERS:
//    lpvParam - unused.
//
//  RETURN VALUE:
//    DWORD - unused.
//
//  COMMENTS:
//
//    The Write thread uses a PeekMessage loop to wait for a string to write,
//    and when it gets one, it writes it to the Comm port.  If the CloseEvent
//    object is signaled, then it exits.  The use of messages to tell the

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久久久久综合| 视频一区二区中文字幕| 玉米视频成人免费看| 青青国产91久久久久久| www.久久精品| 国产色产综合产在线视频| 亚洲国产日韩综合久久精品| 国产美女精品人人做人人爽| 欧美电影在线免费观看| 国产精品看片你懂得| 久草在线在线精品观看| 欧美日韩日日骚| 亚洲男人的天堂在线aⅴ视频| 国产揄拍国内精品对白| 日韩一区二区在线播放| 一区二区三区四区在线| 成人手机在线视频| 26uuu亚洲婷婷狠狠天堂| 日本中文一区二区三区| 欧美性大战xxxxx久久久| 1区2区3区欧美| 成人午夜伦理影院| 久久久久久久久久久久久夜| 精品一区二区在线播放| 日韩一区二区三区电影在线观看| 亚洲国产综合视频在线观看| 91日韩在线专区| 中文字幕日韩欧美一区二区三区| 国产成人免费视频精品含羞草妖精| 制服丝袜日韩国产| 午夜精品一区二区三区免费视频| 欧美视频在线一区二区三区| 亚洲精品乱码久久久久久久久| 成人动漫一区二区三区| 国产精品日日摸夜夜摸av| youjizz国产精品| 国产精品福利影院| 91亚洲永久精品| 亚洲午夜激情av| 欧美精品免费视频| 免费成人你懂的| 久久久久久一二三区| 国产成人亚洲综合色影视| 中文成人综合网| 91碰在线视频| 亚洲成a人v欧美综合天堂下载 | 中文字幕五月欧美| 91农村精品一区二区在线| 亚洲精品日韩综合观看成人91| 91香蕉视频在线| 亚洲成人av一区| 欧美成人a在线| 成人国产精品视频| 一区二区三区精品在线观看| 欧美日韩一级大片网址| 麻豆高清免费国产一区| 欧美精品一区二区三区一线天视频| 久久精品久久99精品久久| 久久亚洲二区三区| 成人黄色777网| 五月天丁香久久| 久久久综合精品| 色天使久久综合网天天| 青青草国产成人99久久| 国产亚洲成aⅴ人片在线观看| 一本久道久久综合中文字幕| 奇米777欧美一区二区| 欧美激情艳妇裸体舞| 欧美人牲a欧美精品| 国产精品一卡二卡在线观看| 午夜精品久久久久久久99樱桃 | 91免费视频观看| 秋霞午夜av一区二区三区| 国产日本欧洲亚洲| 在线观看免费视频综合| 狠狠狠色丁香婷婷综合激情| 一区二区三区欧美在线观看| 久久久亚洲精品石原莉奈| 91福利在线看| 国内精品久久久久影院色| 尤物av一区二区| 久久久久久97三级| 3atv在线一区二区三区| av在线播放一区二区三区| 麻豆极品一区二区三区| 亚洲宅男天堂在线观看无病毒| 国产视频在线观看一区二区三区 | 国产日产精品1区| 制服视频三区第一页精品| 成人av小说网| 九九热在线视频观看这里只有精品| 亚洲免费av在线| 中文字幕巨乱亚洲| 欧美精品一区二区三区在线| 欧美久久婷婷综合色| 91在线丨porny丨国产| 国产伦精品一区二区三区免费迷 | 五月天久久比比资源色| 亚洲三级小视频| 国产欧美日韩三级| 精品国产免费视频| 欧美丰满美乳xxx高潮www| 在线免费亚洲电影| 成人av资源在线观看| 成人性生交大合| 国产伦精品一区二区三区免费 | 精品剧情在线观看| 欧美一区二区视频在线观看| 欧美亚洲高清一区二区三区不卡| av电影在线观看完整版一区二区| 国产精品一区二区你懂的| 精品一区二区av| 国产精品123区| 激情文学综合网| 国产一区二区看久久| 国产激情视频一区二区在线观看| 韩国毛片一区二区三区| 国产一区中文字幕| 国产一区二区三区四| 国产不卡一区视频| 岛国一区二区在线观看| www.日韩在线| 色8久久人人97超碰香蕉987| 欧美性生活大片视频| 51精品国自产在线| 制服丝袜亚洲播放| 精品久久久久久久人人人人传媒| 欧美成人r级一区二区三区| 久久综合精品国产一区二区三区| 精品国产伦一区二区三区观看方式 | 91视频免费播放| 欧美视频在线不卡| 日韩欧美色电影| 久久午夜电影网| 亚洲天堂2014| 天天射综合影视| 国产一区二区在线观看视频| 不卡一区二区中文字幕| 在线观看www91| 欧美一区二区三区四区五区| 精品国产乱码久久久久久闺蜜| 国产日韩精品一区二区三区| 成人欧美一区二区三区小说| 午夜精品免费在线观看| 国内精品视频一区二区三区八戒| 成人高清在线视频| 欧美色图一区二区三区| 亚洲精品一线二线三线无人区| 中文字幕电影一区| 丝袜亚洲另类欧美| 成人综合婷婷国产精品久久免费| 欧美影院一区二区三区| 精品国产一区二区三区四区四| 成人免费在线视频观看| 美女脱光内衣内裤视频久久网站| 不卡高清视频专区| 91精品国产综合久久蜜臀| 中文字幕av在线一区二区三区| 亚洲一区二区三区四区在线| 国产一区在线不卡| 欧美日韩你懂得| 国产精品久久久久久久久图文区| 日韩成人精品视频| 91女人视频在线观看| 久久先锋资源网| 婷婷综合久久一区二区三区| 成人性生交大片免费看中文网站| 欧美高清性hdvideosex| 中文字幕一区不卡| 国精产品一区一区三区mba视频| 在线一区二区视频| 日本一区二区三级电影在线观看 | 一区二区三区美女| www.亚洲免费av| 精品99一区二区| 日日嗨av一区二区三区四区| 99国内精品久久| 国产欧美久久久精品影院| 秋霞电影网一区二区| 欧美日韩国产免费| 亚洲精品乱码久久久久久黑人| 成人美女视频在线观看| 日韩免费福利电影在线观看| 亚洲亚洲人成综合网络| 91女厕偷拍女厕偷拍高清| 中文字幕免费一区| 国产精品66部| 久久影院视频免费| 久久精品99久久久| 欧美一区二区三区在| 日韩一区欧美二区| 欧美色偷偷大香| 亚洲18女电影在线观看| 在线观看免费视频综合| 亚洲免费观看高清完整| 成a人片亚洲日本久久| 国产精品久久久久久一区二区三区| 国产成人精品免费看| 国产视频亚洲色图| 成人的网站免费观看|