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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? commcode.c

?? The TapiComm sample uses both the Telephony API and the Win32 Communications API to demonstrate one
?? C
?? 第 1 頁 / 共 3 頁
字號:
//    Write thread what to write provides a natural desynchronization between
//    the UI and the Write thread.
//
//

DWORD WINAPI StartWriteThreadProc(LPVOID lpvParam)
{
    MSG msg;
    DWORD dwHandleSignaled;

    // Needed for overlapped I/O.
    OVERLAPPED overlappedWrite = {0, 0, 0, 0, NULL};

    overlappedWrite.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
    if (overlappedWrite.hEvent == NULL)
    {
        OutputDebugLastError(GetLastError(), "Unable to CreateEvent: ");
        PostHangupCall();
        goto EndWriteThread;
    }

    // This is the main loop.  Loop until we break out.
    while (TRUE)
    {
        if (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            // If there are no messages pending, wait for a message or 
            // the CloseEvent.
            dwHandleSignaled = 
                MsgWaitForMultipleObjects(1, &g_hCloseEvent, FALSE,
                    INFINITE, QS_ALLINPUT);

            switch(dwHandleSignaled)
            {
                case WAIT_OBJECT_0:     // CloseEvent signaled!
                {
                    // Time to exit.
                    goto EndWriteThread;
                }

                case WAIT_OBJECT_0 + 1: // New message was received.
                {
                    // Get the message that woke us up by looping again.
                    continue;
                }

                case WAIT_FAILED:       // Wait failed.  Shouldn't happen.
                {
                    OutputDebugLastError(GetLastError(),"Write WAIT_FAILED: ");
                    PostHangupCall();
                    goto EndWriteThread;
                }

                default:                // This case should never occur.
                {
                    OutputDebugPrintf("Unexpected Wait return value '%lx'",
                        dwHandleSignaled);
                    PostHangupCall();
                    goto EndWriteThread;
                }

            }
        }

        // Make sure the CloseEvent isn't signaled while retrieving messages.
        if (WAIT_TIMEOUT != WaitForSingleObject(g_hCloseEvent,0))
            goto EndWriteThread;

        // Process the message.

        // This could happen if a dialog is created on this thread.
        // This doesn't occur in this sample, but might if modified.
        if (msg.hwnd != NULL)
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);

            continue;
        }

        // Handle the message.
        switch(msg.message)
        {
            case PWM_COMMWRITE:  // New string to write to Comm port.
            {
                OutputDebugString("Writing to comm port\n");

                // Write the string to the comm port.  HandleWriteData
                // does not return until the whole string has been written,
                // an error occurs or until the CloseEvent is signaled.
                if (!HandleWriteData(&overlappedWrite,
                        (LPSTR) msg.lParam, (DWORD) msg.wParam))
                {
                    // If it failed, either we got a signal to end or there
                    // really was a failure.

                    LocalFree((HLOCAL) msg.lParam); 
                    goto EndWriteThread;
                }

                // Data was sent in a LocalAlloc()d buffer.  Must free it.
                LocalFree((HLOCAL) msg.lParam); 
                break;
            }
    

            // What other messages could the thread get?
            default:
            {
                char Output[256];
    
                wsprintf(Output,
                    "Unexpected message posted to Write thread: %ui\n",
                    msg.message );
                    
                OutputDebugString(Output);
                break;
            }
        } // End of switch(message)

    } // End of main loop.

    // Thats the end.  Now clean up.
  EndWriteThread:

    OutputDebugString("Write thread shutting down\n");

    PurgeComm(g_hCommFile, PURGE_TXABORT | PURGE_TXCLEAR);

    CloseHandle(overlappedWrite.hEvent);

    g_dwWriteThreadID = 0;
    CloseHandle(g_hWriteThread);
    g_hWriteThread = 0;

    return 0;
}


