Another MFC/C++ Question-Threads

Discussion in 'Programmer's Corner' started by Brownout, Jul 28, 2012.

  1. Brownout

    Thread Starter Well-Known Member

    Jan 10, 2012
    2,375
    998
    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!
     
  2. Brownout

    Thread Starter Well-Known Member

    Jan 10, 2012
    2,375
    998
    Took me two days, but I found a good work-around.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    I suppose you are skipping the patent stage to avoid public disclosure. A "trade secret" is oft the best defense.
     
  4. Brownout

    Thread Starter Well-Known Member

    Jan 10, 2012
    2,375
    998
    I didn't disclose because nobody showed any interest.
     
  5. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    I'm interested but only just seen this thread
     
  6. Brownout

    Thread Starter Well-Known Member

    Jan 10, 2012
    2,375
    998
    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.
     
Loading...