亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
成人中文字幕在线| 日本精品一区二区三区高清| 国产盗摄女厕一区二区三区| 成人午夜私人影院| 欧美剧情片在线观看| 2020国产精品| 午夜精品福利视频网站| 国产成人精品影视| 欧美日韩久久久一区| 中文一区在线播放| 美国三级日本三级久久99 | 亚洲第一综合色| 国产一区欧美二区| 欧美伦理电影网| 国产精品入口麻豆九色| 久久国产精品无码网站| 在线观看日产精品| 亚洲国产精品高清| 免费高清成人在线| 欧美日韩性生活| 日韩一区日韩二区| 成人午夜大片免费观看| 欧美一级电影网站| 亚洲一二三区视频在线观看| av欧美精品.com| 国产日产亚洲精品系列| 美女看a上一区| 欧美麻豆精品久久久久久| 亚洲视频在线观看三级| 成人一区二区三区视频 | va亚洲va日韩不卡在线观看| 欧美xfplay| 免费在线观看成人| 欧美久久一二区| 亚洲狼人国产精品| 一本一本大道香蕉久在线精品| 国产性天天综合网| 国产精品白丝jk黑袜喷水| 日韩精品一区二区三区在线| 免费一级片91| 欧美一卡2卡三卡4卡5免费| 成人精品一区二区三区四区 | 成人av综合在线| 久久久久久**毛片大全| 国产一区在线观看视频| 欧美r级在线观看| 狠狠色狠狠色综合系列| 亚洲精品一区二区三区影院| 国产综合一区二区| 国产三级欧美三级日产三级99 | 欧美日韩成人综合| 爽好久久久欧美精品| 日韩一级大片在线观看| 欧美a一区二区| 亚洲精品一区二区三区影院 | 欧美老年两性高潮| 免费成人av在线| 欧美成人性福生活免费看| 狠狠色2019综合网| 国产三级精品视频| 99久久久免费精品国产一区二区| 国产精品久久久久久久久免费丝袜| 成人精品视频一区二区三区尤物| 亚洲欧美视频一区| 欧美精品18+| 久久99精品久久久久久久久久久久| 久久久国产精华| 91麻豆国产在线观看| 日韩一区精品字幕| 久久美女高清视频| 91美女在线视频| 日韩黄色片在线观看| 精品久久久久久久久久久院品网| 色吧成人激情小说| 蜜桃av一区二区| 国产精品成人在线观看| 欧美人xxxx| 国产资源在线一区| 自拍偷拍欧美激情| 欧美一区二区视频在线观看| 国产69精品久久99不卡| 一区二区激情小说| 久久久精品天堂| 色国产精品一区在线观看| 久久99精品一区二区三区三区| 中文字幕乱码亚洲精品一区| 欧美嫩在线观看| 国产ts人妖一区二区| 午夜欧美一区二区三区在线播放| 国产亚洲精品bt天堂精选| 欧美日韩综合色| 国产aⅴ综合色| 丝袜亚洲精品中文字幕一区| 国产精品美女一区二区在线观看| 欧美一区二区精品久久911| av资源站一区| 国产一区免费电影| 日韩电影一区二区三区四区| 自拍偷在线精品自拍偷无码专区| 精品国产不卡一区二区三区| 欧美日韩一区二区在线观看视频 | 日韩黄色免费电影| 亚洲宅男天堂在线观看无病毒| 久久精品亚洲一区二区三区浴池| 欧美日韩日日夜夜| 日本高清无吗v一区| 岛国一区二区在线观看| 老色鬼精品视频在线观看播放| 亚洲一区二区三区四区在线免费观看| 国产欧美精品国产国产专区| 日韩一区二区三区免费观看| 欧美日韩精品系列| 一本色道a无线码一区v| 国产91丝袜在线播放| 精品午夜久久福利影院 | 色乱码一区二区三区88| 99在线精品观看| 播五月开心婷婷综合| 国产馆精品极品| 国产伦精品一区二区三区免费迷 | 国产精品久久久久久久午夜片| 欧美精品一区二区不卡| 日韩一区二区三区在线视频| 欧美精品在线观看播放| 欧美精品久久一区二区三区 | 岛国av在线一区| 国产福利一区二区三区视频在线| 精品一区二区在线播放| 久久99久久久欧美国产| 久久疯狂做爰流白浆xx| 久久激情综合网| 国产综合色在线视频区| 国产超碰在线一区| 99精品欧美一区二区蜜桃免费 | 性做久久久久久免费观看欧美| 亚洲精品va在线观看| 一区av在线播放| 亚洲成人av电影| 蜜桃视频在线一区| 国产美女一区二区| av电影在线观看不卡| 91激情在线视频| 欧美电影影音先锋| 日韩美女视频一区二区在线观看| 久久综合色播五月| 亚洲欧洲日韩av| 亚洲第一av色| 九色porny丨国产精品| 成人免费看视频| 欧美综合一区二区三区| 欧美一区二区三区四区视频| 久久午夜羞羞影院免费观看| 国产精品久久久久久久久图文区 | 亚洲v中文字幕| 精品一区二区久久久| fc2成人免费人成在线观看播放 | 国产91露脸合集magnet| 91丨porny丨最新| 欧美一区二区三区在线观看视频| 26uuu久久综合| 亚洲精品乱码久久久久久日本蜜臀| 午夜视频在线观看一区| 精品写真视频在线观看| 色综合久久六月婷婷中文字幕| 56国语精品自产拍在线观看| 亚洲国产成人自拍| 天天综合色天天综合色h| 国产xxx精品视频大全| 欧美放荡的少妇| 中文字幕视频一区| 美女久久久精品| 欧美亚洲禁片免费| 国产日本欧洲亚洲| 午夜久久久久久久久久一区二区| 丰满少妇在线播放bd日韩电影| 欧美日韩精品三区| 国产精品国产三级国产普通话99 | 在线日韩av片| 久久久久国产精品免费免费搜索| 一区二区三区高清在线| 国产精品一区二区无线| 欧美日韩一级二级| ㊣最新国产の精品bt伙计久久| 蜜臀av性久久久久蜜臀av麻豆 | 欧美在线免费观看亚洲| 久久九九国产精品| 蜜臀久久久99精品久久久久久| 91婷婷韩国欧美一区二区| 久久久午夜精品理论片中文字幕| 亚洲成人激情综合网| 一本大道久久精品懂色aⅴ| 久久久夜色精品亚洲| 青青草精品视频| 欧美婷婷六月丁香综合色| 中文无字幕一区二区三区| 免费观看日韩av| 欧美群妇大交群的观看方式| 一区二区激情小说| 99re6这里只有精品视频在线观看| 2021久久国产精品不只是精品|