Click here to Skip to main content
15,914,452 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionGetLastInputInfo error Pin
Pryabu8-Aug-10 21:44
Pryabu8-Aug-10 21:44 
AnswerRe: GetLastInputInfo error Pin
_AnsHUMAN_ 8-Aug-10 22:12
_AnsHUMAN_ 8-Aug-10 22:12 
GeneralRe: GetLastInputInfo error Pin
Pryabu8-Aug-10 22:17
Pryabu8-Aug-10 22:17 
AnswerRe: GetLastInputInfo error Pin
Niklas L8-Aug-10 23:07
Niklas L8-Aug-10 23:07 
AnswerRe: GetLastInputInfo error Pin
KingsGambit8-Aug-10 23:10
KingsGambit8-Aug-10 23:10 
QuestionCloseHandle() freezes the program... Pin
learningvisualc8-Aug-10 19:27
learningvisualc8-Aug-10 19:27 
AnswerRe: CloseHandle() freezes the program... Pin
«_Superman_»8-Aug-10 19:33
professional«_Superman_»8-Aug-10 19:33 
AnswerRe: CloseHandle() freezes the program... Pin
Iain Clarke, Warrior Programmer8-Aug-10 21:20
Iain Clarke, Warrior Programmer8-Aug-10 21:20 
You've suspended a thread with work still happening on a file handle. Then pulling the rug out from under it. Who know's what was going on in that thread?

Any time I see a thread being suspended from outside, alarm bells ring. TerminateThread just made them louder.

As you're already working with overlapped I/O...

Why not pass your thread a handle to an Event. Then open and close the handle local to the event (this last bit is optional).

Some pseudo code (ie, I don't have access to a compiler right now)

UINT MyThread (LPVOID lpParam)
{
    CMyContext *pSomeStruct = (CMyContext *) lpParam;
    OVERLAPPED o = {0};
    HANDLE hWait = { NULL, NULL };
    o.hEvent = hWait [0] = CreateEvent (...);
    hWait [1] = pSomeStruct->m_hQuitThreadEvent; // created outside, so our thread can be finished with SetEvent.

    while (1)
    {
        if (ReadFile (hPort,  ..., &o))
        {
           Dostuffwithdata ()
        }
        else if (GetLastError () == ERROR_IO_PENDING) // which will happen a lot
        {
            nWait = WaitForMultipleObjects (hWait, 2);
            if (hWait == WAIT_OBJECT_0) // we have data
            {
                // grab data, and do what we like with it
            }
            else if (hWait == WAIT_OBJECT_0 + 1)
            {
                // we've received a quit signal!
                CancelIo (); // Important to clear dangling overlapped I/O
                break;
            }
            else
           {
               // other tidying up code
            }
        }
    }

    CloseHandle (o.hEvent);

    return nReturn;
}


You have a good amount of work to make the above fit for production, but I hope it sets you on the Right (ie, my example) path.

Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!

GeneralRe: CloseHandle() freezes the program... Pin
SRIVATHSAN VIJAYA22-Apr-15 0:33
SRIVATHSAN VIJAYA22-Apr-15 0:33 
QuestionHow to do fast Zip in c++? Pin
002comp8-Aug-10 18:20
002comp8-Aug-10 18:20 
AnswerRe: How to do fast Zip in c++? Pin
N a v a n e e t h8-Aug-10 18:46
N a v a n e e t h8-Aug-10 18:46 
GeneralRe: How to do fast Zip in c++? Pin
elchupathingy8-Aug-10 19:18
elchupathingy8-Aug-10 19:18 
GeneralRe: How to do fast Zip in c++? Pin
002comp8-Aug-10 21:11
002comp8-Aug-10 21:11 
GeneralRe: How to do fast Zip in c++? Pin
002comp9-Aug-10 0:16
002comp9-Aug-10 0:16 
GeneralRe: How to do fast Zip in c++? Pin
Moak10-Aug-10 13:13
Moak10-Aug-10 13:13 
QuestionHow to check the NULL iterator? Pin
DevelopmentNoob8-Aug-10 17:26
DevelopmentNoob8-Aug-10 17:26 
AnswerRe: How to check the NULL iterator? [modified] PinPopular
Niklas L8-Aug-10 19:44
Niklas L8-Aug-10 19:44 
AnswerRe: How to check the NULL iterator? Pin
Moak8-Aug-10 21:39
Moak8-Aug-10 21:39 
AnswerRe: How to check the NULL iterator? Pin
Aescleal8-Aug-10 22:22
Aescleal8-Aug-10 22:22 
QuestionwaveOutOpen returning no message?? Pin
AmbiguousName8-Aug-10 2:45
AmbiguousName8-Aug-10 2:45 
AnswerRe: waveOutOpen returning no message?? Pin
Richard MacCutchan8-Aug-10 2:54
mveRichard MacCutchan8-Aug-10 2:54 
GeneralRe: waveOutOpen returning no message?? Pin
AmbiguousName8-Aug-10 4:30
AmbiguousName8-Aug-10 4:30 
GeneralRe: waveOutOpen returning no message?? Pin
Luc Pattyn8-Aug-10 4:58
sitebuilderLuc Pattyn8-Aug-10 4:58 
GeneralRe: waveOutOpen returning no message?? Pin
Richard MacCutchan8-Aug-10 5:31
mveRichard MacCutchan8-Aug-10 5:31 
QuestionAvoiding Resource Conflicts in MFC Extension DLLs Pin
softwaremonkey7-Aug-10 21:07
softwaremonkey7-Aug-10 21:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.