7
7
from ctypes import *
8
8
from ctypes import _Pointer
9
9
from _ctypes import CopyComPointer
10
- from comtypes import IUnknown , GUID , IID , STDMETHOD , BSTR , COMMETHOD , COMError
10
+ from comtypes import (
11
+ BSTR , COMError , COMMETHOD , GUID , IID , IUnknown , STDMETHOD , TYPE_CHECKING ,
12
+ )
11
13
from comtypes .hresult import *
12
14
import comtypes .patcher
13
15
import comtypes
@@ -19,6 +21,12 @@ class _safearray(object):
19
21
20
22
from ctypes .wintypes import DWORD , LONG , UINT , VARIANT_BOOL , WCHAR , WORD
21
23
24
+ if TYPE_CHECKING :
25
+ from typing import (
26
+ Any , Callable , ClassVar , List , Optional , Tuple , Union as _UnionT ,
27
+ )
28
+ from comtypes import hints
29
+
22
30
23
31
if sys .version_info >= (3 , 0 ):
24
32
int_types = (int , )
@@ -149,6 +157,13 @@ def as_decimal(self):
149
157
# The VARIANT structure is a good candidate for implementation in a C
150
158
# helper extension. At least the get/set methods.
151
159
class tagVARIANT (Structure ):
160
+ if TYPE_CHECKING :
161
+ vt = hints .AnnoField () # type: int
162
+ _ = hints .AnnoField () # type: U_VARIANT1.__tagVARIANT.U_VARIANT2
163
+ null = hints .AnnoField () # type: ClassVar[VARIANT]
164
+ empty = hints .AnnoField () # type: ClassVar[VARIANT]
165
+ missing = hints .AnnoField () # type: ClassVar[VARIANT]
166
+
152
167
class U_VARIANT1 (Union ):
153
168
class __tagVARIANT (Structure ):
154
169
# The C Header file defn of VARIANT is much more complicated, but
@@ -650,6 +665,17 @@ def Next(self, celt):
650
665
651
666
652
667
class tagEXCEPINFO (Structure ):
668
+ if TYPE_CHECKING :
669
+ wCode = hints .AnnoField () # type: int
670
+ wReserved = hints .AnnoField () # type: int
671
+ bstrSource = hints .AnnoField () # type: str
672
+ bstrDescription = hints .AnnoField () # type: str
673
+ bstrHelpFile = hints .AnnoField () # type: str
674
+ dwHelpContext = hints .AnnoField () # type: int
675
+ pvReserved = hints .AnnoField () # type: Optional[int]
676
+ pfnDeferredFillIn = hints .AnnoField () # type: Optional[int]
677
+ scode = hints .AnnoField () # type: int
678
+
653
679
def __repr__ (self ):
654
680
return "<EXCEPINFO %s>" % \
655
681
((self .wCode , self .bstrSource , self .bstrDescription , self .bstrHelpFile , self .dwHelpContext ,
@@ -669,6 +695,11 @@ def __repr__(self):
669
695
EXCEPINFO = tagEXCEPINFO
670
696
671
697
class tagDISPPARAMS (Structure ):
698
+ if TYPE_CHECKING :
699
+ rgvarg = hints .AnnoField () # type: Array[VARIANT]
700
+ rgdispidNamedArgs = hints .AnnoField () # type: _Pointer[DISPID]
701
+ cArgs = hints .AnnoField () # type: int
702
+ cNamedArgs = hints .AnnoField () # type: int
672
703
_fields_ = [
673
704
# C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 696
674
705
('rgvarg' , POINTER (VARIANTARG )),
@@ -691,17 +722,39 @@ def __del__(self):
691
722
DISPID_DESTRUCTOR = - 7
692
723
DISPID_COLLECT = - 8
693
724
725
+
726
+ if TYPE_CHECKING :
727
+ RawGetIDsOfNamesFunc = Callable [
728
+ [_byref_type , Array [c_wchar_p ], int , int , Array [DISPID ]], int ,
729
+ ]
730
+ RawInvokeFunc = Callable [
731
+ [
732
+ int , _byref_type , int , int , # dispIdMember, riid, lcid, wFlags
733
+ _UnionT [_byref_type , DISPPARAMS ], # *pDispParams
734
+ _UnionT [_byref_type , VARIANT ], # pVarResult
735
+ _UnionT [_byref_type , EXCEPINFO , None ], # pExcepInfo
736
+ _UnionT [_byref_type , c_uint ], # puArgErr
737
+ ],
738
+ int
739
+ ]
740
+
694
741
class IDispatch (IUnknown ):
742
+ if TYPE_CHECKING :
743
+ _disp_methods_ = hints .AnnoField () # type: ClassVar[List[comtypes._DispMemberSpec]]
744
+ _GetTypeInfo = hints .AnnoField () # type: Callable[[int, int], IUnknown]
745
+ __com_GetIDsOfNames = hints .AnnoField () # type: RawGetIDsOfNamesFunc
746
+ __com_Invoke = hints .AnnoField () # type: RawInvokeFunc
747
+
695
748
_iid_ = GUID ("{00020400-0000-0000-C000-000000000046}" )
696
749
_methods_ = [
697
750
COMMETHOD ([], HRESULT , 'GetTypeInfoCount' ,
698
751
(['out' ], POINTER (UINT ) ) ),
699
752
COMMETHOD ([], HRESULT , 'GetTypeInfo' ,
700
753
(['in' ], UINT , 'index' ),
701
754
(['in' ], LCID , 'lcid' , 0 ),
702
- # # Normally, we would declare this parameter in this way:
703
- ## (['out'], POINTER(POINTER(ITypeInfo)) ) ),
704
- # # but we cannot import comtypes.typeinfo at the top level (recursive imports!).
755
+ # Normally, we would declare this parameter in this way:
756
+ # (['out'], POINTER(POINTER(ITypeInfo)) ) ),
757
+ # but we cannot import comtypes.typeinfo at the top level (recursive imports!).
705
758
(['out' ], POINTER (POINTER (IUnknown )) ) ),
706
759
STDMETHOD (HRESULT , 'GetIDsOfNames' , [POINTER (IID ), POINTER (c_wchar_p ),
707
760
UINT , LCID , POINTER (DISPID )]),
@@ -711,12 +764,14 @@ class IDispatch(IUnknown):
711
764
]
712
765
713
766
def GetTypeInfo (self , index , lcid = 0 ):
767
+ # type: (int, int) -> hints.ITypeInfo
714
768
"""Return type information. Index 0 specifies typeinfo for IDispatch"""
715
769
import comtypes .typeinfo
716
770
result = self ._GetTypeInfo (index , lcid )
717
771
return result .QueryInterface (comtypes .typeinfo .ITypeInfo )
718
772
719
773
def GetIDsOfNames (self , * names , ** kw ):
774
+ # type: (str, Any) -> List[int]
720
775
"""Map string names to integer ids."""
721
776
lcid = kw .pop ("lcid" , 0 )
722
777
assert not kw
@@ -726,6 +781,7 @@ def GetIDsOfNames(self, *names, **kw):
726
781
return ids [:]
727
782
728
783
def _invoke (self , memid , invkind , lcid , * args ):
784
+ # type: (int, int, int, Any) -> Any
729
785
var = VARIANT ()
730
786
argerr = c_uint ()
731
787
dp = DISPPARAMS ()
@@ -747,6 +803,7 @@ def _invoke(self, memid, invkind, lcid, *args):
747
803
return var ._get_value (dynamic = True )
748
804
749
805
def Invoke (self , dispid , * args , ** kw ):
806
+ # type: (int, Any, Any) -> Any
750
807
"""Invoke a method or property."""
751
808
752
809
# Memory management in Dispatch::Invoke calls:
0 commit comments