Click here to Skip to main content
15,896,153 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: HOW to save DC of onpaint(); in SDI MFC C++? Pin
humais23-Jun-10 9:24
humais23-Jun-10 9:24 
GeneralRe: HOW to save DC of onpaint(); in SDI MFC C++? Pin
CPallini23-Jun-10 10:37
mveCPallini23-Jun-10 10:37 
GeneralRe: HOW to save DC of onpaint(); in SDI MFC C++? Pin
humais23-Jun-10 19:46
humais23-Jun-10 19:46 
GeneralRe: HOW to save DC of onpaint(); in SDI MFC C++? Pin
Cedric Moonen23-Jun-10 20:53
Cedric Moonen23-Jun-10 20:53 
GeneralRe: HOW to save DC of onpaint(); in SDI MFC C++? Pin
CPallini23-Jun-10 21:08
mveCPallini23-Jun-10 21:08 
GeneralRe: HOW to save DC of onpaint(); in SDI MFC C++? Pin
humais24-Jun-10 21:49
humais24-Jun-10 21:49 
QuestionInsetObject effect the starting character selection Pin
ForNow23-Jun-10 7:50
ForNow23-Jun-10 7:50 
QuestionDebug with breakpoint works, but debug without breakpoint or release mode fails ? Pin
oppstp23-Jun-10 6:19
oppstp23-Jun-10 6:19 
Hi all :

I wrote a simple dialog based program to control a specific machine. And there is a button on the program.

When I pressed the button, some functions (from the API of the machine) would be called to do something.

Because the document said that the function is asynchronous, it used PostThreadMessage() to send some API-defined messages.

And the function might be time out. So I used CreateThread() and SetTimer() to check the success message is received or not within the thread.



But I met a strange problem.

If I ran it with debug mode and set the breakpoint on function A (function A wasn't still be called), it runs normally.

If I ran it with debug mode and didn't set the breakpoint on function A or ran it with release mode, the function A would timeout.

But if I ran the sample program (vendor provide, but only binary file, don't have source code), it runs normally...

I checked the debug mode and release mode settings of the project.

The included folders, linked folders, library dependencies...etc are the same.

So I don't know how to solve this question...

Does anyone can give a hint or pointed what's wrong with the code ?


Below is my code :

WaitPostThreadMessage(), MyFunc1() are global functions

SUCCESS_MSG, ERROR_MSG are two messages sent by the machine
TIMEOUT_MSG is the message which I defined to represent the timeout.
The parameter dwThreadId would be sent to the machine to indicate which thread is the post target of the machine

When a user click the button. MachineProc::ClickBtn() will be called.
And I put the workflow code in CreatedThread().
The problem which I mentioned above occured at calling APIFuncB()

UINT_PTR uTimer;
int timerCount;
int timerThreshold;
bool bTimeOut;

void CALLBACK TimerFunc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime) {
	timerCount++;
	if(timerCount >= timerThreshold) {
		bTimeOut = true;
	}
}

int WaitPostThreadMessage() {
	MSG msg;

	while(!bTimeOut) {
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE) {
			switch(msg.message) {
				case SUCCESS_MSG:
					if(KillTimer(NULL, uTimer) == 0) {
						// Do Logging
					} 
					return SUCCESS_MSG;
				case ERROR_MSG:
					if(KillTimer(NULL, uTimer) == 0) {
						// Do Logging
					}
					return ERROR_MSG;
				default:
					break;
			};
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		if(bTimeOut) {
			if(KillTimer(NULL, uTimer) == 0) {
				// Do Logging
			}	
			break;
		}
	}
	return TIMEOUT_MSG;
}

DWORD WINAPI CreatedThread(LPVOID) {
	MSG msg;
	PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);

	int iResult;
	DWORD dwThreadId = GetCurrentThreadId();

	iResult = APIFuncA(argu1, dwThreadId);
	iResult = MyFunc1();

	// other process code
}

int MyFunc1() {
	int iResult;	

	// Reset Timer Data
	bTimeOut = false;
	timerCount = 0;
	timerThreshold = 2;

	APIFuncB();

	// Set Timer
	uTimer = SetTimer(NULL, WM_APP_TIMER, 1000, (TIMERPROC)TimerFunc);

	iResult = WaitPostThreadMessage();
	if(iResult != SUCCESS_MSG) {
		// Do Logging
	}

	// other process code
}

void MachineProc::ClickBtn() {
	HANDLE hThread;
	DWORD nThreadID;
	hThread = CreateThread(0, 0, CreatedThread, 0, 0, &nThreadID);
}



The running ide is visual stuido 2005 (don't install windows sdk)

Thanks a lot.
AnswerRe: Debug with breakpoint works, but debug without breakpoint or release mode fails ? Pin
Code-o-mat23-Jun-10 7:00
Code-o-mat23-Jun-10 7:00 
GeneralRe: Debug with breakpoint works, but debug without breakpoint or release mode fails ? Pin
oppstp23-Jun-10 7:21
oppstp23-Jun-10 7:21 
GeneralRe: Debug with breakpoint works, but debug without breakpoint or release mode fails ? Pin
Code-o-mat23-Jun-10 8:30
Code-o-mat23-Jun-10 8:30 
AnswerRe: Debug with breakpoint works, but debug without breakpoint or release mode fails ? [modified] Pin
Aescleal23-Jun-10 7:30
Aescleal23-Jun-10 7:30 
GeneralRe: Debug with breakpoint works, but debug without breakpoint or release mode fails ? Pin
oppstp23-Jun-10 15:58
oppstp23-Jun-10 15:58 
QuestionRAW Triangle Format: How to parse it properly Pin
ant-damage23-Jun-10 5:37
ant-damage23-Jun-10 5:37 
AnswerRe: RAW Triangle Format: How to parse it properly Pin
El Corazon23-Jun-10 5:44
El Corazon23-Jun-10 5:44 
GeneralRe: RAW Triangle Format: How to parse it properly Pin
ant-damage23-Jun-10 5:55
ant-damage23-Jun-10 5:55 
GeneralRe: RAW Triangle Format: How to parse it properly Pin
El Corazon23-Jun-10 6:03
El Corazon23-Jun-10 6:03 
GeneralRe: RAW Triangle Format: How to parse it properly Pin
ant-damage23-Jun-10 6:05
ant-damage23-Jun-10 6:05 
GeneralRe: RAW Triangle Format: How to parse it properly Pin
El Corazon23-Jun-10 6:45
El Corazon23-Jun-10 6:45 
GeneralRe: RAW Triangle Format: How to parse it properly Pin
ant-damage23-Jun-10 7:01
ant-damage23-Jun-10 7:01 
GeneralRe: RAW Triangle Format: How to parse it properly Pin
El Corazon23-Jun-10 7:03
El Corazon23-Jun-10 7:03 
GeneralRe: RAW Triangle Format: How to parse it properly Pin
ant-damage23-Jun-10 8:08
ant-damage23-Jun-10 8:08 
GeneralRe: RAW Triangle Format: How to parse it properly Pin
ant-damage23-Jun-10 8:16
ant-damage23-Jun-10 8:16 
GeneralRe: RAW Triangle Format: How to parse it properly Pin
El Corazon23-Jun-10 8:21
El Corazon23-Jun-10 8:21 
GeneralRe: RAW Triangle Format: How to parse it properly Pin
ant-damage24-Jun-10 9:41
ant-damage24-Jun-10 9:41 

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.