Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UpdateData???

Status
Not open for further replies.

rdalton

Programmer
Dec 5, 2002
24
0
0
US
Hello,
I'm working through a crazy bug right now with the UpdateData(false) command. I'm trying to update ordinary text that represents a counter in my dialog. Every second I format the string and issue the UpdateData(false) command, which then calls the DataExchange function and so on...While compiling in Debug Mode the update fails. The last line in the call stack is CWnd::AssertValid(). However, this doesn't crash the system in the Release mode. I use the UpdateData(false) command in other places and it works fine, the only difference with the other code is that it is called much more fequently. Does anyone have any ideas. Thanks.

Bob
 
an Assertion is not a crash as so the code after the assertion is probably error checking which is why it does not crash in release mode. Do you get the desired behavior in release mode?

When that assertion fires use the ignore button to keep executing and see the Release mode behavior.

-pete
 
Everything works as expected in release mode...In debug mode there is an assertion failure in wincore.cpp line 884. If I hit ignore the code proceeds through the loop and the text is actually updated, but next time it hits the UpdateData(false) line there's the same assert error. It's strange that if I hit the ignore the text is updated like I want. Wierd stuff.

bob
 
Did you look at the file?
Code:
		ASSERT((CWnd*)p == this);   // must be us

		// Note: if either of the above asserts fire and you are
		// writing a multithreaded application, it is likely that
		// you have passed a C++ object from one thread to another
		// and have used that object in a way that was not intended.
		// (only simple inline wrapper functions should be used)
		//
		// In general, CWnd objects should be passed by HWND from
		// one thread to another.  The receiving thread can wrap
		// the HWND with a CWnd object by using CWnd::FromHandle.
		//
		// It is dangerous to pass C++ objects from one thread to
		// another, unless the objects are designed to be used in
		// such a manner.

-pete
 
I see what the problem is now, but I'm having trouble getting around it. I pass a pointer to the dialog to the worker thread during creation. I use this pointer in the to make changes to some MFC controls (mainly static text) then try to update the controls. I'm trying to pass a HWND using GetSafeHwnd() then using CWnd::FromHandle(), but it's not working correctly. Anytime I get try to access data members in my dialog, from within the thread, it crashes saying cannot access memory. Do you have any suggestions?

bob
 
>> Do you have any suggestions?

My first suggestion would be to learn to research information. Trying to do multi-threaded development is not trivial in most cases. When developing more complex applications and using technology and API’s that you are not experienced in, you need to research and read the documentation. Just winging it usually won’t cut it.

It took me 5 seconds to find this article on MSDN Online ( msdn.microsoft.com ) There are others as well as technical notes about using MFC in threaded applications.


-pete
 
Hey Bob,

I'm having the same issue you had...the assert and all that. Do you remember how you fixed the issue?
 
hey bluecrush,
sorry for the delay...In my case, I just re-organized my code and the problem went away due to a cleaner solution. Can you be more descriptive about what it is your trying to do and where you are getting the assert? Maybe I can help.

Bob
 
Thanks for getting back to me, but I found a work-around for what I was trying to do. I went with posting a message whenever I need the data updated rather than passing the HWND object. Thank you again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top