2

I created a C program and choose to use python as my GUI creator I wrote the python GUI and decided to create a struct

typedef struct GUIcommunicator
{
    char action[MAX_SIZE];
    char params[MAX_PARAMS][MAX_SIZE];
}GUIcommunicator;

I using this answer I will return the struct from the python receive him in my C code

but I don't know how. And I'd like to some help

(the function that sends the struct (the python code) already got the action and the params as string list )

Eyal Elbaz
  • 31
  • 9

2 Answers2

1

Regardless of the direction of the call, you end up with a PyObject* in C that refers to a list of strings. Fetch each element, then fetch the string data pointer and size for a Python 2 str or (the UTF-8 encoding of) a Python 3 str. Check the size against MAX_SIZE (probably MAX_SIZE-1) and beware of embedded null characters, which your struct presumably cannot represent.

There are of course ways of accepting any iterable, converting elements to strings, etc., if you want that flexibility.

Davis Herring
  • 36,443
  • 4
  • 48
  • 76
1

If you are developing a linux based application, you can perform Inter-Process Communication using FIFO files

For windows based applications, you could use Named-pipes

Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50