This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lepaperwan
Recipients amaury.forgeotdarc, belopolsky, lepaperwan, meador.inge
Date 2016-08-19.18:11:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1471630297.02.0.563258836934.issue27803@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-08-19 18:11:37lepaperwansetrecipients: + lepaperwan, amaury.forgeotdarc, belopolsky, meador.inge
2016-08-19 18:11:37lepaperwansetmessageid: <1471630297.02.0.563258836934.issue27803@psf.upfronthosting.co.za>
2016-08-19 18:11:36lepaperwanlinkissue27803 messages
2016-08-19 18:11:36lepaperwancreate