Providing IServiceProvider.QueryService to third party AX controls...

  • Thread starter Thread starter Nathan Baulch
  • Start date Start date
N

Nathan Baulch

I need to use a third party database Activex control that uses the
IServiceProvider (aka IOleServiceProvider) interface to get an instance of
the application API object.
It uses this API object to get an OleDb connection string so that it can
interact with a database.

What is the best way to hook into the IServiceProvider.QueryService OLE
mechanism in .net?

As far as I understand, when the third party control receives an
IOleClientSite instance via the IOleObject.SetClientSite method, it casts it
to IServiceProvider and if not null, asks for the API object via the
QueryService method.

I have successfully cast the control to an IOleObject and passed my own
instance of IOleClientSite (which also implements IServiceProvider), but
none of the methods are being called.

((IOleObject) thirdPartyControl1.GetOcx()).SetClientSite(new
MyTestClientSite());

For all I know, a different IOleClientSite is being given shortly after
mine, or perhaps it's just a problem with the sequence of events. I really
have no idea why it's not working.


I also tried to use reflection to manually call
Control.ActiveXInstance.SetClientSite(), but it kept complaining that my
custom IOleClientSite implementation couldn't be cast correctly. This
probably makes sense since it is expecting a
UnsafeNativeMethods.IOleClientSite but actaully getting a
WindowsApplication1.IOleClientSite (even though mine has ComImport and the
same Guid).


Nathan
 
Back
Top