How to pass char** in python ctype?

How to pass char** in python ctype and once it is modified in 'C++' code how do i access it

  • I'm trying to access a c++ function from python using ctypes int func(void**, char**policy_names) { // 1.allocate memory to policy_names // 2.fill policy_names with policy names ex: policy_names[0] ="hi" policy_names[1]="bye" return 0; } memory allocation happens in c++ func mentioned above and the policy_name is filled with list of strings . python code: policy_list = POINTER(c_char)() Handle = c_void_p() Getpolicy = lib.func() func.argtypes = [c_void_p, POINTER(POINTER(c_char))] x = GetPolicy(Handle, policy_list) Questions I have is Is it the right way of passing char** args using ctypes ?? once the c++ function allocates , fills the policy_names how do i access it back in python??

  • Answer:

    I some how fixed it after some research it should be the following way: I'm trying to access a c++ function from python using ctypes python code: policy_list = POINTER(c_char_p)() Handle = c_void_p() Getpolicy = lib.func() x = GetPolicy(Handle, policy_list) how to access it is policy_list[0], .....

Ram at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.