Reputation: 143
I am trying to wrap a C function that requires an array of structures to be passed to it.
The function definition in my .i file is:
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)
The structs SCRIPT_CONTROL, SCRIPT_STATE and SCRIPT_ITEM have all been previously defined in the .i file.
I can indicate that pcItems is a return values by including the following lines:
%include <typemaps.i>
%apply int *OUTPUT {int *pcItems};
However, attempting to do the same with with pItems:
%apply SCRIPT_ITEM *OUTPUT {SCRIPT_ITEM *pItems};
I get this warning:
Can't apply (SCRIPT_ITEM *OUTPUT). No typemaps are defined.
How do I indicate that pItems is a return value?
Also, how do I create the array of SCRIPT_ITEM structures from within Python?
Upvotes: 1
Views: 888
Reputation: 143
I've managed to find the way to do this by changing my .i file as follows:
%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)
Upvotes: 2