MCPcopy Create free account
hub / github.com/enthought/comtypes / FindOutgoingInterface

Function FindOutgoingInterface

comtypes/client/_events.py:113–150  ·  view source on GitHub ↗

XXX Describe the strategy that is used...

(source: IUnknown)

Source from the content-addressed store, hash-verified

111
112
113def FindOutgoingInterface(source: IUnknown) -> type[IUnknown]:
114 """XXX Describe the strategy that is used..."""
115 # If the COM object implements IProvideClassInfo2, it is easy to
116 # find the default outgoing interface.
117 try:
118 pci = source.QueryInterface(IProvideClassInfo2)
119 guid = pci.GetGUID(GUIDKIND_DEFAULT_SOURCE_DISP_IID)
120 except COMError:
121 pass
122 else:
123 # another try: block needed?
124 try:
125 interface = comtypes.com_interface_registry[str(guid)]
126 except KeyError:
127 tinfo = pci.GetClassInfo()
128 tlib, index = tinfo.GetContainingTypeLib()
129 GetModule(tlib)
130 interface = comtypes.com_interface_registry[str(guid)]
131 logger.debug("%s using sinkinterface %s", source, interface)
132 return interface
133
134 # If we can find the CLSID of the COM object, we can look for a
135 # registered outgoing interface (__clsid has been set by
136 # comtypes.client):
137 clsid = source.__dict__.get("__clsid")
138 try:
139 interface = comtypes.com_coclass_registry[clsid]._outgoing_interfaces_[0] # type: ignore
140 except KeyError:
141 pass
142 else:
143 logger.debug("%s using sinkinterface from clsid %s", source, interface)
144 return interface
145
146 # interface = find_single_connection_interface(source)
147 # if interface:
148 # return interface
149
150 raise TypeError("cannot determine source interface")
151
152
153def find_single_connection_interface(source):

Callers 1

GetEventsFunction · 0.85

Calls 7

GetModuleFunction · 0.90
GetClassInfoMethod · 0.80
GetContainingTypeLibMethod · 0.80
debugMethod · 0.80
getMethod · 0.80
QueryInterfaceMethod · 0.45
GetGUIDMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…