Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CNi Object in thread is it possible ???

Hello, I'm using CreatThread in a visual application, and I pass the "this" pointer to the thread. But when I want to access to a CNi object like Knob or Button, created in my view, a abnormal program termination occured.

void ThreadPortique(LPVOID param)
{
((CStation4View *)param)->m_ledConnect2.SetValue(true);
}


First :Could I do this kind of thinks;
Second :If yes....How ????
0 Kudos
Message 1 of 2
(2,942 Views)
If you catch the exception thrown by SetValue and display the message, I suspect you will find that you have not called ::CoInitialize in the thread. This is likely the cause of the problem. At the beginning of your thread callback, add a call to ::CoInitialize(NULL) and at the end of the callback, add a call to ::CoUninitialize(). This should do the trick.

Underneath, the Measurement Studio UI controls are ActiveX controls. This means that you must initialize COM in every thread that accesses them. Unfortunately we cannot do this for you automatically because we do not have a way to properly clean up.

David Rohacek
National Instruments
0 Kudos
Message 2 of 2
(2,942 Views)