Click here to Skip to main content
15,898,374 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
AnswerRe: Few doubts in MFC application?? Pin
Iain Clarke, Warrior Programmer24-Feb-09 23:45
Iain Clarke, Warrior Programmer24-Feb-09 23:45 
QuestionCreateProcess in WinCE Pin
vijaywithu24-Feb-09 22:48
vijaywithu24-Feb-09 22:48 
AnswerRe: CreateProcess in WinCE Pin
Sethuraman.K24-Feb-09 23:33
Sethuraman.K24-Feb-09 23:33 
GeneralRe: CreateProcess in WinCE Pin
Sethuraman.K24-Feb-09 23:49
Sethuraman.K24-Feb-09 23:49 
GeneralRe: CreateProcess in WinCE Pin
vijaywithu24-Feb-09 23:50
vijaywithu24-Feb-09 23:50 
GeneralRe: CreateProcess in WinCE Pin
Sethuraman.K25-Feb-09 0:07
Sethuraman.K25-Feb-09 0:07 
GeneralRe: CreateProcess in WinCE Pin
Sethuraman.K25-Feb-09 0:31
Sethuraman.K25-Feb-09 0:31 
GeneralRe: CreateProcess in WinCE Pin
ujjawal kumar25-Feb-09 20:13
ujjawal kumar25-Feb-09 20:13 
QuestionAny one can help me with these code Pin
Archy_Yu24-Feb-09 21:27
Archy_Yu24-Feb-09 21:27 
AnswerRe: Any one can help me with these code Pin
ashtwin24-Feb-09 21:35
ashtwin24-Feb-09 21:35 
AnswerRe: Any one can help me with these code Pin
Sethuraman.K24-Feb-09 23:25
Sethuraman.K24-Feb-09 23:25 
GeneralRe: Any one can help me with these code Pin
Iain Clarke, Warrior Programmer24-Feb-09 23:51
Iain Clarke, Warrior Programmer24-Feb-09 23:51 
GeneralRe: Any one can help me with these code Pin
CPallini25-Feb-09 0:38
mveCPallini25-Feb-09 0:38 
QuestionHow can stop highligting button control? Pin
Le@rner24-Feb-09 20:34
Le@rner24-Feb-09 20:34 

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.