Due to a failed assertion when parsing a typelib (PortableDeviceApi), I suggest the following changes:
In comtypes/automation.py, add the following after the CURRENCY
type definition:
class tagDEC(Structure): _fields_ = [("wReserved", c_ushort), ("scale", c_ubyte), ("sign", c_ubyte), ("Hi32", c_ulong), ("Lo64", c_ulonglong)] DECIMAL = tagDEC
In comtypes/tools/tlbparser.py, replace the DECIMAL_type
definition with the following:
DECIMAL_type = typedesc.Structure("DECIMAL", align=alignment(automation.DECIMAL)*8, members=[], bases=[], size=sizeof(automation.DECIMAL)*8)
Additionally, it could be useful to define the decVal
and pDecVal
fields in comtypes' predefined VARIANT
definition, although I don't know if it doesn't break anything.
In comtypes/automation.py:
# The VARIANT structure is a good candidate for implementation in a C # helper extension. At least the get/set methods. class tagVARIANT(Structure): class U_VARIANT1(Union): class __tagVARIANT(Structure): # The C Header file defn of VARIANT is much more complicated, but # this is the ctypes version - functional as well. class U_VARIANT2(Union): class _tagBRECORD(Structure): _fields_ = [("pvRecord", c_void_p), ("pRecInfo", POINTER(IUnknown))] _fields_ = [ ("VT_BOOL", VARIANT_BOOL), ("VT_I1", c_byte), ("VT_I2", c_short), ("VT_I4", c_long), ("VT_I8", c_longlong), ("VT_INT", c_int), ("VT_UI1", c_ubyte), ("VT_UI2", c_ushort), ("VT_UI4", c_ulong), ("VT_UI8", c_ulonglong), ("VT_UINT", c_uint), ("VT_R4", c_float), ("VT_R8", c_double), ("VT_CY", c_longlong), ("c_wchar_p", c_wchar_p), ("c_void_p", c_void_p), ("pparray", POINTER(POINTER(_safearray.tagSAFEARRAY))), ("bstrVal", BSTR), ("_tagBRECORD", _tagBRECORD), ] _anonymous_ = ["_tagBRECORD"] _fields_ = [("vt", VARTYPE), ("wReserved1", c_ushort), ("wReserved2", c_ushort), ("wReserved3", c_ushort), ("_", U_VARIANT2) ] _fields_ = [("__VARIANT_NAME_2", __tagVARIANT), ("decVal", DECIMAL)] _anonymous_ = ["__VARIANT_NAME_2"] _fields_ = [("__VARIANT_NAME_1", U_VARIANT1)] _anonymous_ = ["__VARIANT_NAME_1"] # ...
It could be made to further support the DECIMAL
type properly, but the main purpose for now is to make the VARIANT
struct have the right size.
Here's a handy patch with exactly these changes.