I'm facing a problem that makes me nearly going nuts
I have a javascript in an HTA that must call some COM objects
var com1= new ActiveXObject("progID");
It works fine for nearly all the COM objects, excepted a COM object that implements 2 interfaces IComOne and IComTwo
Is there a way to "cast" the com1 object in order to tell him to use only "IComOne" interface ?
I'd be grateful for any su开发者_运维技巧ggestion...
It's been a few years since I last had to play with script and COM, but I thought script could only invoke methods offered up by the IDispatch interface. If your component doesn't support this, you can't use it. It's not like you can call IUnknown.AddRef on any object, for example.
You can get more insight into your component using the OLE/COM object viewer utility of the Windows SDK.
First, if both interfaces are dual then there are multiple implementations of IDispatch
-- one for each interface, i.e. QI for IDispatch
on IComOne
!= QI for IDispatch
on IComTwo
.
com1
will point IDispatch
impl on the default interface (say IComOne
). One way to get IDispatch
impl on IComTwo
is if there is a method on IComOne
that casts self to IComTwo
(QI for IDispatch
on retval happens automagically). So var com1 = ...
then var com2 = com1.GetSecondInterface()
.
You could make a "casting helper" to do this too, if "progID" is closed external component.
精彩评论