Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CNiTimer OnEvent function

Hello,

I use CNiTimer in CDialog class with CNiButton:

// .h
CMyDialog : public CDialog
{
public:
...
CNiTimer* pTimer;
CNiButton m_btnRed;

public:
//constructor,destructor,initdialog functions...
void OnEventTimer(CNitimer &timer);

}

// .cpp
void CMyDialog :: OnEventTimer(CNitimer &timer)
{
m_btnRed.EnableWindow(TRUE); --> OK
m_btnRed.SetValue(true); --> CNiOleError !!
}

When OnEventTimer is executing, "m_btnRed.SetValue" generate an error ?
Thanks.
0 Kudos
Message 1 of 2
(3,246 Views)
If you catch the exception and display the message, I suspect that you will see that CoInitialize has not been called from the thread. The timer calls your OnEventTimer from a worker thread. Because the Measurement Studio user interface controls are ActiveX controls, you must initialize COM from each thread that calls into them. Call CoInitialize or CoInitializeEx at the beginning of OnEventTimer to fix this problem.
0 Kudos
Message 2 of 2
(3,231 Views)