Complex ActiveX Control Usage

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?

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.

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.

Glad you got it working :slight_smile: