In the following example, the GetPos function calls the Poll function to retrieve information about the joystick:
UINT GetPos(UINT id, JOYINFO FAR * lpInfo)
{
if(id > 1)
return JOYERR_PARMS; // Error...bad parameter
lpInfo->wZpos = 0;
if(wcAxes == 3) // Poll 3-axis joystick?
{
if(id == 1) // If 3D, must be joystick 1
return JOYERR_UNPLUGGED;
else
{
if(!Poll(1, iZaxis)) // Poll z axis
return JOYERR_UNPLUGGED;
lpInfo->wZpos = wYpos;
if(!Poll(0, 0)) // Poll x and y axes
return JOYERR_UNPLUGGED;
}
}
else if(!Poll(id, 0)) // Poll 2-axis joystick
return JOYERR_UNPLUGGED;
lpInfo->wButtons = wButtons;
lpInfo->wXpos = wXpos;
lpInfo->wYpos = wYpos;
return JOYERR_NOERROR;
}