diff --git a/CHANGES.txt b/CHANGES.txt index f0c965f157..ad85e5d420 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -13,8 +13,9 @@ https://mhammond.github.io/pywin32_installers.html . Coming in build 310, as yet unreleased -------------------------------------- -* Drop support for Vista, set Windows 7 as the minimal Windows version. (#, @Avasam) - * Restores many IIDs in `win32com(ext).shell.shell`. See #2486 for details. +* Fixed a regression where `win32com.client.DispatchWithEvents` and win32com.client.WithEvents` would throw a `TypeError` on the second call (#2491, @Avasam) +* Dropped support for Vista, set Windows 7 as the minimal Windows version. (#2487, @Avasam) +* Restored many IIDs in `win32com(ext).shell.shell`. See #2486 for details. (#2487, @Avasam) Build 309, released 2025/03/09 ------------------------------ diff --git a/com/win32com/client/__init__.py b/com/win32com/client/__init__.py index d1e84e09c0..ae879590b5 100644 --- a/com/win32com/client/__init__.py +++ b/com/win32com/client/__init__.py @@ -269,23 +269,24 @@ def __get_disp_and_event_classes(dispatch): disp = Dispatch(dispatch) if disp.__class__.__dict__.get("CLSID"): - return disp.__class__ + disp_class = disp.__class__ + else: + # Eeek - no makepy support - try and build it. + error_msg = "This COM object can not automate the makepy process - please run makepy manually for this object" + try: + ti = disp._oleobj_.GetTypeInfo() + disp_clsid = ti.GetTypeAttr()[0] + tlb, index = ti.GetContainingTypeLib() + tla = tlb.GetLibAttr() + gencache.EnsureModule(tla[0], tla[1], tla[3], tla[4], bValidateFile=0) + # Get the class from the module. + disp_class = gencache.GetClassForProgID(str(disp_clsid)) + except pythoncom.com_error as error: + raise TypeError(error_msg) from error + + if disp_class is None: + raise TypeError(error_msg) - # Eeek - no makepy support - try and build it. - error_msg = "This COM object can not automate the makepy process - please run makepy manually for this object" - try: - ti = disp._oleobj_.GetTypeInfo() - disp_clsid = ti.GetTypeAttr()[0] - tlb, index = ti.GetContainingTypeLib() - tla = tlb.GetLibAttr() - gencache.EnsureModule(tla[0], tla[1], tla[3], tla[4], bValidateFile=0) - # Get the class from the module. - disp_class = gencache.GetClassForProgID(str(disp_clsid)) - except pythoncom.com_error as error: - raise TypeError(error_msg) from error - - if disp_class is None: - raise TypeError(error_msg) # Get the clsid clsid = disp_class.CLSID # Create a new class that derives from 2 classes: @@ -333,7 +334,6 @@ class object that derives from three classes: >>> ie = DispatchWithEvents("InternetExplorer.Application", IEEvents) >>> ie.Visible = 1 Visible changed: 1 - >>> """ disp, disp_class, events_class = __get_disp_and_event_classes(clsid) result_class = type(