Click here to Skip to main content
15,907,497 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: is there any fuction an get an object form window handle? Pin
«_Superman_»25-Feb-09 1:54
professional«_Superman_»25-Feb-09 1:54 
GeneralRe: is there any fuction an get an object form window handle? Pin
tyr200025-Feb-09 2:11
tyr200025-Feb-09 2:11 
GeneralRe: is there any fuction an get an object form window handle? Pin
«_Superman_»25-Feb-09 2:14
professional«_Superman_»25-Feb-09 2:14 
GeneralRe: is there any fuction an get an object form window handle? Pin
tyr200025-Feb-09 2:29
tyr200025-Feb-09 2:29 
GeneralRe: is there any fuction an get an object form window handle? Pin
«_Superman_»25-Feb-09 2:31
professional«_Superman_»25-Feb-09 2:31 
GeneralRe: is there any fuction an get an object form window handle? Pin
tyr200025-Feb-09 2:46
tyr200025-Feb-09 2:46 
QuestionReg: Dialogue size change Pin
coding_ram25-Feb-09 1:01
coding_ram25-Feb-09 1:01 
AnswerRe: Reg: Dialogue size change Pin
SandipG 25-Feb-09 1:07
SandipG 25-Feb-09 1:07 
GeneralRe: Reg: Dialogue size change Pin
coding_ram25-Feb-09 1:12
coding_ram25-Feb-09 1:12 
GeneralRe: Reg: Dialogue size change Pin
SandipG 25-Feb-09 1:16
SandipG 25-Feb-09 1:16 
GeneralRe: Reg: Dialogue size change Pin
coding_ram25-Feb-09 1:20
coding_ram25-Feb-09 1:20 
GeneralRe: Reg: Dialogue size change Pin
SandipG 25-Feb-09 1:21
SandipG 25-Feb-09 1:21 
AnswerRe: Reg: Dialogue size change Pin
David Crow25-Feb-09 3:20
David Crow25-Feb-09 3:20 
GeneralRe: Reg: Dialogue size change Pin
coding_ram25-Feb-09 18:14
coding_ram25-Feb-09 18:14 
QuestionWhy am I not able to get handle of file? Pin
SherTeks25-Feb-09 0:53
SherTeks25-Feb-09 0:53 
AnswerRe: Why am I not able to get handle of file? Pin
SandipG 25-Feb-09 1:05
SandipG 25-Feb-09 1:05 
GeneralRe: Why am I not able to get handle of file? Pin
ky_rerun25-Feb-09 3:47
ky_rerun25-Feb-09 3:47 
GeneralRe: Why am I not able to get handle of file? Pin
SandipG 25-Feb-09 4:38
SandipG 25-Feb-09 4:38 
QuestionRe: Why am I not able to get handle of file? Pin
David Crow25-Feb-09 3:22
David Crow25-Feb-09 3:22 
AnswerRe: Why am I not able to get handle of file? Pin
ky_rerun25-Feb-09 5:58
ky_rerun25-Feb-09 5:58 
AnswerRe: Why am I not able to get handle of file? Pin
Stuart Dootson25-Feb-09 12:06
professionalStuart Dootson25-Feb-09 12:06 
QuestionSerial coms worker thread not working Pin
jimjim73324-Feb-09 23:30
jimjim73324-Feb-09 23:30 
Hi All,

I wondered if someone can shed some light on what might be going on here.
I have created the worker thread (code below) and when my system first boots up and I run through debug I find that the thread doesn't fire off the PostMessage(UWM_DATA_READ) until the buffer is full up....what I want it to do is fire it off when ever it reads in something.
The interesting part is that if I stop the application and open Hyperterminal on the same com port then close it and then rerun the application it works as I intended????
Does anyone have any ideas what is going on??????

Cheers

Jim

UINT CMyDlg::monitorThread(LPVOID pParam)
{
	DWORD		dwRead;
	DWORD		dwRes;
	BOOL		fWaitingOnRead = FALSE;
	OVERLAPPED	osReader = {0};
	struct PTZCommStruct *pPTZStruct = (struct PTZCommStruct *)pParam;


	// Create the overlapped event.
	osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	if(osReader.hEvent == NULL)
	{
		// Error creatiing overlapped event, abort.
		DWORD err = ::GetLastError();
		pPTZStruct->pWnd->PostMessage(UWM_READER_SHUTTING_DOWN, (WPARAM)err);
		return 0;
	} 


	while(pPTZStruct->nPTZCommTerminate == 0)
	{
		if(!fWaitingOnRead)
		{
			// Issue read Operation.
			BOOL tmp = ReadFile(m_hPTZCtrlPort, PTZbuffer, MAX_BUFFER_SIZE, &dwRead, &osReader);
			if(!tmp)
			{
				if(GetLastError() != ERROR_IO_PENDING) // read not delayed
				{
					// Error in comms - report!!!
					return 0;
				}
				else
				{
					fWaitingOnRead = TRUE;
				}
			}
			else
			{
				// ***Read the data
				pPTZStruct->pWnd->PostMessage(UWM_DATA_READ);
			}
		}
		else
		{
			dwRes = WaitForSingleObject(osReader.hEvent, READ_TIMEOUT);
			switch(dwRes)
			{
				// Read Completed
			case WAIT_OBJECT_0:
				if(!GetOverlappedResult(m_hPTZCtrlPort, &osReader, &dwRead, FALSE))
				{
					DWORD dwError = GetLastError();
					switch(dwError)
					{
						case ERROR_HANDLE_EOF:
							return 0;
							break;
						case ERROR_IO_PENDING:
							return 0;
							break;
						case ERROR_IO_INCOMPLETE:
							return 0;
							break;
						case ERROR_OPERATION_ABORTED:
							return 0;
							break;
						default:
							// error in comms - report
							Dump1("Serial Read Error %d\r\n", ::GetLastError());
							return 0;
							break;
					}
				}
				else
				{
					// ***Read the Data 
			        pPTZStruct->pWnd->PostMessage(UWM_DATA_READ);
				}
				fWaitingOnRead = FALSE;
				break;

			case WAIT_TIMEOUT:
				// Operation isn't complete yet. fWaitingOnRead flag isn't changed since I'll
				// loop back around, and I don't want to issue another read until the first one finishes.
				//
				break;

			default:
				// Error in the WaitForSigleObject; abort!!!!
				// This indicates a problem with the OVERLAPPED structure's event handle.
				return 0;
				break;

			}
		} 
	}
	return 0;
}

AnswerRe: Serial coms worker thread not working Pin
Cedric Moonen24-Feb-09 23:40
Cedric Moonen24-Feb-09 23:40 
GeneralRe: Serial coms worker thread not working Pin
jimjim73325-Feb-09 0:20
jimjim73325-Feb-09 0:20 
QuestionFew doubts in MFC application?? Pin
kapardhi24-Feb-09 23:22
kapardhi24-Feb-09 23:22 

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.