11-03-2005 03:45 AM
Hello,
I have TestStand sequence that calls an CVI-dll, that displays some text, graphics and has a few buttons.
TestStand calls this DLL in MTA by default.
In order to display an ActiveX Control on the DLLs mainpanel, I create a new thread pool inside this DLL and open a new thread in STA containing a panel with the mentioned ActiveX Control.
So far it works well, as long as both panels (the MTA-panel and the ActiveX Control STA panel) exist separately. (Two panels on different positions on the screen).
But actually I don’t want the AxtiveX Control panel to be separated from the mainpanel, so I have tried to make it a child of the mainpanel with SetParent (from SDK), called with PostDeferredCallToThread in a Callback. In fact it works but only until the mainpanel reaches RunUserInterface(). At this point the whole application hangs (including TestStand).
This is what I have done:
mainpanel:
{
...
mainthreadID = CmtGetCurrentThreadID ();
CmtNewThreadPool (50, &poolHandle);
CmtScheduleThreadPoolFunction (poolHandle, (ThreadFunctionPtr)CreateActiveXCtrl, 0,
&threadID);
...
RunUserInterface()
...
}
ActiveXControl panel:
int CVICALLBACK CreateActiveXCtrl(....)
{
...
CA_InitActiveXThreadStyleForCurrentThread (0, COINIT_APARTMENTTHREADED);
...
pHandle = NewPanel (...);
NewActiveXCtrl(...);
...
PostDeferredCallToThread ((DeferredCallbackPtr)MakeChildPanel,0, mainthreadID);
...
}
void CVICALLBACK MakeChildPanel (void *callbackData)
{
SetParent((HWND)actXPanel, (HWND)mainPanel);
}
Does somebody have an idea how to solve this case? And what’s the reason for this behaviour?
It would be also fine to include the ActiveXControl directly to the mainpanel, but I guess it doen't work because of the mainpanel being in MTA!?!
Mathias
11-08-2005 05:40 PM
Mathias,
First, the CVI user interface library is not designed to work in conjunction with the Windows SDK. Some SDK functionality will work OK, but there are many ways that SDK functions can interact with the CVI user interface library that will cause problems, crashes, hangs, etc. It is not suprising that your call to SetParent caused problems. You should use the 'Parent Panel Handle' parameter of NewPanel or LoadPanel to setup the parent/child relationship between your panels.
Second, the CVI user interface library requires that parent panels and child panels be created in the same thread. This is stated in the CVI help in the following topic:
Library Reference>>User Interface Library>>Multithreading>>Multithreading Restrictions>>Panels and Multithreading