I'm developing a screen manager for a GUI. It stores the coordinates of all objects on the screen. The screen manager is dynamically allocated and initialised:
I have a function which is designed to take the x,y coordinates of the mouse click (which are provided by the callback routine) and then search through the screen manager database to work out which object was clicked. It takes 3 arguments:Code:ScreenManager * sm = screenManagerNew();
The problem I have is that I cannot pass the address of the screen manager into the callback function, and I can't call the "whichObject" function from within the callback function either, because I still need the struct pointer to pass into this function and I can't find a way for the function to recognise it.Code:int screenManagerWhichObject(struct screenManager *sm, int x, int y);
I've tried all sorts so far, with no success: e.g.
a) declaring and initialising the screen manager struct at the top of main (compiler complains - initialiser element is not constant)
b) declaring the struct pointer at the top of the header file:
struct screenManager *sm;
c) Adding an additonal extern keyword for good measure
d) Declaring and initialising the struct within the draw() function for my program which includes all the callback functions
Generally the result I get is that even though I declare and initialise the screen manager struct, the callback function either does not recognise it or it recognises it as a NULL pointer.
Can anyone can shine some light on what I'm doing wrong here?