[python-win32] [win32com] Meaning of "TypeError: Only com_record objects can be used as records"?

Tim Roberts timr at probo.com
Tue Apr 28 02:31:32 EDT 2020


On Apr 27, 2020, at 12:58 PM, Terry Davis <terry.y.davis at gmail.com> wrote:
> 
> 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?

Well, yes.  There are rigid rules for writing IDL to make a valid dispatch interface, and generic structs like that are not in those rules.  Some people get the idea that anything they can express in C++ can be shoved in a COM interface, but it ain’t so.

You should be able to add a GUID attribute to the IDL:

[ uuid(12345678-1234-1234-1234-123456789ABC) ]
typedef struct SoftwareInfo {
…
} SoftwareInfo;

Just generate a new GUID for each one.
— 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list