Pasar objetos de Python como argumentos a la función C / C ++ usando ctypes
Tengo una DLL con una función que toma PyObject como argumento algo así como
void MyFunction(PyObject* obj)
{
PyObject *func, *res, *test;
//function getAddress of python object
func = PyObject_GetAttrString(obj, "getAddress");
res = PyObject_CallFunction(func, NULL);
cout << "Address: " << PyString_AsString( PyObject_Str(res) ) << endl;
}
y quiero llamar a esta función en el dll de python usando ctypes
Mi código de python parece
import ctypes as c
path = "h:\libTest"
libTest = c.cdll.LoadLibrary( path )
class MyClass:
@classmethod
def getAddress(cls):
return "Some Address"
prototype = c.CFUNCTYPE(
c.c_char_p,
c.py_object
)
func = prototype(('MyFunction', libTest))
pyobj = c.py_object(MyClass)
func( c.byref(pyobj) )
hay un problema en mi código Python cuando ejecuto este código recibí un mensaje como
WindowsError: excepción: infracción de acceso que lee 0x00000020
Cualquier sugerencia para mejorar el código de python sería valiosa.