XXX Describe the strategy that is used...
(source: IUnknown)
| 111 | |
| 112 | |
| 113 | def 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 | |
| 153 | def find_single_connection_interface(source): |
no test coverage detected
searching dependent graphs…