//
//  FUNCTION: HandleWriteData(LPOVERLAPPED, LPCSTR, DWORD)
//
//  PURPOSE: Writes a given string to the comm file handle.
//
//  PARAMETERS:
//    lpOverlappedWrite      - Overlapped structure to use in WriteFile
//    lpszStringToWrite      - String to write.
//    dwNumberOfBytesToWrite - Length of String to write.
//
//  RETURN VALUE:
//    TRUE if all bytes were written.  False if there was a failure to
//    write the whole string.
//
//  COMMENTS:
//
//    This function is a helper function for the Write Thread.  It
//    is this call that actually writes a string to the comm file.
//    Note that this call blocks and waits for the Write to complete
//    or for the CloseEvent object to signal that the thread should end.
//    Another possible reason for returning FALSE is if the comm port
//    is closed by the service provider.
//
//

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

    DWORD dwNumberOfBytesWritten = 0;
    DWORD dwWhereToStartWriting = 0; // Start at the beginning.

    DWORD dwHandleSignaled;
    HANDLE HandlesToWaitFor[2];

    HandlesToWaitFor[0] = g_hCloseEvent;
    HandlesToWaitFor[1] = lpOverlappedWrite -> hEvent;

    // Keep looping until all characters have been written.
    do
    {
        // Start the overlapped I/O.
        if (!WriteFile(g_hCommFile, 
                &lpszStringToWrite[ dwWhereToStartWriting ], 
                dwNumberOfBytesToWrite, &dwNumberOfBytesWritten,
                lpOverlappedWrite))
        {
            // WriteFile failed.  Expected; lets handle it.
            dwLastError = GetLastError();

            // Its possible for this error to occur if the 
            // service provider has closed the port.  Time to end.
            if (dwLastError == ERROR_INVALID_HANDLE)
            {
                OutputDebugString("ERROR_INVALID_HANDLE, "
                    "Likely that the Service Provider has closed the port.\n");
                return FALSE;
            }

            // Unexpected error.  No idea what.
            if (dwLastError != ERROR_IO_PENDING)
            {
                OutputDebugLastError(dwLastError,
                    "Error to writing to CommFile");
                
                OutputDebugString("Closing TAPI\n");
                PostHangupCall();
                return FALSE;
            }

            // This is the expected ERROR_IO_PENDING case.


            // Wait for either overlapped I/O completion,
            // or for the CloseEvent to get signaled.
            dwHandleSignaled = 
                WaitForMultipleObjects(2, HandlesToWaitFor, 
                    FALSE, INFINITE);

            switch(dwHandleSignaled)
            {
                case WAIT_OBJECT_0:     // CloseEvent signaled!
                {
                    // Time to exit.
                    return FALSE;
                }

                case WAIT_OBJECT_0 + 1: // Wait finished.
                {
                    // Time to get the results of the WriteFile
                    break;
                }

                case WAIT_FAILED: // Wait failed.  Shouldn't happen.
                {
                    OutputDebugLastError(GetLastError(), 
                        "Write WAIT_FAILED: ");
                    PostHangupCall();
                    return FALSE;
                }

                default: // This case should never occur.
                {
                    OutputDebugPrintf(
                        "Unexpected Wait return value '%lx'",
                        dwHandleSignaled);
                    PostHangupCall();
                    return FALSE;
                }
            }

            if (!GetOverlappedResult(g_hCommFile,
                     lpOverlappedWrite,
                     &dwNumberOfBytesWritten, TRUE))
            {
                dwLastError = GetLastError();

                // Its possible for this error to occur if the 
                // service provider has closed the port.
                if (dwLastError == ERROR_INVALID_HANDLE)
                {
                    OutputDebugString("ERROR_INVALID_HANDLE, "
                        "Likely that the Service Provider has closed the port.\n");
                    return FALSE;
                }

                // No idea what could cause another error.
                OutputDebugLastError(dwLastError,
                    "Error writing to CommFile while waiting");
                OutputDebugString("Closing TAPI\n");
                PostHangupCall();
                return FALSE;
            }
        }

        // Some data was written.  Make sure it all got written.

        dwNumberOfBytesToWrite -= dwNumberOfBytesWritten;
        dwWhereToStartWriting += dwNumberOfBytesWritten;
    }
    while(dwNumberOfBytesToWrite > 0);  // Write the whole thing!

    // Wrote the whole string.
    return TRUE;
}


