When you want to access C++ classes and their objects from C, there are a few well-known patterns around. Google for them.
An easy one is to wrap it in a piece of OO C:
typedef void* my_handle_t;
handle_t create(void); // returns address of new'ed object
void destroy(handle_t); // deletes object
MsgData_t* get_data(handle_t); // returns address of data in object
That leaves the question of how to make MsgData_t
accessible from C. I see three possibilities:
- move its definition into its own header (IMO best, but you already said you're not allowed to do it)
- duplicate its definition (easy, but IMO worst alternative)
- fiddle with the preprocessor (
#ifndef __cplusplus
) to make the C++ header accessible for a C parser (hackish, but avoids the code duplication of #2)