1

I am using the PyObject functionality to call c functions, and

return Py_BuildValue("theTypeToConvert", myCVariable);

to return things back to my python program, this all works fine.

However I have a custom C type

extern HANDLE pascal

how do I pass an instance of this back to python so I can give it to other c functions later, the closest I could think of was to use

Py_BuildValue("O&", etc)

but this apparently mangles the variable as I am not getting the correct results later on.

1 Answers1

0

If I understand correctly that you want the object to be "opaque" from the Python perspective, i.e. just a pointer value that you can pass around in Python but not operate on the object it points to, then you might be after the Capsule object.

Official Python docs on capsules: https://docs.python.org/2/c-api/capsule.html#capsules

See also: Passing a C pointer around with the Python/C API

Community
  • 1
  • 1
Brian McFarland
  • 9,052
  • 6
  • 38
  • 56