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 ?

2
  • 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 Commented Oct 27, 2017 at 11:04
  • You could perhaps generate some Java class source codes and compile on the fly. Commented Oct 27, 2017 at 11:10

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.