Open ILikeUrCtG opened 2 years ago
all of the syntax errors have been fixed and are located in this PR https://github.com/enthought/comtypes/pull/253
The VARIANT structure does not follow the Windows SDK naming convention for the fields and this is one of the things I have wanted to correct myself.
I would post the code for a corrected VARIANT structure but it's pretty large and the structures that make up the fields are spread across a couple of files. So not easy to tear out only the VARIANT structure.
I am not sure what you meant by not being able to import comtypes.typeinfo
Your issue is very hard to read and understand what you are talking about, some of the code is formatted and some of it isn't and some things there are crazy headers with code in it (assuming this is because of the code not being formatted)..
Here is the markup you need to use at the begining and the end of a code block. ```python
```
If you use \ in front of markup characters the character will be properly displayed. _, *, #, `
@ILikeUrCtG please check comtypes==1.1.11
(by pip install -U comtypes
).
After fixing a bunch of errors by looking them up, I came across this one where I could not find anywhere except for a discussion closed here in the Issues of the comtypes module in GitHub, named (ignore the italics - "_" in GitHub = italics begin/end): "TypeError: type must have storage info." I am using Python 3.7.9 on a Windows 11 computer in Spyder (downloaded from Anaconda). I have done so much research to fix lots of the code, so if anyone also has the issues I came across, provided is the fix for the errors I have fixed so far. If you want a summary of my current fixes, here they are:
Step 1: Change all instances of "unicode" that are not part of a variable name to "str" Step 2: Change all instances of "COMError, err" to "COMError as err" Step 3: (Discalaimer: I am not exactly sure of the validation of my correction for this third step) Go to line 542, and change "v._.VTI4 = 0x80020004L" to "v..VT_I4 = "0x80020004L"" (add quotes around that number id thingy)
This is the error I am baffled by. Here is the code I fixed so far in "automation.py" without that error fixed yet:
`# comtypes.automation module import array import datetime import decimal
from ctypes import from ctypes import _Pointer from _ctypes import CopyComPointer from comtypes import IUnknown, GUID, IID, STDMETHOD, BSTR, COMMETHOD, COMError from comtypes.hresult import from comtypes.patcher import Patch from comtypes import npsupport try: from comtypes import _safearray except (ImportError, AttributeError): class _safearray(object): tagSAFEARRAY = None
from ctypes.wintypes import DWORD, LONG, UINT, VARIANT_BOOL, WCHAR, WORD
LCID = DWORD DISPID = LONG SCODE = LONG
VARTYPE = c_ushort
DISPATCH_METHOD = 1 DISPATCH_PROPERTYGET = 2 DISPATCH_PROPERTYPUT = 4 DISPATCH_PROPERTYPUTREF = 8
tagINVOKEKIND = c_int INVOKE_FUNC = DISPATCH_METHOD INVOKE_PROPERTYGET = DISPATCH_PROPERTYGET INVOKE_PROPERTYPUT = DISPATCH_PROPERTYPUT INVOKE_PROPERTYPUTREF = DISPATCH_PROPERTYPUTREF INVOKEKIND = tagINVOKEKIND
################################
helpers
IID_NULL = GUID() riid_null = byref(IID_NULL) _byref_type = type(byref(c_int()))
30. December 1899, midnight. For VT_DATE.
_com_null_date = datetime.datetime(1899, 12, 30, 0, 0, 0)
################################################################
VARIANT, in all it's glory.
VARENUM = c_int # enum VT_EMPTY = 0 VT_NULL = 1 VT_I2 = 2 VT_I4 = 3 VT_R4 = 4 VT_R8 = 5 VT_CY = 6 VT_DATE = 7 VT_BSTR = 8 VT_DISPATCH = 9 VT_ERROR = 10 VT_BOOL = 11 VT_VARIANT = 12 VT_UNKNOWN = 13 VT_DECIMAL = 14 VT_I1 = 16 VT_UI1 = 17 VT_UI2 = 18 VT_UI4 = 19 VT_I8 = 20 VT_UI8 = 21 VT_INT = 22 VT_UINT = 23 VT_VOID = 24 VT_HRESULT = 25 VT_PTR = 26 VT_SAFEARRAY = 27 VT_CARRAY = 28 VT_USERDEFINED = 29 VT_LPSTR = 30 VT_LPWSTR = 31 VT_RECORD = 36 VT_INT_PTR = 37 VT_UINT_PTR = 38 VT_FILETIME = 64 VT_BLOB = 65 VT_STREAM = 66 VT_STORAGE = 67 VT_STREAMED_OBJECT = 68 VT_STORED_OBJECT = 69 VT_BLOB_OBJECT = 70 VT_CF = 71 VT_CLSID = 72 VT_VERSIONED_STREAM = 73 VT_BSTR_BLOB = 4095 VT_VECTOR = 4096 VT_ARRAY = 8192 VT_BYREF = 16384 VT_RESERVED = 32768 VT_ILLEGAL = 65535 VT_ILLEGALMASKED = 4095 VT_TYPEMASK = 4095
class tagCY(Structure): fields = [("int64", c_longlong)] CY = tagCY CURRENCY = CY
class tagDEC(Structure): fields = [("wReserved", c_ushort), ("scale", c_ubyte), ("sign", c_ubyte), ("Hi32", c_ulong), ("Lo64", c_ulonglong)]
DECIMAL = tagDEC
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
these are missing:
getter[VT_ERROR]
getter[VT_ARRAY]
getter[VT_BYREF|VT_UI1]
getter[VT_BYREF|VT_I2]
getter[VT_BYREF|VT_I4]
getter[VT_BYREF|VT_R4]
getter[VT_BYREF|VT_R8]
getter[VT_BYREF|VT_BOOL]
getter[VT_BYREF|VT_ERROR]
getter[VT_BYREF|VT_CY]
getter[VT_BYREF|VT_DATE]
getter[VT_BYREF|VT_BSTR]
getter[VT_BYREF|VT_UNKNOWN]
getter[VT_BYREF|VT_DISPATCH]
getter[VT_BYREF|VT_ARRAY]
getter[VT_BYREF|VT_VARIANT]
getter[VT_BYREF]
getter[VT_BYREF|VT_DECIMAL]
getter[VT_BYREF|VT_I1]
getter[VT_BYREF|VT_UI2]
getter[VT_BYREF|VT_UI4]
getter[VT_BYREF|VT_INT]
getter[VT_BYREF|VT_UINT]
VARIANT = tagVARIANT VARIANTARG = VARIANT
_oleaut32 = OleDLL("oleaut32")
_VariantChangeType = _oleaut32.VariantChangeType _VariantChangeType.argtypes = (POINTER(VARIANT), POINTER(VARIANT), c_ushort, VARTYPE)
_VariantClear = _oleaut32.VariantClear _VariantClear.argtypes = (POINTER(VARIANT),)
_SysAllocStringLen = windll.oleaut32.SysAllocStringLen _SysAllocStringLen.argtypes = c_wchar_p, c_uint _SysAllocStringLen.restype = c_void_p
_VariantCopy = _oleaut32.VariantCopy _VariantCopy.argtypes = POINTER(VARIANT), POINTER(VARIANT)
_VariantCopyInd = _oleaut32.VariantCopyInd _VariantCopyInd.argtypes = POINTER(VARIANT), POINTER(VARIANT)
some commonly used VARIANT instances
VARIANT.null = VARIANT(None) VARIANT.empty = VARIANT() VARIANT.missing = v = VARIANT() v.vt = VTERROR v..VT_I4 = "0x80020004L" del v
_carg_obj = type(byref(c_int())) from _ctypes import Array as _CArrayType
@Patch(POINTER(VARIANT)) class _(object):
Override the default .from_param classmethod of POINTER(VARIANT).
################################################################
interfaces, structures, ...
class IEnumVARIANT(IUnknown): iid = GUID('{00020404-0000-0000-C000-000000000046}') idlflags = ['hidden'] _dynamic = False def iter(self): return self
if isinstance(index, slice):
self.Skip(index.start or 0)
return self.Next(index.stop or sys.maxint)
IEnumVARIANT.methods = [ COMMETHOD([], HRESULT, 'Next', ( ['in'], c_ulong, 'celt' ), ( ['out'], POINTER(VARIANT), 'rgvar' ), ( ['out'], POINTER(c_ulong), 'pceltFetched' )), COMMETHOD([], HRESULT, 'Skip', ( ['in'], c_ulong, 'celt' )), COMMETHOD([], HRESULT, 'Reset'), COMMETHOD([], HRESULT, 'Clone', ( ['out'], POINTER(POINTER(IEnumVARIANT)), 'ppenum' )), ]
from _ctypes import VARIANT_set
import new
VARIANT.value = property(VARIANT._get_value, new.instancemethod(VARIANT_set, None, VARIANT))
class tagEXCEPINFO(Structure): def repr(self): return "<EXCEPINFO %s>" % \ ((self.wCode, self.bstrSource, self.bstrDescription, self.bstrHelpFile, self.dwHelpContext, self.pfnDeferredFillIn, self.scode),) tagEXCEPINFO.fields = [ ('wCode', WORD), ('wReserved', WORD), ('bstrSource', BSTR), ('bstrDescription', BSTR), ('bstrHelpFile', BSTR), ('dwHelpContext', DWORD), ('pvReserved', c_void_p),
('pfnDeferredFillIn', WINFUNCTYPE(HRESULT, POINTER(tagEXCEPINFO))),
] EXCEPINFO = tagEXCEPINFO
class tagDISPPARAMS(Structure): fields = [
C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 696
DISPPARAMS = tagDISPPARAMS
DISPID_VALUE = 0 DISPID_UNKNOWN = -1 DISPID_PROPERTYPUT = -3 DISPID_NEWENUM = -4 DISPID_EVALUATE = -5 DISPID_CONSTRUCTOR = -6 DISPID_DESTRUCTOR = -7 DISPID_COLLECT = -8
class IDispatch(IUnknown): iid = GUID("{00020400-0000-0000-C000-000000000046}") methods = [ COMMETHOD([], HRESULT, 'GetTypeInfoCount', (['out'], POINTER(UINT) ) ), COMMETHOD([], HRESULT, 'GetTypeInfo', (['in'], UINT, 'index'), (['in'], LCID, 'lcid', 0),
Normally, we would declare this parameter in this way:
(['out'], POINTER(POINTER(ITypeInfo)) ) ),
but we cannot import comtypes.typeinfo at the top level (recursive imports!).
################################################################
safearrays
XXX Only one-dimensional arrays are currently implemented
map ctypes types to VARTYPE values
_arraycode_to_vartype = { "d": VT_R8, "f": VT_R4, "l": VT_I4, "i": VT_INT, "h": VT_I2, "b": VT_I1, "I": VT_UINT, "L": VT_UI4, "H": VT_UI2, "B": VT_UI1, }
_ctype_to_vartype = { c_byte: VT_I1, c_ubyte: VT_UI1,
POINTER(IUnknown): VT_UNKNOWN,
POINTER(IDispatch): VT_DISPATCH,
_vartype_to_ctype = {} for c, v in _ctype_to_vartype.iteritems(): _vartype_to_ctype[v] = c _vartype_to_ctype[VT_INT] = _vartype_to_ctype[VT_I4] _vartype_to_ctype[VT_UINT] = _vartype_to_ctype[VT_UI4] _ctype_to_vartype[c_char] = VT_UI1
try: from comtypes.safearray import _midlSAFEARRAY except (ImportError, AttributeError): pass `