I am trying to interact with a dll from python using ctypes, reading the documentation the C++ method signature is of the following:
my_c_pp_function(user *param1[],const int_8 param2,const int_8 values3[],const int_8 length_param1)
Essentially the c++ function requires a list of users, an integer,a list of values and the number of users, also an integer
Note: the users is a structure containing name,age, and id. Something like:
typedef struct
{
char name[255];
int_16 age;
int_32 uid;
}user;
When I try calling this function from python code using ctypes I do:
def call_my_c_pp_function(list_of_users,int_param2,list_of_values,int_lenght_of_list):
myparam1=(ctypes.c_char_p * len(list_of_users))(*list_of_users)
myparam2=ctypes.c_int8(int_param2)
myparam3=(ctypes.c_int8 * len(list_of_values))(*list_of_values)
myparam4=ctypes.c_int8(int_lenght_of_list)
self.dll_object.my_c_pp_function.argtypes(ctypes.POINTER(ctypes.c_char_p),ctypes.c_int8,ctypes.POINTER(ctypes.c_int8),ctypes.c_int8)
ret_value=self.dll_object.my_c_pp_function(myparam1,myparam2,myparam3,myparam4)
Now every time I call the python function I get an error basically if the function succeeds the return value should be 0, any non zero number indicates some kind of problem.
I keep getting a large non-zero number as the return value. What could I possibly be doing wrong? is the way I'm creating the array of users, and the array of values wrong?
I am not sure how to populate/make use of the c++ user structure in my python code so that my list is not just a list of strings but a list of users
I'm using Python2.7 on Windows
Regards
std::string *you will have to find some way to populate it, aschar *is not astd::stringstd::stringin the public interface of the function (since it is a c++ type).ctypesonly provides support for C compatible data types.users, but you've not shown us anything about that type.