LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand calls CVI-dll with ActiveX Control with wrong thread-style

Hello,
 
I am trying to create a step type for TestStand, that popups a CVI-panel (.uir) with some text and graphics.
If a certain parameter is passed to the cvi-dll (that shows the popup) an ActiveX Control should be placed on that panel.
 
Everything works fine, except the ActiveX Control. I get error -143(CVI-error), -2147467259 (WIN-error) each time when I try to create that panel with
NewActiveXCtrl on the panel.
 
By putting the ActiveX Control code in an executable, I do not get this error, so the code should work somehow.
 
As far as I know TestStand calls its modules multi-threaded (MTA), but an ActiveX Control needs to be in a single-threaded apartment (STA).
I have already found the ...\National Instruments\TestStand 3.1\Examples\MFCActiveXContainerDlg example, that shows how to
call a moudle in STA using a sequence call, but the step type is going to used very often in my sequence and I don't want to complicate my sequence with unnecessary sequence calls. Besides I want the panel to be executed in a separate thread in order to have the possibility to let the panel exist longer than the duration of a single TestStand step.
 
To summarize the above: I need a dll that can be called multi-threaded from TestStand and handles a ActiveX Control in single-threaded apartment.
 
I have already tried to start a new thread out of my dll with:
 
   CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, (ThreadFunctionPtr)CreateWActiveXCtrl, &panel, NULL);            
 
   int CVICALLBACK CreateActiveXCtrl(int *panel)
   {
   ..
   }
 
but without any success and the same error messages from above.
 
When I try to set the thread with:
 
  CA_InitActiveXThreadStyleForCurrentThread (0, COINIT_APARTMENTTHREADED)    
 
I can't change the thread-style because it was already set when called by TestStand to MTA and moreover I just want to set the thread of the ActiveXCtrl to STA and not the other parts of the DLL.
 
Does someone has a solution?
 
Mathias
 
 
 
 

Message Edited by MaWie on 10-31-2005 03:50 AM

Message Edited by MaWie on 10-31-2005 03:52 AM

0 Kudos
Message 1 of 3
(3,402 Views)

Mathias,

I think you should be able to call CA_InitActiveXThreadStyleForCurrentThread and set the thread style to STA in your thread function and it should work.  If you do not set the thread style, then it will default to MTA.  You need to make sure that your application is not using the default thread pool for anything else that would cause the threads in that pool to be MTA.

If you can't get the default thread pool to work for some reason, you could create your own thread pool.  You call CmtNewThreadPool to create the new thread pool and you call CmtInstallThreadPoolCallback with EVENT_TP_THREAD_BEGIN to setup a thread pool callback that will be called by each newly created thread in that thread pool.  You could use this callback to initialize each new thread in the thread pool to STA.

Hope this helps.

-Jeff

Message 2 of 3
(3,360 Views)
Jeff,
 
thanks for your help.
 
It works the way you have described it, with one restriciton:
 
The ActiveX Control needs to be created (NewActiveXCtrl) in a separate panel (NewPanel) that belongs to the STA thread of the ActiveXControl. If I try to make this new panel a child of my main panel, I will get error -129 (UIEMustBeInTopLevelPanelThread).
 
Even with SetPanel (SDK) it doesn't work and the application hangs.
 
I will open a new message thread for this topic.
 
Mathias
0 Kudos
Message 3 of 3
(3,333 Views)