带有指针结构的SWIG函数 [英] SWIG function with pointer struct

查看:212
本文介绍了带有指针结构的SWIG函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用SWIG封装C共享库的新手.

Im new using SWIG to wrapped C shared library.

我在用python中的Struct指针调用C函数时遇到问题.

I have problem to call a C function with Struct pointer in python.

我的文件:

ST_Param.h:

typedef struct {
       unsigned int* device_Address;
       ....
       ....
       unsigned int lock;
}ST_param_ST;      


unsigned char ST_Param_Initialize(ST_param_ST * ST_param, unsigned int device_Address);

ST_Param.c

......... Rest of file.............

unsigned char ST_Param_Initialize(ST_param_ST * ST_param, unsigned int device_Address){

    if(ST_param == NULL){
    .......... rest of funtion .......................

    return 0;
}

在ST_Param_Initialize内,如果不相信,我确认指针存在

Within ST_Param_Initialize I confirm that the pointer exists, if not believe

ST_Param.i :

/* File : ST_Param.i */
%module ST_Param

%{
#define SWIG_FILE_WITH_INIT
#include "ST_Param.h"
%}




%include "typemaps.i" 
%include "ST_Param.h"

我编译并生成了一个.so文件. 在python中,我可以导入库,但由于需要ST_Param_ST *参数,因此无法调用ST_Param_Initialize:

I compiled and generated a .so file good. In python I can import a library but I cant call a ST_Param_Initialize because a need a ST_Param_ST * parameter:

ST_param_ST *错误

我该怎么做?

注意:我无法修改.c和.h文件.只有.i文件.

Note: i cant modify a .c and .h file. Only a .i file.

在Google中进行搜索,但我不知道该怎么做

A search in google but I dont understand how to do it

谢谢 问候.

推荐答案

执行此操作的方式基本上与在C中执行此操作的方式相同:首先创建一个ST_param_ST结构,然后将其传递给初始化函数ST_Param_Initialize().这是Python中的示例,假设您的模块名为ex:

You do this essentially the same way you do it in C: You first create a ST_param_ST struct and then pass this to the initialization function ST_Param_Initialize(). Here is an example in Python, assuming your module is called ex:

>>> import ex
>>> ST_Param = ex.ST_param_ST()
>>> ex.ST_Param_Initialize(ST_param, 42)

这篇关于带有指针结构的SWIG函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