Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd committed May 28, 2024
1 parent 4a437ea commit 9880f6b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
23 changes: 11 additions & 12 deletions comtypes/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,7 @@ def _set_value(self, value):
memmove(byref(self._), byref(obj), sizeof(obj))
self.vt = VT_ARRAY | obj._vartype_
elif isinstance(value, Structure) and hasattr(value, "_recordinfo_"):
guids = value._recordinfo_
from comtypes.typeinfo import GetRecordInfoFromGuids

ri = GetRecordInfoFromGuids(*guids)
ri = _get_recordinfo(value) # type: ignore
self.vt = VT_RECORD
# Assigning a COM pointer to a structure field does NOT
# call AddRef(), have to call it manually:
Expand Down Expand Up @@ -394,10 +391,7 @@ def _set_value(self, value):
self._.c_void_p = addressof(ref)
self.__keepref = value
if isinstance(ref, Structure) and hasattr(ref, "_recordinfo_"):
guids = ref._recordinfo_
from comtypes.typeinfo import GetRecordInfoFromGuids

ri = GetRecordInfoFromGuids(*guids)
ri = _get_recordinfo(ref) # type: ignore
self.vt = VT_RECORD | VT_BYREF
# Assigning a COM pointer to a structure field does NOT
# call AddRef(), have to call it manually:
Expand All @@ -411,10 +405,7 @@ def _set_value(self, value):
self._.c_void_p = addressof(ref)
self.__keepref = value
if isinstance(ref, Structure) and hasattr(ref, "_recordinfo_"):
guids = ref._recordinfo_
from comtypes.typeinfo import GetRecordInfoFromGuids

ri = GetRecordInfoFromGuids(*guids)
ri = _get_recordinfo(ref) # type: ignore
self.vt = VT_RECORD | VT_BYREF
# Assigning a COM pointer to a structure field does NOT
# call AddRef(), have to call it manually:
Expand Down Expand Up @@ -603,6 +594,14 @@ def ChangeType(self, typecode):
del v

_carg_obj = type(byref(c_int()))


def _get_recordinfo(struct: "hints.HasSinderRecordInfo") -> "hints.IRecordInfo":
from comtypes.typeinfo import GetRecordInfoFromGuids

return GetRecordInfoFromGuids(*struct._recordinfo_)


from ctypes import Array as _CArrayType


Expand Down
13 changes: 12 additions & 1 deletion comtypes/hints.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ else:
import comtypes
from comtypes.automation import IDispatch as IDispatch, VARIANT as VARIANT
from comtypes.server import IClassFactory as IClassFactory
from comtypes.typeinfo import ITypeInfo as ITypeInfo
from comtypes.typeinfo import ITypeInfo as ITypeInfo, IRecordInfo as IRecordInfo

Incomplete: TypeAlias = Any
"""The type symbol is used temporarily until the COM library parsers or
Expand All @@ -61,6 +61,17 @@ class FirstComItfOf(Generic[_T_coclass]):
as an argument.
"""

class HasSinderRecordInfo(Protocol):
_recordinfo_: Tuple[str, int, int, int, str]
"""
A fixed-length array composed of five elements:
- Type library GUID string
- Major version number of the type library
- Minor version number of the type library
- Language code ID number
- Type information GUID string
"""

class _MethodTypeDesc(Protocol):
arguments: List[Tuple[Any, str, List[str], Optional[Any]]]
idlflags: List[str]
Expand Down
5 changes: 5 additions & 0 deletions comtypes/typeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,11 @@ def GetFieldNames(self, *args: Any) -> List[Optional[str]]:
# XXX Should SysFreeString the array contents. How to?
return result

if TYPE_CHECKING:

def RecordCreateCopy(self, pvSource: Any) -> Optional[int]:
...


IRecordInfo._methods_ = [
COMMETHOD([], HRESULT, "RecordInit", (["in"], c_void_p, "pvNew")),
Expand Down

0 comments on commit 9880f6b

Please sign in to comment.