I am currently embedding python in a C++ module. I have a problem in that one of the functions I am trying to build must be capable of accepting various structures for processing specific commands.

The function should be declared in C++ as follows

void Write(char *cmd, void* mystruct, struct_type structID);

The function itself should then take the 3rd parameter (it is an enumeration containing structure type id's) and then process the void pointer (2nd parameter) based on the structure type.

I am exporting all structure types into python, so it should have access to each type of structure. In the python code, I will fill out the structure, then send it to the Write function.

Is this possible?

Recommended Answers

All 5 Replies

Yes it should be.

If the write function is possible, how is a void pointer sent from python to the exposed C++ function? Is the casting dynamic?

Also, if I were to read and return a structure, will a void pointer suffice in python?

Look into the module struct in the Python manual.

Yes, it should all work but i dont know how a void pointer is sent to the exposed c++ function.

Yes, it should all work but i dont know how a void pointer is sent to the exposed c++ function.

Again, look into the module struct in the Python manual.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.