Python SWIG中结构数组的处理
我试图包装一个C函数,它需要向它传递一个结构数组 .i文件中的函数定义为:Python SWIG中结构数组的处理,python,swig,Python,Swig,我试图包装一个C函数,它需要向它传递一个结构数组 .i文件中的函数定义为: extern HRESULT WINAPI ScriptItemize( const WCHAR *pwcInChars, // In Unicode string to be itemized int cInChars, // In Codepoint count to itemize int cMax
extern HRESULT WINAPI ScriptItemize(
const WCHAR *pwcInChars, // In Unicode string to be itemized
int cInChars, // In Codepoint count to itemize
int cMaxItems, // In Max length of itemization array
const SCRIPT_CONTROL *psControl, // In Analysis control (optional)
const SCRIPT_STATE *psState, // In Initial bidi algorithm state (optional)
SCRIPT_ITEM *pItems, // Out Array to receive itemization
int *pcItems); // Out Count of items processed (optional)
structs SCRIPT_控件、SCRIPT_状态和SCRIPT_项之前都已在.i文件中定义
我可以通过包括以下行来指示pcItems是返回值:
%include <typemaps.i>
%apply int *OUTPUT {int *pcItems};
我得到这个警告:
Can't apply (SCRIPT_ITEM *OUTPUT). No typemaps are defined.
我如何指出pItems是一个返回值
另外,如何从Python中创建脚本项结构数组?我已经找到了通过更改.I文件来实现这一点的方法,如下所示:
%include <carrays.i>
%array_class(SCRIPT_ITEM, SCRIPT_ITEM_ARRAY);
extern HRESULT WINAPI ScriptItemize(
const WCHAR *pwcInChars, // In Unicode string to be itemized
int cInChars, // In Codepoint count to itemize
int cMaxItems, // In Max length of itemization array
const SCRIPT_CONTROL *psControl, // In Analysis control (optional)
const SCRIPT_STATE *psState, // In Initial bidi algorithm state (optional)
SCRIPT_ITEM_ARRAY *pItems, // Out Array to receive itemization
int *pcItems); // Out Count of items processed (optional)
%include
%数组类(脚本项、脚本项、数组);
外部HRESULT WINAPI脚本项目化(
常量WCHAR*pwcInChars,//以要逐项列出的Unicode字符串表示
int cInChars,//在要逐项列出的代码点计数中
int cMaxItems,//在项目化数组的最大长度中
const SCRIPT_CONTROL*psControl,//在分析控件中(可选)
const SCRIPT_STATE*psState,//处于初始bidi算法状态(可选)
SCRIPT_ITEM_ARRAY*pItems,//输出数组以接收项目化
int*pcItems);//已处理项目的超出计数(可选)
%include <carrays.i>
%array_class(SCRIPT_ITEM, SCRIPT_ITEM_ARRAY);
extern HRESULT WINAPI ScriptItemize(
const WCHAR *pwcInChars, // In Unicode string to be itemized
int cInChars, // In Codepoint count to itemize
int cMaxItems, // In Max length of itemization array
const SCRIPT_CONTROL *psControl, // In Analysis control (optional)
const SCRIPT_STATE *psState, // In Initial bidi algorithm state (optional)
SCRIPT_ITEM_ARRAY *pItems, // Out Array to receive itemization
int *pcItems); // Out Count of items processed (optional)