I just discovered this message:
https://mail.python.org/pipermail/python-list/2003-August/214888.html
and when I tried getting a com_record:
client.Record("SoftwareInfo",app._com)
I got this error:
ValueError: The structure 'SoftwareInfo' is not defined in module '<module
'win32com.gen_py.<GUID>x1x0'

I looked in the generated file, and its RecordMap dict was empty, with a
comment. There are a dozen or so structs that should be available to the
interface. Is there any workaround for this, such as manually defining each
com_record?

RecordMap = {
###'LegacyMicroSamplerInfo': '{00000000-0000-0000-0000-000000000000}', #
Record disabled because it doesn't have a non-null GUID
}

I was also given an idl file, which includes record definitions, like this
one:

typedef struct SoftwareInfo {
   BSTR name;
   BSTR version;
} SoftwareInfo;

Is there something missing from the idl file that's causing these to be
missed by win32com?


On Wed, Apr 22, 2020 at 9:28 AM Terry Davis <terry.y.da...@gmail.com> wrote:

> Any ideas?
>
> On Tue, Jan 28, 2020 at 1:06 PM Terry Davis <terry.y.da...@gmail.com>
> wrote:
>
>> Update 2: After discovering the `pythoncom.GetRecordFromGuids` and
>> `.GetRecordFromTypeInfo` (with the comment: "This function will fail if the
>> specified type info does not have a guid defined").
>>
>> I found that the Record types don't appear to have a GUID.
>> lib_pyITypelib.GetDocumentation(4) = ('SoftwareInfo', None, 0, None)
>> lib_pyITypelib.GetTypeInfo(4).GetTypeAttr().iid
>> = IID('{00000000-0000-0000-0000-000000000000}')
>>
>> So, is it possible to create a Record object without a GUID?
>> (Assuming that passing a Record object `ccs.GetSoftwareInfo(info=<some
>> Record Object>)` is the correct approach here.)
>>
>> I also tried assigning a `pythoncom.CreateGuid() to the `iid` attribute
>> above, but `GetRecordFromGuids` failed with `pywintypes.com_error:
>> (-2147319765, 'Element not found.', None, None)`. So I assume the GUID
>> assignment didn't make it outside of python into COM-space.
>>
>> P.S.
>> I also found this old thread:
>>
>> https://grokbase.com/t/python/python-win32/0821b2n4e5/how-to-create-a-com-record
>> which appears to be related to my problem, but no solutions were
>> identified.
>> (I tried the `DumbDispatch` solution; it didn't work).
>>
>>
>> On Mon, Jan 27, 2020 at 4:31 PM Terry Davis <terry.y.da...@gmail.com>
>> wrote:
>>
>>> Update: The functions that don't work return Record types, and the ones
>>> that do work just return multiple values (a tuple).
>>> Do I need to pass in the appropriate Record type (or an empty record)
>>> during each function call?
>>> If so, how do I get to the Record types that I see in the python object
>>> browser (python -m win32com.client.combrowse)?
>>>
>>> Thanks,
>>> Terry
>>>
>>> On Mon, Jan 27, 2020 at 3:33 PM Terry Davis <terry.y.da...@gmail.com>
>>> wrote:
>>>
>>>> Hi all,
>>>>
>>>> I tried searching the mailing list archives for "com_record" but didn't
>>>> find anything relevant.
>>>>
>>>> For context, I'm trying to access a COM interface defined in a .tlb
>>>> file.
>>>>
>>>> Here's a skeleton of the script I'm using to expose this interface:
>>>> import pythoncom
>>>> from win32com.client import gencache
>>>>
>>>> lib_GUID = "{<GUID>}"
>>>> lib_major = 1
>>>> lib_minor = 0
>>>> lib_pyITypelib = pythoncom.LoadRegTypeLib(lib_GUID, lib_major,
>>>> lib_minor)
>>>> lib = gencache.EnsureModuleForTypelibInterface(_lib_pyITypelib)
>>>>
>>>> ccs = lib.CControlServer()  # CControlServer is a CoClass
>>>> eid, *other = ccs.LoadExperiment(**path to file**)  # Works
>>>> ccs.GetSoftwareInfo()  # Fails with exception below.
>>>> ccs.GetSolvent(eid)  # also fails
>>>>
>>>> I can't dig down in the debugger to find the source of the exception,
>>>> so I'm hoping someone here can help!
>>>>
>>>>
>>>> Exception:
>>>>
>>>> def GetSoftwareInfo(self, info=pythoncom.Missing):
>>>>
>>>>
>>>> <ipython-input-8-7304ad54d54a> in <module>
>>>> ----> 1 ccs.GetSoftwareInfo()
>>>>
>>>> ~\AppData\Local\Temp\gen_py\3.7\<GUID>x0x1x0.py in
>>>> GetSoftwareInfo(self, info)
>>>>     279         def GetSoftwareInfo(self, info=pythoncom.Missing):
>>>>     280                 'method GetSoftwareInfo'
>>>> --> 281                 return self._ApplyTypes_(13, 1, (24, 0), ((36,
>>>> 2),), 'GetSoftwareInfo', None,info
>>>>     282                         )
>>>>     283
>>>>
>>>> C:\Python37\lib\site-packages\win32com\client\__init__.py in
>>>> _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID,
>>>> *args)
>>>>     465         def _ApplyTypes_(self, dispid, wFlags, retType,
>>>> argTypes, user, resultCLSID, *args):
>>>>     466                 return self._get_good_object_(
>>>> --> 467                         self._oleobj_.InvokeTypes(dispid, 0,
>>>> wFlags, retType, argTypes, *args),
>>>>     468                         user, resultCLSID)
>>>>     469
>>>>
>>>> TypeError: Only com_record objects can be used as records
>>>>
>>>
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to