Jump to content

What's the next step after "QueryInterface"


timepp
 Share

Recommended Posts

I already have a COM object. I want to query another interface and call method from that interface. I expect something like this:

Local $pp
$app.QueryInterface($tRIID_IServiceProvider, $pp)
Bind($pp, $dtag_IServiceProvider)
$pp.QueryService(...)

in line 3, I want to bind a vtable to this variable (or something similar) but currently there seems no such mechanism.

or something like this:

Local $pp = QueryInterface($app, $tRIID_IServiceProvider, $dtag_IServiceProvider)
$pp.QueryService(...)

but no such thing either.

 

The only workable solution I know is the following:

Local $pp
$app.QueryInterface($tRIID_IServiceProvider, $pp)
Local $provider = ObjCreateInterface($pp, $sIID_IServiceProvider, $dtag_IServiceProvider)
$provider.QueryService(...)

but apparently there is a duplication for IID_IServiceProvider, which violates the DRY(don't repeat yourself) principle.

Is there any other better solution?

Link to comment
Share on other sites

This should work.

Local $pIServiceProvider, $oIServiceProvider
  $oIWebBrowserApp.QueryInterface( $tRIID_IServiceProvider, $pIServiceProvider )
  $oIServiceProvider = ObjCreateInterface( $pIServiceProvider, $sIID_IServiceProvider, $dtag_IServiceProvider )

Saludos

Link to comment
Share on other sites

BTW, I don't know why the following code can't work:

Local $provider = ObjCreateInterface($app, $sIID_IServiceProvider, $dtag_IServiceProvider)

can anyone explain to me why?

It should be:

$app.AddRef() ; needed depending on implementation of $app. Usually documented somewhere
Local $provider = ObjCreateInterface($app(), $sIID_IServiceProvider, $dtag_IServiceProvider)

... or what Danyfirex said.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...