Click here to Skip to main content
15,918,303 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CFileDialog save as Pin
letymau5-Dec-03 1:59
letymau5-Dec-03 1:59 
Generalto change drawing size of SDI formview Pin
coda_x4-Dec-03 20:45
coda_x4-Dec-03 20:45 
GeneralUuidCreateSequential() does not work Pin
Smita Duraphe4-Dec-03 20:03
Smita Duraphe4-Dec-03 20:03 
GeneralRe: UuidCreateSequential() does not work Pin
Mike Dimmick4-Dec-03 23:53
Mike Dimmick4-Dec-03 23:53 
QuestionAnyone here want to earn some money by writing a few small programs fhat i need for my introductary C++ class? Pin
badsocvol4-Dec-03 18:03
sussbadsocvol4-Dec-03 18:03 
AnswerRe: Anyone here want to earn some money by writing a few small programs fhat i need for my introductary C++ class? Pin
Prakash Nadar4-Dec-03 18:59
Prakash Nadar4-Dec-03 18:59 
AnswerRe: Anyone here want to earn some money by writing a few small programs fhat i need for my introductary C++ class? Pin
фил4-Dec-03 21:05
фил4-Dec-03 21:05 
AnswerRe: Anyone here want to earn some money by writing a few small programs fhat i need for my introductary C++ class? Pin
Abebe4-Dec-03 21:24
Abebe4-Dec-03 21:24 
AnswerRe: Anyone here want to earn some money by writing a few small programs fhat i need for my introductary C++ class? Pin
Roger Wright4-Dec-03 22:10
professionalRoger Wright4-Dec-03 22:10 
GeneralRe: Anyone here want to earn some money by writing a few small programs fhat i need for my introductary C++ class? Pin
KaЯl5-Dec-03 2:04
KaЯl5-Dec-03 2:04 
GeneralRe: Anyone here want to earn some money by writing a few small programs fhat i need for my introductary C++ class? Pin
Roger Wright5-Dec-03 4:58
professionalRoger Wright5-Dec-03 4:58 
GeneralRe: Anyone here want to earn some money by writing a few small programs fhat i need for my introductary C++ class? Pin
Jörgen Sigvardsson6-Dec-03 2:10
Jörgen Sigvardsson6-Dec-03 2:10 
GeneralThe synchronization issue on sending and receiving data via UDP Multicast... Pin
JoeZhang4-Dec-03 16:33
JoeZhang4-Dec-03 16:33 
GeneralRe: The synchronization issue on sending and receiving data via UDP Multicast... Pin
Roger Wright4-Dec-03 18:05
professionalRoger Wright4-Dec-03 18:05 
GeneralRe: The synchronization issue on sending and receiving data via UDP Multicast... Pin
Johnny ²4-Dec-03 21:35
Johnny ²4-Dec-03 21:35 
GeneralRe: The synchronization issue on sending and receiving data via UDP Multicast... Pin
JoeZhang4-Dec-03 22:04
JoeZhang4-Dec-03 22:04 
GeneralRe: The synchronization issue on sending and receiving data via UDP Multicast... Pin
Mike Dimmick4-Dec-03 23:55
Mike Dimmick4-Dec-03 23:55 
GeneralMultithreaded QuickSort Pin
Robert Buldoc4-Dec-03 16:29
Robert Buldoc4-Dec-03 16:29 
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 
I have a function in my tcp server that starts a thread to try and stop the server, i'm using a thread because when the server stops, things have to be removed from a list of clients, and so it cant block the message queu or i cant use SendMessage(). The problem is that when i test, by connecting via telnet, and stop the server while the client is connected, WaitForMultipleObjects() usually returns WAIT_FAILED with error code 6 (Invalid handle). Only the first time i stop the server it sometimes works ok. But after that its always WAIT_FAILED. HEre's the code to the stopper thread:

DWORD WINAPI StopServerThread(void* prms)
{
	HWND hWnd = (HWND)prms;
	HL thread;
	HLI hli;

	int result=0;

	// Close the listener
	shutdown(sListener,SD_BOTH);
	closesocket(sListener);


	if(client.size()>0)
	{
		DWORD err;

		for(cli=client.begin();cli!=client.end();++cli)
		{
			thread.push_back((HANDLE)(*cli)->ThreadHandle);
		}

		if(!WSASetEvent(hSuicideEvent))
			MessageBox(hWnd,"WSASetEvent() failed","Error",MB_ICONERROR);
	
		result = WaitForMultipleObjects( thread.size(), thread.begin(), TRUE, 5000 );
		switch ( result )
		{
		case WAIT_TIMEOUT:
			ConsoleOutput("Not all threads died in time");
			break;
		case WAIT_FAILED:
			err = GetLastError();
			ConsoleOutput("WaitForMultipleObjects(): WAIT_FAILED (%i)", (int)err);
			break;
		default:
			ConsoleOutput("All client threads terminated successfully");
			break;
		}

		for ( hli = thread.begin(); hli != thread.end(); ++ hli )
			CloseHandle( *hli );

		client.clear();
		thread.clear();
	
	}

	DeleteCriticalSection(&lpCritSection);

	WSACloseEvent(hSuicideEvent);

	bIsRunning = FALSE;

	// Update the menu
	HMENU mainmenu = GetMenu(hWnd);
	EnableMenuItem(mainmenu,IDM_START,MF_ENABLED);
	EnableMenuItem(mainmenu,IDM_STOP,MF_GRAYED);

	ExitThread(0);

	return 0;
}


client is a list of client information, also containing the thread handles of each client thread. Weird thing is that the client threads DO exit and all, everything works fine except that WaitForMultipleObjects starts to return WAIT_FAILED. Anyone have any idea why?
Thanks

Kuniva
--------------------------------------------

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.