Sunday, January 17, 2010

How can I programmatically inspect an ActiveXObject at runtime, using Javascript?

I am looking to create a Javascript library for ActiveX objects, enabling chainability.

Answers

Only objects that implement IDispatchEx can be inspected at runtime. MSDN specifically lists the differences between IDispatch and IDispatchEx:

IDispatchEx was developed to provide all the services of IDispatch as well as some extensions that are appropriate for more dynamic late-bound languages such as scripting languages. The additional features of IDispatchEx beyond those provided by IDispatch are:

Add new members to an object ("expando").

Delete members of an object.

Case-sensitive dispatch operations.

Search for member with implicit name.

Enumerate DISPIDs of an object.

Map from DISPID to element name.

Obtain properties of object members.

Method invocation with this pointer.

Allow browsers that support the concept of name spaces to obtain the name space parent of an object.

I've made bold the relevant issue.

As Eric points out in the comments, you can use enumerate the members of the objects using foreach (or for...in perhaps?), but I'm not sure, from the question, what you specifically want to do.

Since not all ActiveX controls will implement IDispatchEx (or may not implement all methods of IDispatchEx properly or completely), are there specific controls you're looking to play with?

More details will lead to better answers.

No comments:

Post a Comment