Hi,
Attached is a module which contains a definition of the IServiceProvider
interface. This interface is provided as an interface on COM objects to
make it possible to switch to a different service, related to the
object. For example given an IAccessible (MSAA) object, you can use its
IServiceProvider interface to get to other things such as an
IHTMLElement (when dealing with MSHTML), or IAccessible2 etc.
Info on this interface can be found at:
http://msdn.microsoft.com/en-us/library/cc678965%28VS.85%29.aspx
IServiceProvider is defined in servprov.idl in the Microsoft Platform SDK.
A part from providing a standard comtypes definition of the interface, I
have also overridden the QueryService method, to be a little more
pythonic, so that you can pass an interface as the second argument,
rather than just an IID, and then it actually returns an instance of
that interface, rather than just an IUnknown pointer.
I propose that this module (servprov.py) be added to comtypes, so that
others can make use of this, rather than having to code the definition
manually.
Note also that IServiceProvider is not included in any standard type
library that I know of, so defining this interface specifically is the
only way to use it.
Hopefully I have formatted the file suitably for inclusion.
Thanks
Mick
# -*- coding: mbcs -*-
from ctypes import *
from comtypes import *
class IServiceProvider(IUnknown):
_case_insensitive_ = True
_iid_ = GUID('{6D5140C1-7436-11CE-8034-00AA006009FA}')
_idlflags_ = []
#Overridden QueryService to make it nicer to use (passing it an interface
and it returns a pointer to that interface)
def QueryService(self,serviceIID,interface):
if not issubclass(interface,IUnknown):
raise ValueError("interface argument must be a COM interface")
interfaceIID=interface._iid_
if not isinstance(serviceIID,GUID):
raise ValueError("serviceIID argument must be a GUID")
p=self._QueryService(byref(serviceIID),byref(interfaceIID))
return POINTER(interface)(p)
IServiceProvider._methods_ = [
COMMETHOD([], HRESULT, 'QueryService',
( ['in'], POINTER(GUID), 'guidService' ),
( ['in'], POINTER(GUID), 'riid' ),
( ['out'], POINTER(c_void_p), 'ppvObject' )),
COMMETHOD([], HRESULT, 'RemoteQueryService',
( ['in'], POINTER(GUID), 'guidService' ),
( ['in'], POINTER(GUID), 'riid' ),
( ['out'], POINTER(POINTER(IUnknown)), 'ppvObject' )),
]
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users