辉煌仪奇
2022-03-30 13:29
采纳率: 49.1%
浏览 133

python调用dll内函数,如何接受返回函数

c++生成动态dll,python调用该dll如何传参
这是dll链接


下面是c++函数代码

double* disp11(unsigned char* rev)
{
    union gyro
    {
        char ch[4];
        float f;
        int si;
    };
    union gyro Gyrox[4];
    unsigned short int data_temp1;
    int i, j;
    static double angleRT[16];
    unsigned short int YearMonth;     //年
    unsigned short int Product_ID_T; //产品编号

    i = 2;
    Product_ID_T = rev[2] + rev[3] * 256; //产品编号
    YearMonth = rev[4] + rev[5] * 256;      //年

    i = 11;
    j = 0;
    Gyrox[0].ch[0] = rev[i++]; //经度
    Gyrox[0].ch[1] = rev[i++];
    Gyrox[0].ch[2] = rev[i++];
    Gyrox[0].ch[3] = rev[i++];
    angleRT[0] = Gyrox[0].f;

    i = 15;
    j = 0;
    Gyrox[0].ch[j++] = rev[i++]; //纬度
    Gyrox[0].ch[j++] = rev[i++];
    Gyrox[0].ch[j++] = rev[i++];
    Gyrox[0].ch[j++] = rev[i++];
    angleRT[1] = Gyrox[0].f;
    i = 19;
    j = 0;
    Gyrox[0].ch[j++] = rev[i++]; //高度,m
    Gyrox[0].ch[j++] = rev[i++];
    Gyrox[0].ch[j++] = rev[i++];
    Gyrox[0].ch[j++] = rev[i++];
    angleRT[2] = Gyrox[0].f;

    i = 23;
    j = 0;
    Gyrox[0].ch[j++] = rev[i++]; //航向
    Gyrox[0].ch[j++] = rev[i++];
    Gyrox[0].ch[j++] = rev[i++];
    Gyrox[0].ch[j++] = rev[i++];
    angleRT[3] = Gyrox[0].f;

    i = 27;
    j = 0;
    Gyrox[0].ch[j++] = rev[i++]; //步数
    Gyrox[0].ch[j++] = rev[i++];
    Gyrox[0].ch[j++] = rev[i++];
    Gyrox[0].ch[j++] = rev[i++];
    angleRT[4] = Gyrox[0].f;

    //步幅度,低字节
    data_temp1 = rev[32] * 256 + rev[31];
    angleRT[5] = (double)data_temp1;

    angleRT[6] = (double)rev[33];       //卫星数
    angleRT[7] = (double)rev[34];       //状态字1
    angleRT[8] = (double)rev[35];       //状态字2
    angleRT[9] = (double)Product_ID_T; //状态字2

    angleRT[10] = (double)YearMonth; //年
    angleRT[11] = (double)rev[6];     //月
    angleRT[12] = (double)rev[7];     //日
    angleRT[13] = (double)rev[8];     //时
    angleRT[14] = (double)rev[9];     //分
    angleRT[15] = (double)rev[10];     //秒

    return angleRT;
}

这是我使用python调用的代码

from ctypes import *
dll = CDLL('./Dll1.dll')
print(dir(dll))
print(dll.disp11([0xAA,0x55,0xAD,0x02,0xBC,0x08,0x01,0x06,0x08,0x00,0x00,0x08,0x33,0xD6,0x42,0xF0,0x97,0xEF,0x41,0x24,0x18,0xB7,0x43,0xEF,0x69,0x56,0x43,0x00,0x00,0x50,0x41,0xA8,0x02,0x00,0x00,0x01,0xEF]))

img

返回应该是个数组,但是接受到却是一个整数,我该如何取出dll返回参数

8条回答 默认 最新

相关推荐 更多相似问题