I am currently using the out of date open BGI library for C as that is what my uni wants us to do but I can't figure out how to use this function.
extern void getmousestate(g_mousestate *state);
Definition:
void getmousestate(g_mousestate * state)
{
CHECK_GRAPHCS_INITED
state->x = sharedStruct->mouseX;
state->y = sharedStruct->mouseY;
state->buttons = sharedStruct->mouseButton;
}
g_mousestate Definition:
typedef struct mousestate {
int x, y;
int buttons;
}g_mousestate;
sharedStruct definition:
static SHARED_STRUCT * sharedStruct;
SHARED_STRUCT Definition:
typedef struct
{
int mouseX, mouseY;
int mouseButton;
int keyCode;
int keyLetter;
int visualPage;
} SHARED_STRUCT;
The sort of thing I was trying to do to call:
g_mousestate *a;
getmousestate(a->x);
But I don't know what to initialize a to...
I assumed this function could tell me what position the mouse is in and what buttons are being pressed etc, but I can't figure out how to call the function properly. Very much a beginner here, any help would be appreciated.
OK, beginner, let's start. You want to do:
g_mousestate *a;
getmousestate(a->x);
to get the x-position of the mouse. First note that you have declared a
as a pointer, but no memory has been allocated for it (it points to nothing yet). So first you must have memory for the g_mousestate
object:
g_mousestate a;
getmousestate(&a);
Now a
is no longer a pointer but an object and you pass a pointer to the getmousestate
function by taking the address of a
with the &
operator ("address-of").
You need to do no more since, if you look at the definition of the function, you see that all members are filled in by it.