enthought / enthought/comtypes

Date arguments raise ctypes.ArgumentError when a datetime value is used

Open
#152 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
345
Forks
105
PR merge metrics
No merged PRs in 30d

Description

I'm trying to call a COM method defined as follows (copy-pasted from the API docs, as I don't have access to the IDL):

Function ExportCalibrationToDCM(
ExportFileName As String,
[ExportChangedOnly As Boolean = False],
[ExportFullDataItemNames As Boolean = False],
[UseDisplayFormat As Boolean = False],
[ExportDCM2Format As Boolean = False],
[ExportComments As Boolean = False],
[ExportFunctions As Boolean = False],
[ExportUnits As Boolean = False],
[FilterFileName As String],
[ModificationSource As String],
[ModificationFromDateTime As Date],
[ModificationToDateTime As Date],
[FilterMatchOption As VISION_EXPORT_FILTER_MATCH_OPTION = VISION_EXPORT_FILTER_MATCH_AND_AXIS_ITEMS]
) As VISION_STATUS_CODES

The code that comtypes generates for this method looks like this:

COMMETHOD([dispid(1610743868), helpstring('Exports a DCM calibration file (*.dcm)')], HRESULT, 'ExportCalibrationToDCM',
( ['in'], BSTR, 'ExportFileName' ),
( ['in', 'optional'], VARIANT_BOOL, 'ExportChangedOnly', False ),
( ['in', 'optional'], VARIANT_BOOL, 'ExportFullDataItemNames', False ),
( ['in', 'optional'], VARIANT_BOOL, 'UseDisplayFormat', False ),
( ['in', 'optional'], VARIANT_BOOL, 'ExportDCM2Format', False ),
( ['in', 'optional'], VARIANT_BOOL, 'ExportComments', False ),
( ['in', 'optional'], VARIANT_BOOL, 'ExportFunctions', False ),
( ['in', 'optional'], VARIANT_BOOL, 'ExportUnits', False ),
( ['in', 'optional'], BSTR, 'FilterFileName', '' ),
( ['in', 'optional'], BSTR, 'ModificationSource', '' ),
( ['in', 'optional'], c_double, 'ModificationFromDateTime', datetime.datetime(1899, 12, 30, 0, 0) ),
( ['in', 'optional'], c_double, 'ModificationToDateTime', datetime.datetime(1899, 12, 30, 0, 0) ),
( ['in', 'optional'], VISION_EXPORT_FILTER_MATCH_OPTION, 'FilterMatchOption', 1 ),
( ['out', 'retval'], POINTER(VISION_STATUS_CODES), 'Status' )),

When I try to call this with just the first argument, or explicitly call it with a datetime object as `ModificationFromDateTime`, I get the following exception:

ctypes.ArgumentError: argument 11: : wrong type

I have to explicitly set the two date arguments to `0` in order to make the call succeed:

s.ExportCalibrationToDCM('c:\a.dcm', ModificationFromDateTime=0, ModificationToDateTime=0)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.