# Complex ActiveX Control Usage

**URL:** <https://forum.inductiveautomation.com/t/complex-activex-control-usage/2606>\
**Category:** Ignition\
**Created:** [February 4, 2011, 4:35am UTC](https://forum.inductiveautomation.com/t/complex-activex-control-usage/2606 "2011-02-04T04:35:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![todd.be](https://avatars.discourse-cdn.com/v4/letter/t/6f9a4e/32.png) [@todd.be](https://forum.inductiveautomation.com/u/todd.be)\
**Post date:** [February 4, 2011, 4:35am UTC](https://forum.inductiveautomation.com/t/complex-activex-control-usage/2606/1 "2011-02-04T04:35:15Z")

</div>

I have a third party ActiveX control that we would like to use in the HMI as it is used thoroughly in the company and having it in the HMI would be useful.

So the creation part part is easy with the ActiveX Module. The interface that the component exposes is fairly complex and has many child objects that return IDispatch pointers.

I realize this is probably going of into unsupported land but hoping this might be a softball.

The code I think should look something like the following:

[code]ax = event.source.parent.getComponent(‘Generic ActiveX Control’)  
print ax.getProperty(‘Color’, [])

plotvt = ax.getVariantProperty(‘Plot’, []) # plot is an IDispatchImpl property  
plot = ax.getAutomationObject(plotvt, [])  
print plot.getProperty(‘LineColor’)  
[/code]

The first part to get the Color property of the main control works fine. The subsequent call to get the object as a variant fails. Basically it returns “com.jniwrapper.win32.automation.impl.IDispatchImpl cannot be cast to com.jniwrapper.win32.automation.types.Variant”.

The Variant wrapper object should be able to create a variant to house the IDispatch pointer but is just trying to do a straight up cast which is not useful here. If I use ax.getProperty(‘Plot’,[]) it returns an IDispatchImpl but I cannot use that directly (well maybe with great pain) but that is what the Automation wrapper is for. I was hoping it would create a Variant to house it to call getAutomationObject with in this instance but no go.

Is it possible to import the jni wrapper libraries in jython to wrap the Automation or variant myself? Is there some other way to achieve this?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [February 4, 2011, 4:58pm UTC](https://forum.inductiveautomation.com/t/complex-activex-control-usage/2606/2 "2011-02-04T16:58:25Z")

</div>

The ActiveX component is a difficult one to wrap up into a component. You are calling getAutomationObject which is expecting a Variant. You need to use the Automation wrapper using IDispatch object. You can do the following:`import sys
sys.add_package("com.jniwrapper.win32.automation")
from com.jniwrapper.win32.automation import Automation
plotvt = ax.getVariantProperty('Plot', [])
automation = Automation(plotvt, 1)
automation.getProperty('LineColor')`Let me know if that works.

---

<div class="post-metadata">

**Author:** ![todd.be](https://avatars.discourse-cdn.com/v4/letter/t/6f9a4e/32.png) [@todd.be](https://forum.inductiveautomation.com/u/todd.be)\
**Post date:** [February 4, 2011, 10:02pm UTC](https://forum.inductiveautomation.com/t/complex-activex-control-usage/2606/3 "2011-02-04T22:02:17Z")

</div>

Yes that does it. The requirement to call add\_package was what was I needed. The working code looked like the following for reference.

`import sys
sys.add_package("com.jniwrapper.win32.automation")
from com.jniwrapper.win32.automation import Automation
print ax.getProperty('Color', [])
plot = Automation( ax.getProperty('Plot', []) )
lcvt = plot.getProperty('LineColor')
print lcvt.getUintVal()
`

Thanks for the help. I think I can get the rest working from here.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [February 4, 2011, 10:08pm UTC](https://forum.inductiveautomation.com/t/complex-activex-control-usage/2606/4 "2011-02-04T22:08:55Z")

</div>

Glad you got it working 🙂
