如何使用cython类函数的参数接受c ++ struct

时间:2014-10-06 10:35:54

标签: python c++ struct cython

c ++头文件代码:

typedef int TSecurityFtdcErrorIDType;

typedef char TSecurityFtdcErrorMsgType[81];

struct CSecurityFtdcRspInfoField
{

    TSecurityFtdcErrorIDType    ErrorID;

    TSecurityFtdcErrorMsgType   ErrorMsg;
};

c ++ class header:

class CSecurityFtdcMdSpi
{
  public:
    virtual void OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};  
}

我的pxd定义:

ctypedef int TSecurityFtdcErrorIDType

ctypedef char TSecurityFtdcErrorMsgType[81]

cdef struct CSecurityFtdcRspInfoField:

    TSecurityFtdcErrorIDType    ErrorID

    TSecurityFtdcErrorMsgType    ErrorMsg

cython类定义pxd:

cdef cppclass CSecurityFtdcMdSpi:
    void OnRspError(CSecurityFtdcRspInfoField *pRspInfo,
                    int nRequestID,
                    bool bIsLast) except +

如果我尝试在pyx文件中定义类:

cdef class CSecurityMdSpi:
    cdef CSecurityFtdcMdSpi  *_this_md_spi 

    cpdef OnRspError(self, CSecurityFtdcRspUserLoginField *pRspInfo,
                 int nRequestID,
                 bool bIsLast) except +:
          self._this_md_spi.OnRspError(pRspInfo, nRequestID, bIsLast)

但是当我尝试编译代码时,控制台输出:

Cannot convert 'CSecurityFtdcRspInfoField *' to Python object

如何在python中转换c ++结构,如何在cython中声明struct参数,使用cdef函数还是其他?

0 个答案:

没有答案