NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a dll from Teststand that uses ActiveX controls

I have a sequence file that calls a dll (ActiveX Automation server written in C#). The dll displays a GUI that has an ActiveX graph. I get the error message that the ActiveX can not be instantiated because it is not a single threaded apartment. I added the following code to change from MTA to STA.

Thread.CurrentThread.ApartmentState = ApartmentState.STA;

This has no effect in the code; if I check ApartmentState it is still MTA. Apparently, TestStand sets to MTA and by the time my dll is called it is to late to change. Is there some way to change thead state in Teststand (sequence editor)?

Thank You,
Philip
0 Kudos
Message 1 of 4
(3,448 Views)
Hi
All TS threads coInitilized as MTA.

To work around this have a look at this example below

"DLL Works When Called outside of TestStand but Not When Called from TestStand"


http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/ad46b130ba24bb5c86256b8100689612?OpenDocument
Message 2 of 4
(3,448 Views)
Thank you, Anand

I created an executable that TestStand calls. Inside the executable I set the Apartment Threading and then call my dll. It works fine.

I'm still not clear why I can't change the Apartment threading inside my dll yet I can change it inside the executable.

Thanks again,
Philip
0 Kudos
Message 3 of 4
(3,448 Views)
Philip -
Once a thread is defined to be MTA or STA you cannot change it because this is the way Microsoft has defined its COM interface. TestStand initializes its execution threads as MTA for many reasons, but mainly for speed. Because the execution threads are MTA, we do not have to worry about marshalling ActiveX pointers between threads with special code. This allows the sharing of pointers between threads and allows user code modules to do the same without any extra code. The one side affect is that ActiveX controls must be hosted in a separate STA thread.

Scott Richardson (NI)
Scott Richardson
https://testeract.com
0 Kudos
Message 4 of 4
(3,448 Views)