comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

Define enumerations in generated modules.

Open junkmd opened this issue 3 years ago • 0 comments

Currently, when we generate a Python module from a COM type library with client.GetModule, the stuffs defined as Enumeration in the COM type library are defined in Python as aliases for ctypes.c_int.

They are passed to STDMETHOD, COMMETHOD, DISPMETHOD or DISPPROPERTY to define method and property arguments and return values.

This makes it difficult to add functionality such as enumeration type member information to these symbols.

This problem has been left as a comment that marked XXX on the codegenerator, since this package was born. https://github.com/enthought/comtypes/blob/cc9a0131edc76bd92073f75e9737aad40cd10c58/comtypes/tools/codegenerator.py#L406-L421

I propose the following procedure as a solution to this problem.

  1. The args passed to functions like STDMETHOD will be changed to ctypes.c_int itself from the symbols defined as Enumeration and External or Alias those referred to Enumeration in the COM type library.

    • Actual code will be below.
    ...
    XlCreator = c_int  # enum
    ...
        DISPMETHOD([dispid(149), 'propget'], XlCreator, 'Creator'),
    ...
    

    ...
    XlCreator = c_int  # enum
    ...
        DISPMETHOD([dispid(149), 'propget'], c_int, 'Creator'),
    ...
    
  2. The symbols currently defined as aliases of ctypes.c_int will be changed the definition as enumeration types.

    • The de facto standard for defining enumeration types in Python is the enum module. The enum module is supported since Py3.4, so it is not available in Py2.7 or Py3.3. Therefore, it will be after older Python versions are dropped that these will actually be changed.

junkmd avatar Aug 23 '22 14:08 junkmd