Skip to content

Commit

Permalink
Add the QueryInterface doctest.
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd committed Dec 28, 2024
1 parent 4c4dd78 commit 89305f0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/source/com_interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ The ``IUnknown`` as a Python class
of ``-2147467262`` (``E_NOINTERFACE``, ``'0x80004002'`` in
signed-32bit hex)

.. doctest::

>>> from comtypes.client import CreateObject, GetModule
>>> from comtypes import IUnknown
>>> from comtypes.automation import IDispatch
>>> GetModule('scrrun.dll') # doctest: +ELLIPSIS
<module 'comtypes.gen.Scripting' from ...>
>>> from comtypes.gen import Scripting
>>> dic = CreateObject(Scripting.Dictionary)
>>> dic # doctest: +ELLIPSIS
<POINTER(IDictionary) ptr=... at ...>
>>> dic.QueryInterface(IDispatch) # doctest: +ELLIPSIS
<POINTER(IDispatch) ptr=... at ...>
>>> dic.QueryInterface(IUnknown) # doctest: +ELLIPSIS
<POINTER(IUnknown) ptr=... at ...>
>>> dic.QueryInterface(Scripting.IFileSystem) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
_ctypes.COMError: (-2147467262, ..., (None, None, None, 0, None))

.. py:method:: Add()
This wraps the `IUnknown::AddRef <https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-addref>`_.
Expand Down

0 comments on commit 89305f0

Please sign in to comment.