03-20-2014 08:46 AM
Hi,
I have problem about how to activate an activeX control in teststand. I created a c# form dll which has an activeX control. In teststand, i created an object for that form and want to use the functions in that dll. But i find that if i do not run that form, the activeX control can not be activated by only createing an object for that form. in fact, i do not want to run that form.
I wonder someone may help me to solve this problem. Thanks in advance!
SIda
03-21-2014 10:30 AM - edited 03-21-2014 10:34 AM
I'm assuming you are already running in an STA thread. If so, just create a hidden form that hosts the activex control. You don't have to ever make the form visible, just create it. Most ActiveX controls expect to be hosted on an ActiveX container, so there is likely no other way than this. The ActiveX container itself though can be hidden, so no one will ever see or be able to interact with the control (which sounds like what you want).
You might need to call CreateHandle() or CreateControl() on the form, though I'm not sure about this.
Hope this helps,
-Doug
03-24-2014 12:22 PM
Thanks for your help.
I tried create control(), but it does not work as you have to activate on the form. i use application.run() to run the hide form but it always runs and i do not know how to stop it...
03-25-2014 04:44 PM
System.Windows.Forms.Form hiddenForm = new System.Windows.Forms.Form(); MyNamespace.Ax.AxMyClass myobject = new MyNamespace.Ax.AxMyClass(); ((System.ComponentModel.ISupportInitialize)(myobject)).BeginInit(); hiddenForm.Controls.Add(myobject); ((System.ComponentModel.ISupportInitialize)(myobject)).EndInit();
I think the above should work.
-Doug