Another MFC/C++ Question-Threads

Thread Starter

Brownout

Joined Jan 10, 2012
2,390
My MFC program for testing new digital designs is coming along nicely. (see here for details: http://forum.allaboutcircuits.com/showthread.php?t=70900) However, I've hit a snag. I'm using the Document/View structure, which allows me to build a very functional, if still evolving, interface for setting up tests, configuring my electronics systems, getting output, etc. Now, I need to be able to create threads for connecting to the DUT and managing communications. Further, I need for the threads to be able to communicate data back to the main program. I generate the thread from the view module, and everthing goes OK until I need to feed data back from the thread. The view defines data members and data access member methods, and the thread calls those methods via an object pointer to the view. The methods modify the data members, as usual for the C++ methodology. The problem is, when the thread calls the methods, the data members don't get modified as they should. But, I can use the method calls to modify global variables ( as a work-around, though that isn't the right way to do things ) So, in summary, the methods can modify global variables but not class data members.

I can post my code, but it's alot of experimental code and might be tough to unwind. If anyone seriously wants to go through it, let me know.

Thanks!
 

ErnieM

Joined Apr 24, 2011
8,377
I suppose you are skipping the patent stage to avoid public disclosure. A "trade secret" is oft the best defense.
 

Thread Starter

Brownout

Joined Jan 10, 2012
2,390
I'm interested but only just seen this thread
Are you interested in multi-threading? My first attempt to pass a value from the thread to the calling module used a method from this page: http://msdn.microsoft.com/en-us/library/h14y172e(d=printer,v=vs.80).aspx Look near the bottom where it talks about Handle Maps. I passed an HWND object and extracted a pointer to the object using FromHandle(). Then I called an accessor function using... ObjectPointer->function()... As I described above, I could only access global variables this way. Then, I decided to pass a message to the window using the method described in this post: http://www.codeproject.com/Articles/18067/Synchronization-in-Multithreaded-Applications-with Near the end of the article, there's a heading "Communication between Secondary Threads and the Primary Threads" It uses user-defined messages for passing information to the main window of an application. For an unexplained reason, that didn't work either. But, then I changed the line in the worker thread

::postMessage(hWnd, WM_MYMSG, 0, 0);
to this:

AfxGetMainWnd()->SendMessage(WM_MY_MESSAGE, 0, 0);
Then all was well.

If you want more details, just ask.
 
Top