Message273149
When using a custom class to store a ctype value, passing that class as a function argument explicitly declared to be a pointer type fails to pass the _as_parameter_ class attribute as a pointer and instead raises a TypeError.
For example:
>>> from ctypes import *
>>> from ctypes.wintypes import *
>>>
>>> class CustomPHKEY(object):
... def __init__(self, value):
... self._as_parameter_ = HKEY(value)
...
>>>
>>> function = windll.function
>>> function.argtypes = [POINTER(HKEY)]
>>> function.restype = LONG
>>> result = CustomPHKEY(0)
>>> function(result)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: expected LP_c_void_p instance instead of c_void_p
Shouldn't ctypes apply the required byref() conversion automatically? Or is this behavior normal and automatic byref() only concerns native ctypes types?
I only flagged Python 3.5 and Python 2.7 since they are the only ones I explicitly tested this on but I suspect other versions are affected. |
|
Date |
User |
Action |
Args |
2016-08-19 18:11:37 | lepaperwan | set | recipients:
+ lepaperwan, amaury.forgeotdarc, belopolsky, meador.inge |
2016-08-19 18:11:37 | lepaperwan | set | messageid: <1471630297.02.0.563258836934.issue27803@psf.upfronthosting.co.za> |
2016-08-19 18:11:36 | lepaperwan | link | issue27803 messages |
2016-08-19 18:11:36 | lepaperwan | create | |
|