Skip to content

Commit 181d249

Browse files
committed
feat: Handle GUID_NULL for outgoing interface IID in FindOutgoingInterface.
When `IProvideClassInfo2` returns `GUID_NULL` as the outgoing interface IID, `FindOutgoingInterface` now raises a `NotImplementedError`. This addresses cases where some COM servers (like `htmlfile`) return a null GUID instead of the default source interface's GUID. A new test case `test_retrieved_outgoing_iid_is_guid_null` has been added to `test_eventinterface.py` to verify this behavior.
1 parent 2706fe3 commit 181d249

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

comtypes/client/_events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def FindOutgoingInterface(source: IUnknown) -> type[IUnknown]:
120120
except COMError:
121121
pass
122122
else:
123+
if guid == comtypes.GUID():
124+
raise NotImplementedError("retrieved outgoing interface IID is GUID_NULL")
123125
# another try: block needed?
124126
try:
125127
interface = comtypes.com_interface_registry[str(guid)]

comtypes/test/test_eventinterface.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,13 @@ def test_nondefault_eventinterface(self):
112112

113113

114114
class Test_MSHTML(ut.TestCase):
115-
def test(self):
115+
def test_retrieved_outgoing_iid_is_guid_null(self):
116116
doc = CreateObject("htmlfile")
117117
sink = object()
118118
# MSHTML's HTMLDocument (which is what `CreateObject('htmlfile')`
119119
# returns) does not expose a valid default source interface through
120120
# `IProvideClassInfo2`.
121-
# Specifically, it returns `GUID_NULL` as its default source interface,
122-
# which results in a `KeyError` when `GetEvents` tries to look it up in
123-
# the interface registry.
124-
with self.assertRaises(KeyError, msg="{00000000-0000-0000-0000-000000000000}"):
121+
with self.assertRaises(NotImplementedError):
125122
GetEvents(doc, sink)
126123

127124

0 commit comments

Comments
 (0)