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

C / C++ / MFC

 
GeneralRe: Multithreaded QuickSort Pin
Xiangyang Liu 刘向阳8-Dec-03 1:13
Xiangyang Liu 刘向阳8-Dec-03 1:13 
QuestionThe Trouble with List Controls(CListCtrl)?? Pin
MissingLinkError4-Dec-03 16:23
MissingLinkError4-Dec-03 16:23 
AnswerRe: The Trouble with List Controls(CListCtrl)?? Pin
Abin4-Dec-03 20:18
Abin4-Dec-03 20:18 
GeneralRe: The Trouble with List Controls(CListCtrl)?? Pin
MissingLinkError5-Dec-03 9:32
MissingLinkError5-Dec-03 9:32 
Generalcontinuous voice problem Pin
yingkou4-Dec-03 15:46
yingkou4-Dec-03 15:46 
GeneralOpenGL problem on XP, wglMakeCurrent changes tooltips behavior for windows desktop Pin
Yawar Maajed4-Dec-03 14:20
Yawar Maajed4-Dec-03 14:20 
GeneralWaitForMultipleObjects always returns WAIT_FAILED Pin
Kuniva4-Dec-03 10:50
Kuniva4-Dec-03 10:50 
GeneralRe: WaitForMultipleObjects always returns WAIT_FAILED Pin
Kelly Herald4-Dec-03 17:52
Kelly Herald4-Dec-03 17:52 
I was getting this problem a couple of years ago. It was very frustrating until I read the chapter on threading in Jeff Prosise's book Programming Windows with MFC.

If the threads were created using AfxBeginThread which returns a CWinThread* then what is happening is that when at least one thread finishes the CWinThread is automatically deleting the thread handle which will cause WaitForMultipleObjects to return failed because at least one handle is invalid (closed). One way to resolve this is to create the thread suspended, duplicate the handle, and finally resume the thread. This means that the duplicate handle will be valid until YOU close it. Here is a simple code snippet:

CWinThread* pThread = AfxBeginThread(ThreadFunc, lpData, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
::DuplicateHandle(AfxGetProcess(), pThread->m_hThread, AfxGetProcess(), &hThread, 0, FALSE, DUPLICATE_SAME_ACCESS);
pThread->ResumeThread();

...
...

::WaitForMultipleObjects...
::CloseHandle(hThread); // <-- remember to close the handles that you duplicated


This is VERY abbreviated code but it should give you the general idea.


Kelly Herald
Software Developer
MPC
GeneralRe: WaitForMultipleObjects always returns WAIT_FAILED Pin
Kuniva5-Dec-03 0:19
Kuniva5-Dec-03 0:19 
GeneralRe: WaitForMultipleObjects always returns WAIT_FAILED Pin
Kuniva5-Dec-03 0:30
Kuniva5-Dec-03 0:30 
GeneralRe: WaitForMultipleObjects always returns WAIT_FAILED Pin
Mike Dimmick5-Dec-03 0:02
Mike Dimmick5-Dec-03 0:02 
GeneralRe: WaitForMultipleObjects always returns WAIT_FAILED Pin
Kuniva5-Dec-03 0:18
Kuniva5-Dec-03 0:18 
GeneralButton in windows forms..c++ Pin
mitil203904823044-Dec-03 10:36
mitil203904823044-Dec-03 10:36 
GeneralSwitching Views in SDI Pin
swerajan4-Dec-03 9:52
swerajan4-Dec-03 9:52 
GeneralRe: Switching Views in SDI Pin
Peter Molnar4-Dec-03 13:38
Peter Molnar4-Dec-03 13:38 
GeneralProblem with lpdirect3ddevice9 Pin
Simon Booth4-Dec-03 9:26
Simon Booth4-Dec-03 9:26 
GeneralRe: Problem with lpdirect3ddevice9 Pin
ZoogieZork4-Dec-03 18:17
ZoogieZork4-Dec-03 18:17 
GeneralPostMessage() problems Pin
Sid_smily4-Dec-03 9:18
Sid_smily4-Dec-03 9:18 
GeneralRe: PostMessage() problems Pin
David Crow4-Dec-03 9:24
David Crow4-Dec-03 9:24 
GeneralThe right way Pin
Abin4-Dec-03 13:27
Abin4-Dec-03 13:27 
GeneralUpdateLayeredWindow() Help !!! Pin
4-Dec-03 8:50
suss4-Dec-03 8:50 
GeneralLastest beta of Visual Studio .NET Pin
Robert Buldoc4-Dec-03 7:54
Robert Buldoc4-Dec-03 7:54 
GeneralRe: Lastest beta of Visual Studio .NET Pin
Mike Dimmick5-Dec-03 0:23
Mike Dimmick5-Dec-03 0:23 
GeneralRe: Lastest beta of Visual Studio .NET Pin
Robert Buldoc5-Dec-03 21:05
Robert Buldoc5-Dec-03 21:05 
GeneralVS .NET window type Pin
rpadrela4-Dec-03 7:29
rpadrela4-Dec-03 7:29 

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.