c - Python, when to use ctypes.byref to pass as reference -
i've loaded function third party dll. i've been successful accessing function entry point library via ctypes.windll.loadlibrary
. function has 30 parameters including many 2 dimensional arrays. function prototype specifies parameters passed reference in cases. when make function call i'm getting return code indicates there problem internal variable, makes me think i've passed wrong pointers. (it's vague.) question is, under circumstances should use ctypes.byref
pass reference. example, lets have following:
double_matrix = (ctypes.c_double * 100) * 100 my_array = double_matrix()
should pass my_array or ctypes.byref(my_array)?
my_string = ctypes.create_string_buffer("hello world!")
what object created using types.create_string_buffer()? should pass my_string or ctypes.byref(my_string) if passing reference required?
edit:
i don't have code dll.
function prototype looks except there 5 or 6 of each type.
int process(char *input, int indicator, double (*dmatrix)[100][100], int (*groups)[100]);
thanks
generally, if prototype looks this:
int process(char *input, int indicator, double (*dmatrix)[100][100], int (*groups)[100]);
then 1 can assume worth trying following
pass parameters follows: input reference indicator value dmatrix reference groups reference
generally speaking assuming prototype c function , given referring ctypes python; process function expecting pass address reference following parameters: input, dmatrix, , groups. indicator variable on other hand passed direct value. when parameter passed reference means receiving function can change value , whatever changes made, caller able analyze changes directly (as both sharing same particular address space).
if had pass 30 parameters on , over, i'd come bridge function pack them structure fitting structure of target parameter list of function , call function. unpack results (if any) on way out of bridge function.
of course guess degree, of trial fire...
Comments
Post a Comment