如何将 typedef 变量的指针实现到 SWIG 中?参数 2 类型为“BYTE const *”错误
我现在正在设置一个 Python-C SWIG 接口。我已经通过以下命令生成共享对象文件:
swig -python myFile.i
gcc -c myFile.c myFile2.c myFile3.c myFile_wrap.c -IC:\myincludedirectory\include
gcc -shared myFile。 o myFile2.o myFile3.o myFile_wrap.o -Ic:\myincludedirectory\libs -lpython27 -o _myfile3.o
In myFile.i,我有:
/* myFile3 */
%module myFile3
%{
#include "myFile.h"
#include "defs.h"
#include "myFile2.h"
#include "myFile3.h"
%}
%include "defs.h"
%include "myFile.h"
%include "myFile2.h"
%include "myFile3.h"
defs.h 包含以下行(除其他外):
typedef unsigned int BOOL;
typedef unsigned short WORD; //Word is 2 bytes but int* is 4 bytes ??
typedef unsigned int DWORD;
typedef unsigned long long QWORD;
typedef unsigned char BYTE;
当我尝试调用我的程序时,我在命令提示符中执行以下操作:
python
import myFile3
myFile3.myFuncInit()
myFile3.myFuncWrite ("ABCD" ,“ABCDEFGHI”,8); // <= 当我输入此行时出现错误。
其中 myFuncWrite 的参数是 (char *param1, const BYTE *param2, WORD param3)
我相信问题在于它是一个事实常量字节指针。我不确定是否需要执行一些简单的辅助函数或类型映射才能使其正确通过。事实上,我一直被困在这里,我不知道我应该做什么才能让我明白我只是传递 BYTE 的 typedef 指针。
I am setting up a Python-C SWIG interface right now. I've already gotten it to produce the shared object file through the following commands:
swig -python myFile.i
gcc -c myFile.c myFile2.c myFile3.c myFile_wrap.c -IC:\myincludedirectory\include
gcc -shared myFile.o myFile2.o myFile3.o myFile_wrap.o -Ic:\myincludedirectory\libs -lpython27 -o _myfile3.o
In myFile.i, I have:
/* myFile3 */
%module myFile3
%{
#include "myFile.h"
#include "defs.h"
#include "myFile2.h"
#include "myFile3.h"
%}
%include "defs.h"
%include "myFile.h"
%include "myFile2.h"
%include "myFile3.h"
defs.h contains the following lines (among others):
typedef unsigned int BOOL;
typedef unsigned short WORD; //Word is 2 bytes but int* is 4 bytes ??
typedef unsigned int DWORD;
typedef unsigned long long QWORD;
typedef unsigned char BYTE;
When I attempt to call my program, I do the following in command prompt:
python
import myFile3
myFile3.myFuncInit()
myFile3.myFuncWrite ("ABCD", "ABCDEFGHI", 8); // <= I get an error when I enter this line.
where myFuncWrite's parameters are (char *param1, const BYTE *param2, WORD param3)
I believe the issue lies in the fact that it's a const BYTE pointer. I am not sure if I need to do some simple helper function or a typemap to get it to pass properly. As it is, I keep getting stuck here and I've no idea what I should do to get swig to understand I'm simply passing a pointer of BYTE's typedef.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 %include "defs.h 行之后,尝试添加此行:
这会将所有 char* 类型映射(包括类型检查)应用到 BYTE*。有关详细信息,请阅读 SWIG 手册的以下部分:
http://www.swig.org/Doc2.0/Typemaps.html#Typemaps_nn6
After the %include "defs.h line, try adding this line:
This will apply all of the char* typemaps (including type-checking) to BYTE*. For more on this, read the following section of the SWIG manual:
http://www.swig.org/Doc2.0/Typemaps.html#Typemaps_nn6