comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

.NET COM events using IDispatch are not handled

Open spynetcamera opened this issue 5 months ago • 4 comments

In C#, as a guideline, events are exposed by an IDispatch interface for late-binding only, by using the attribute [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)].

It seems like there's no way to sink those events, a code like follows:

class IEvents():
    def IEvents_OnResult(self, this, result):
        print(f"Event! {result}")

from comtypes.client import GetEvents
sink = IEvents()
connection = GetEvents(obj, sink)

will cause the error _ctypes.COMError: (-2147467263, 'Not implemented', ('The method or operation is not implemented.', 'mscorlib', None, 0, None))

Is there a way to handle this use case?

Thanks

spynetcamera avatar Sep 19 '25 08:09 spynetcamera

COM event handling is consistently one of the more challenging areas for this project. Moreover, dealing with event sinking through late-bind only interfaces adds significant complexity.

To help us investigate this issue further, would you be able to provide a minimal reproducer for the C# COM server and event you are using? This would be extremely helpful for isolating and debugging the problem.

junkmd avatar Oct 12 '25 05:10 junkmd

Hello, here's a demo project with some notes and Python scripts that may help. Please check FIXME tags. You can register with regasm DemoCOM.dll /codebase /tlb after build, sorry but binaries are not included because of email policies. Regards

Il giorno dom 12 ott 2025 alle ore 07:56 Jun Komoda < @.***> ha scritto:

junkmd left a comment (enthought/comtypes#873) https://github.com/enthought/comtypes/issues/873#issuecomment-3393961938

COM event handling is consistently one of the more challenging areas for this project. Moreover, dealing with event sinking through late-bind only interfaces adds significant complexity.

To help us investigate this issue further, would you be able to provide a minimal reproducer for the C# COM server and event you are using? This would be extremely helpful for isolating and debugging the problem.

— Reply to this email directly, view it on GitHub https://github.com/enthought/comtypes/issues/873#issuecomment-3393961938, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUCBQFSIFXC5POJRKGS6U7T3XHUQJAVCNFSM6AAAAACG6H5RR6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGOJTHE3DCOJTHA . You are receiving this because you authored the thread.Message ID: @.***>

spynetcamera avatar Oct 14 '25 21:10 spynetcamera

No file is attached. Could you share the files on your public repository?

junkmd avatar Oct 31 '25 23:10 junkmd

DemoCOM (NET Framework).zip

Here you go, I have attached to email and just realized it is not visible on GitHub.

spynetcamera avatar Nov 01 '25 20:11 spynetcamera