//
//  FUNCTION: StartReadThreadProc(LPVOID)
//
//  PURPOSE: This is the starting point for the Read Thread.
//
//  PARAMETERS:
//    lpvParam - unused.
//
//  RETURN VALUE:
//    DWORD - unused.
//
//  COMMENTS:
//
//    The Read Thread uses overlapped ReadFile and sends any strings
//    read from the comm port to the UI to be printed.  This is
//    eventually done through a PostMessage so that the Read Thread
//    is never away from the comm port very long.  This also provides
//    natural desynchronization between the Read thread and the UI.
//
//    If the CloseEvent object is signaled, the Read Thread exits.
//
//    Note that there is absolutely *no* interpretation of the data,
//    which means no terminal emulation.  It basically means that this
//    sample is pretty useless as a TTY program.
//
//	  Separating the Read and Write threads is natural for a application
//    like this sample where there is no need for synchronization between
//    reading and writing.  However, if there is such a need (for example,
//    most file transfer algorithms synchronize the reading and writing),
//    then it would make a lot more sense to have a single thread to handle
//    both reading and writing.
//
//

DWORD WINAPI StartReadThreadProc(LPVOID lpvParam)
{
    char szInputBuffer[INPUTBUFFERSIZE];
    DWORD nNumberOfBytesRead;

    HANDLE HandlesToWaitFor[3];
    DWORD dwHandleSignaled;

    DWORD fdwEvtMask;

    // Needed for overlapped I/O (ReadFile)
    OVERLAPPED overlappedRead  = {0, 0, 0, 0, NULL};

    // Needed for overlapped Comm Event handling.
    OVERLAPPED overlappedCommEvent = {0, 0, 0, 0, NULL};

    // Lets put an event in the Read overlapped structure.
    overlappedRead.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
    if (overlappedRead.hEvent == NULL)
    {
        OutputDebugLastError(GetLastError(), "Unable to CreateEvent: ");
        PostHangupCall();
        goto EndReadThread;
    }

    // And an event for the CommEvent overlapped structure.
    overlappedCommEvent.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
    if (overlappedCommEvent.hEvent == NULL)
    {
        OutputDebugLastError(GetLastError(), "Unable to CreateEvent: ");
        PostHangupCall();
        goto EndReadThread;
    }

    // We will be waiting on these objects.
    HandlesToWaitFor[0] = g_hCloseEvent;
    HandlesToWaitFor[1] = overlappedCommEvent.hEvent;
    HandlesToWaitFor[2] = overlappedRead.hEvent;


    // Setup CommEvent handling.

    // Set the comm mask so we receive error signals.
    if (!SetCommMask(g_hCommFile, EV_ERR))
    {
        OutputDebugLastError(GetLastError(),"Unable to SetCommMask: ");
        PostHangupCall();
        goto EndReadThread;
    }

    // Start waiting for CommEvents (Errors)
    if (!SetupCommEvent(&overlappedCommEvent, &fdwEvtMask))
    {
        PostHangupCall();
        goto EndReadThread;
    }

    // Start waiting for Read events.
    if (!SetupReadEvent(&overlappedRead,
                szInputBuffer, INPUTBUFFERSIZE,
                &nNumberOfBytesRead))
    {
        PostHangupCall();
        goto EndReadThread;
    }

    // Keep looping until we break out.
    while (TRUE)
    {
        // Wait until some event occurs (data to read; error; stopping).
        dwHandleSignaled = 
            WaitForMultipleObjects(3, HandlesToWaitFor,
                FALSE, INFINITE);

        // Which event occured?
        switch(dwHandleSignaled)
        {
            case WAIT_OBJECT_0:     // Signal to end the thread.
            {
                // Time to exit.
                goto EndReadThread;
            }

            case WAIT_OBJECT_0 + 1: // CommEvent signaled.
            {
                // Handle the CommEvent.
                if (!HandleCommEvent(&overlappedCommEvent, &fdwEvtMask, TRUE))
                {
                    PostHangupCall();
                    goto EndReadThread;
                }

                // Start waiting for the next CommEvent.
                if (!SetupCommEvent(&overlappedCommEvent, &fdwEvtMask))
                {
                    PostHangupCall();
                    goto EndReadThread;
                }
                break;
            }

            case WAIT_OBJECT_0 + 2: // Read Event signaled.
            {
                // Get the new data!
                if (!HandleReadEvent(&overlappedRead,
                            szInputBuffer, INPUTBUFFERSIZE,
                            &nNumberOfBytesRead))
                {
                    PostHangupCall();
                    goto EndReadThread;
                }

                // Wait for more new data.
                if (!SetupReadEvent(&overlappedRead,
                            szInputBuffer, INPUTBUFFERSIZE,
                            &nNumberOfBytesRead))
                {
                    PostHangupCall();
                    goto EndReadThread;
                }
                break;
            }

            case WAIT_FAILED:       // Wait failed.  Shouldn't happen.
            {
                OutputDebugLastError(GetLastError(),"Read WAIT_FAILED: ");
                PostHangupCall();
                goto EndReadThread;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美在线综合视频| 97精品久久久久中文字幕| 国产精品你懂的| 欧美欧美午夜aⅴ在线观看| 不卡av电影在线播放| 欧美aaaaaa午夜精品| 中文字幕亚洲在| 2022国产精品视频| 欧美日韩精品一区视频| 成人永久看片免费视频天堂| 蜜臀av亚洲一区中文字幕| 综合久久综合久久| 国产亚洲欧美日韩俺去了| 欧美精品欧美精品系列| 92精品国产成人观看免费| 国内不卡的二区三区中文字幕| 亚洲欧美激情在线| 国产精品天天看| 精品少妇一区二区三区| 久久久久久电影| 91精品午夜视频| 欧美色精品在线视频| k8久久久一区二区三区| 国产精品中文字幕日韩精品| 日本中文一区二区三区| 亚洲综合在线观看视频| 亚洲欧美在线高清| 国产亚洲一本大道中文在线| 日韩欧美美女一区二区三区| 欧美最猛性xxxxx直播| av中文一区二区三区| 国产精华液一区二区三区| 久久99精品国产麻豆婷婷洗澡| 一区二区三区国产精华| 亚洲毛片av在线| 综合色中文字幕| 国产精品久久久久久妇女6080| 久久久久久电影| 国产亚洲一区二区三区在线观看| www国产成人| 26uuu亚洲| 精品国产三级电影在线观看| 日韩免费电影一区| 欧美电影精品一区二区| 欧美mv日韩mv国产网站| 精品国产一区二区三区忘忧草 | 无码av中文一区二区三区桃花岛| 亚洲欧美成aⅴ人在线观看| 综合久久久久综合| 亚洲另类一区二区| 亚洲一级电影视频| 日韩不卡手机在线v区| 免费看欧美美女黄的网站| 久久国内精品自在自线400部| 热久久国产精品| 国产一区在线看| 国v精品久久久网| 99免费精品视频| 欧美亚洲综合另类| 欧美久久婷婷综合色| 欧美一级爆毛片| 久久亚洲一区二区三区四区| 欧美经典三级视频一区二区三区| 国产欧美日韩亚州综合| 亚洲日本在线视频观看| 亚洲最大的成人av| 青青草一区二区三区| 激情另类小说区图片区视频区| 国产精品一区二区久久精品爱涩| 成人性生交大片免费看在线播放 | 亚洲午夜久久久久久久久久久| 肉色丝袜一区二区| 国产在线精品免费av| 成人动漫一区二区在线| 欧美三级日韩在线| 2024国产精品| 亚洲男人的天堂在线aⅴ视频| 偷拍亚洲欧洲综合| 国产真实乱对白精彩久久| 99久久久久久99| 欧美精品xxxxbbbb| 欧美激情一区二区在线| 亚洲国产欧美另类丝袜| 九九精品一区二区| 91视频国产资源| 日韩欧美一区二区免费| 国产精品电影一区二区| 午夜精品一区在线观看| 国产成人在线免费观看| 欧美无砖砖区免费| 国产三级欧美三级日产三级99| 亚洲免费观看高清完整版在线观看| 日本成人在线不卡视频| 成人精品视频一区二区三区| 69成人精品免费视频| 中文在线一区二区| 青娱乐精品视频| 91亚洲国产成人精品一区二区三| 91精品国产综合久久福利软件| 国产精品久久久久久久第一福利 | 一区二区三区国产豹纹内裤在线| 免费成人你懂的| 91视频你懂的| 亚洲精品一区二区精华| 五月激情综合婷婷| 99国产精品99久久久久久| 欧美tk丨vk视频| 亚洲一区二区在线视频| 本田岬高潮一区二区三区| 欧美电影精品一区二区| 亚洲一卡二卡三卡四卡无卡久久| 成人激情文学综合网| 精品久久久久久久久久久久包黑料| 亚洲一区在线看| 99久久久久久99| 久久久精品国产免大香伊| 日本va欧美va瓶| 欧美三级欧美一级| 亚洲欧美日韩国产中文在线| 岛国精品一区二区| 久久这里只有精品视频网| 天使萌一区二区三区免费观看| 91蜜桃传媒精品久久久一区二区| 国产亚洲女人久久久久毛片| 精品一区二区三区久久| 69久久99精品久久久久婷婷| 亚洲国产综合91精品麻豆| 91免费观看国产| 综合亚洲深深色噜噜狠狠网站| 国产91精品精华液一区二区三区 | 黑人精品欧美一区二区蜜桃 | 欧美日韩一区中文字幕| 亚洲乱码国产乱码精品精可以看| 国产不卡在线播放| 久久久亚洲精华液精华液精华液| 麻豆精品一区二区综合av| 欧美精品乱码久久久久久| 亚洲一区欧美一区| 欧美日韩综合不卡| 午夜电影一区二区| 欧美高清视频在线高清观看mv色露露十八 | 欧美日韩一区二区三区四区| 亚洲综合色成人| 日本韩国欧美在线| 亚洲亚洲人成综合网络| 欧美图片一区二区三区| 亚洲一二三级电影| 欧美肥妇free| 奇米四色…亚洲| 26uuu欧美| 国产成人av影院| 最新热久久免费视频| 91麻豆swag| 亚洲国产毛片aaaaa无费看| 欧美日韩国产另类不卡| 免费美女久久99| 欧美经典三级视频一区二区三区| 白白色亚洲国产精品| 欧美高清在线视频| 色成年激情久久综合| 午夜精品爽啪视频| 欧美电影免费观看高清完整版在线观看 | 一区二区三区成人在线视频| 欧美日韩激情一区二区三区| 国产99久久久精品| 一级日本不卡的影视| 91麻豆精品国产91久久久久| 九九热在线视频观看这里只有精品| 久久天堂av综合合色蜜桃网| eeuss鲁片一区二区三区在线观看| 亚洲精品成人天堂一二三| 日韩一区二区三区视频在线观看| 国产一区二区三区在线观看精品| 国产精品乱码一区二三区小蝌蚪| 在线中文字幕不卡| 精彩视频一区二区| 亚洲精品欧美二区三区中文字幕| 欧美日韩国产经典色站一区二区三区| 日本成人在线一区| 中文字幕亚洲不卡| 欧美一区二区三区视频免费 | 欧美一区欧美二区| 国产成人在线视频免费播放| 亚洲一区二区三区视频在线播放 | 一区二区三区成人| 精品人在线二区三区| jiyouzz国产精品久久| 日韩伦理电影网| av亚洲产国偷v产偷v自拍| 日本最新不卡在线| 国产日本亚洲高清| 欧美一区在线视频| 国产成人精品影视| 亚洲第四色夜色| 国产精品久久久久国产精品日日 | 国产精品一二三四| 亚洲一区二区不卡免费| 精品电影一区二区| 日本久久一区二区| 国产精品一区不卡|