2 liujunbiao007 liujunbiao007 于 2017.09.14 19:17 提问

python调用so 如何传递结构体参数(纯虚接口)?

第一次发求助帖,格式不太规范,烦请各位答友见谅

本人想python调用动态库的一个接口,接口其中一个参数是接口类的指针,不知如何调用,请大牛指教,不胜感激

1、so接口函数

 //导出接口函数
extern "C" int CreateCardReaderDevice(const char *pName,
                                      ICardReaderDevice *&ppDevice)
                                                                            {

    ppDevice = new CNDTCardReader_OMRON();

    return 0;
}

2、结构体

 typedef struct _TRACK_INFO
{

    char szTrack1[77];
    char szTrack2[38];
    char szTrack3[105];
    bool bTrack1OK;
    bool bTrack2OK;
    bool bTrack3OK;
}TRACK_INFO;

struct  ICardReaderDevice
{

     virtual const char * GetVersion()
    {
        string version="2.2";
        return version.c_str();
    }
    virtual void Release() = 0;
    virtual int Init(int nFlag, int nNeedWobble = 3) = 0;
    virtual int Open(const char *pMode) = 0;
    virtual void Close()= 0;
    virtual int EatCard() = 0;
    virtual int EjectCard() = 0;
    virtual int AcceptCard(ULONG ulTimeout, IWaitCancel *pWaitCancel,bool Magnetic=true) = 0;
    virtual int WriteTracks(TRACK_INFO &stTrackInfo) = 0;
    virtual int ReadTracks(TRACK_INFO &stTrackInfo) = 0;
        ......
};

3、接口返回的是子类的对象

 class CNDTCardReader_OMRON: public ICardReaderDevice
{

public:
    int m_nCardStatus;
    int m_nLastError;
    bool m_bCardInGatePosition; 
    bool m_bReTakeIn;             
    int m_nEjectedCard;     
    int m_nTakeCard;        

    CNDTCardReader_OMRON(void);
    virtual int Init(int nFlag, int nNeedWobble = 3);
    virtual int EatCard();
    virtual int EjectCard();
            ......
}

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.14 23:49
Csdn user default icon
上传中...
上传图片
插入图片