Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CW++ and Threads

I'm having trouble talking to my CW++ controls from a multithreaded environment. I don't know much about threads yet but if there are some things I should keep in mind when working with them and the CW++ toolset I would appreciate knowing.

I've read that Cwnd objects should be passed by HWND from one thread to another. Once I have my threads working the way I want how do I insert calls to say a graph without violating protocol?

Grant
Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 1 of 2
(3,452 Views)
There isn't really a simple answer to this question because of the fact that the Measurement Studio controls are ActiveX controls.

With ActiveX controls in MFC, you have two different sets of functions. One set of functions are those that are available via CWnd. If you want to call these functions from a worker thread, you have to obtain the CWnd's underlying HWND and pass the HWND to the worker thread. You can attach this HWND to a CWnd in the worker thread and you should be able to call all CWnd functions from the worker thread. You can access CWnd::m_hWnd to obtain a CWnd's underlying HWND. You can use CWnd::Attach to attach the HWND to the CWnd object in the worker thread.

The second set of functions are those that are available through the ActiveX control's
COM interface. To call these from a worker thread, you must first use COM marshaling to pass the interface between the threads. COM marshaling by itself is somewhat complicated. Furthermore, the CW++ classes use custom COM interfaces and so do not provide a way to attach an interface to the class once it is marshaled to another thread. If you REALLY have to do this, post a follow-up and we'll try to create some example code that shows how to do it through the control's underlying IDispatch interface.

We are addressing calling the controls from worker threads in the next version of Measurement Studio. The Measurement Studio C++ classes will handle the marshaling, thus allowing you to call the C++ methods (CNiGraph::PlotY, for example) from any thread. We currently do not plan to handle the CWnd functions, but you will still be able to do it as outlined above.

David Rohacek
National Instruments
Message 2 of 2
(3,452 Views)