comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

['out', 'optional'] causes TypeError

Open pierssen opened this issue 5 years ago • 0 comments

I've been using comtypes successfully for years, but for the first time I'm calling a method that has an optional output parameter. Here's the code generated by comtypes:

COMMETHOD([helpstring(u'Returns the item in the collection at the specified index.')], HRESULT, 'QueryItem',
          ( ['in'], c_int, 'Index' ),
          ( ['out'], POINTER(POINTER(IAnnotateLayerProperties)), 'Item' ),
          ( ['out', 'optional'], POINTER(POINTER(IElementCollection)), 'placedElements', 0 ),
          ( ['out', 'optional'], POINTER(POINTER(IElementCollection)), 'unplacedElements', 0 )),

When I call the method as follows:

pAnnoProp, pPlaced, pUnplaced = pAPC.QueryItem(i)

I get the following error:

argument 3: <type 'exceptions.TypeError'>: expected LP_POINTER(IElementCollection) instance instead of int

However, if I alter the generated code as follows:

COMMETHOD([helpstring(u'Returns the item in the collection at the specified index.')], HRESULT, 'QueryItem',
          ( ['in'], c_int, 'Index' ),
          ( ['out'], POINTER(POINTER(IAnnotateLayerProperties)), 'Item' ),
          ( ['out'], POINTER(POINTER(IElementCollection)), 'placedElements'),
          ( ['out'], POINTER(POINTER(IElementCollection)), 'unplacedElements')),

it works just fine. Is this a defect in comtypes, or should I be doing something different?

pierssen avatar Jun 09 '20 16:06 pierssen