i belive that my memory leak is here:
Code:
else if(wParam==JoystickTimer)
{
JOYINFOEX b={0};
b.dwSize=sizeof(JOYINFOEX );
b.dwFlags=JOY_RETURNALL;
//cicle all possible joysticks
for (int i=0; i<16; i++)
{
int direction=0;
if(joyGetPosEx(i,&b)== JOYERR_NOERROR) //if theres any error then continue to next joystick
{
if(i==0)
inst->Joystick(-1, -1,-1);
else
inst->Joystick(0, -1,-1);
break;
}
long h =b.dwButtons;
//testing the directions
//will be 8 directions(inclued diagonals)
if (b.dwXpos == 0 && b.dwYpos ==65535)
{
direction=5;
}
else if (b.dwXpos == 65535 && b.dwYpos ==0)
{
direction=6;
}
else if (b.dwXpos == 65535 && b.dwYpos ==65535)
{
direction=7;
}
else if(b.dwXpos == 0 && b.dwYpos == 0)
{
direction=8;
}
else if (b.dwXpos == 0)
{
direction=1;
}
else if (b.dwXpos == 65535)
{
direction=2;
}
else if (b.dwYpos == 0)
{
direction=3;
}
else if (b.dwYpos == 65535)
{
direction=4;
}
inst->Joystick(i, direction,h); //lambda function
}
}
- the form is a subclass window(like my others controls). the inst is the pointer to the form objects\instances.
why i think that it's these 'if'? i comment it, and i don't see the memory leak.
so how can i detect how many Joysticks are connected to pc?