1

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 ?

Marged
  • 10,577
  • 10
  • 57
  • 99
  • 1
    Java can't create an object it doesn't know, so if you don't have .class, then you can not create the object – Lino Oct 27 '17 at 11:04
  • You could perhaps generate some Java class source codes and compile on the fly. – Vlasec Oct 27 '17 at 11:10

1 Answers1

2

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.

acelent
  • 7,965
  • 21
  • 39