Click here to Skip to main content
15,499,571 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: conflicting types for 'uint32_t' issue Pin
Richard MacCutchan5-May-22 5:02
mveRichard MacCutchan5-May-22 5:02 
AnswerRe: conflicting types for 'uint32_t' issue Pin
Randor 5-May-22 10:28
professional Randor 5-May-22 10:28 
GeneralRe: conflicting types for 'uint32_t' issue Pin
focusdoit5-May-22 15:04
Memberfocusdoit5-May-22 15:04 
GeneralRe: conflicting types for 'uint32_t' issue Pin
Randor 5-May-22 15:31
professional Randor 5-May-22 15:31 
GeneralRe: conflicting types for 'uint32_t' issue Pin
Richard MacCutchan5-May-22 23:23
mveRichard MacCutchan5-May-22 23:23 
QuestionComplier error C2280 explanation Pin
ForNow5-May-22 2:37
MemberForNow5-May-22 2:37 
AnswerRe: Complier error C2280 explanation Pin
CPallini5-May-22 2:59
mveCPallini5-May-22 2:59 
GeneralRe: Complier error C2280 explanation Pin
ForNow5-May-22 3:07
MemberForNow5-May-22 3:07 
GeneralRe: Complier error C2280 explanation Pin
CPallini5-May-22 3:10
mveCPallini5-May-22 3:10 
GeneralRe: Complier error C2280 explanation Pin
ForNow5-May-22 3:21
MemberForNow5-May-22 3:21 
GeneralRe: Complier error C2280 explanation Pin
CPallini5-May-22 3:34
mveCPallini5-May-22 3:34 
GeneralRe: Complier error C2280 explanation Pin
ForNow5-May-22 4:01
MemberForNow5-May-22 4:01 
Questioncannot Create CListBox : CFormView without IDD Pin
rtischer82774-May-22 5:04
Memberrtischer82774-May-22 5:04 
QuestionRe: cannot Create CListBox : CFormView without IDD Pin
David Crow4-May-22 5:47
MemberDavid Crow4-May-22 5:47 
QuestionWaitForSingleObject Visual C++ bug Pin
coco2431-May-22 9:35
Membercoco2431-May-22 9:35 
Hi,

I am following an example from a book, and I have an WaitForSingleObject that works just first time and I don't know
how to resolve that.

The main things are happening in the ChildThreadProc. At the first execution of the ChildThreadProc the procedure steps through all lines of code, but when is launched again, the execution stops at WaitForSingleObject, as if hAutoEvent isn't signaled or I don't know what is happening, and please help me to figure this out.

So,
In the WindProc main procedure when the window is created, is created the Event also:

C++
case WM_CREATE:  // Make an auto-reset event with initial state of signaled
	    hAutoEvent = CreateEvent ( NULL, FALSE, TRUE, "EXAMPLE-AUTOEVENT" );
		return DefWindowProc(hWnd, message, wParam, lParam);


The example of WaitForSingleObject is presented in the following procedure:

C++
// Child thread procedure. The child waits to get event. It then sits idle
// for five seconds and sets the event again so another thread can use it.

DWORD WINAPI ChildThreadProc ( HWND hWnd )
{
	char szBuffer[256];   //work area for print formatting
	HANDLE hAutoEvent = OpenEvent( SYNCHRONIZE, FALSE, "EXAMPLE-AUTOEVENT");
	wsprintf(szBuffer, "Thread %x waiting for Event %x", GetCurrentThreadId(), hAutoEvent );
	SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer);

	// Check that write auto reset is signaled.
	WaitForSingleObject(hAutoEvent, INFINITE );
	wsprintf(szBuffer, " Thread %x got event", GetCurrentThreadId() );
	SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer );
	Sleep(2000);

	//Release event
	wsprintf(szBuffer, "Thread %x is dome with event", GetCurrentThreadId() );
	SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer);
	SetEvent(hAutoEvent);
	CloseHandle( hAutoEvent);
	ExitThread( TRUE );


The ChildThreadProc is started here:

C++
case IDM_TEST:
			{
				DWORD id=0;
				CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)ChildThreadProc, hWnd, 0, &id );
			}
			break;


and here is where text out is handled:

C++
case WM_USER:
		{
			TCHAR szBuffer[101];
			static int row = 0;
			static int msg_num = 1;

			HDC hDC = GetDC(hWnd);

			FillMemory(szBuffer, 100, 32 );
			TextOut( hDC, 0, row, szBuffer, 100 );
			wsprintf(szBuffer, "%3d: %s", msg_num++, (LPSTR)lParam );
			TextOut(hDC, 0, row, szBuffer, lstrlen(szBuffer) );
            row = (row > 200 ) ? 0 : row += 20;
			ReleaseDC(hWnd,hDC);

		}
		break;


Please help me to find what I am not doing right.

Thank you,
AnswerRe: WaitForSingleObject Visual C++ bug Pin
Randor 1-May-22 11:22
professional Randor 1-May-22 11:22 
GeneralRe: WaitForSingleObject Visual C++ bug Pin
coco2434-May-22 6:43
Membercoco2434-May-22 6:43 
GeneralRe: WaitForSingleObject Visual C++ bug Pin
Randor 4-May-22 9:02
professional Randor 4-May-22 9:02 
GeneralRe: WaitForSingleObject Visual C++ bug Pin
coco2434-May-22 10:19
Membercoco2434-May-22 10:19 
QuestionOne DrawItem Function for both CStatic and CComboBox Pin
ForNow30-Apr-22 16:11
MemberForNow30-Apr-22 16:11 
AnswerRe: One DrawItem Function for both CStatic and CComboBox Pin
Richard MacCutchan30-Apr-22 22:06
mveRichard MacCutchan30-Apr-22 22:06 
GeneralRe: One DrawItem Function for both CStatic and CComboBox Pin
ForNow1-May-22 4:27
MemberForNow1-May-22 4:27 
GeneralRe: One DrawItem Function for both CStatic and CComboBox Pin
Richard MacCutchan1-May-22 4:36
mveRichard MacCutchan1-May-22 4:36 
GeneralRe: One DrawItem Function for both CStatic and CComboBox Pin
ForNow1-May-22 4:52
MemberForNow1-May-22 4:52 
QuestionClist Find question Pin
ForNow29-Apr-22 4:12
MemberForNow29-Apr-22 4:12 

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.