Marged
Marged

Reputation: 10963

Use JNA to CreateObject of a COM object I have no .class for

I have seen examples like this

MsWordApp comObj = this.factory.createObject(MsWordApp.class);

in other questions here on SO.

My problem is that I need to create an object like it is done in a vbscript example:

Set tdc = CreateObject("TDApiOle80.TDConnection")

In this Scenario the createObject would need to process a String, not a class. How can I translate this vbscript to Java / JNA ?

Upvotes: 1

Views: 1011

Answers (1)

acelent
acelent

Reputation: 8135

VBScript's CreateObject is essentially CLSIDFromProgID followed by CoCreateInstance, with error handling.

VBScript always uses late binding, so you're interested in IDispatch support.

It seems JNA provides this through COMBindingBaseObject:

new COMBindingBaseObject("TDApiOle80.TDConnection", false)

Then, use the provided IDispatch to invoke methods and get or set properties.

Reference.

Upvotes: 2

Related Questions