When your application no longer needs to receive periodic joystick messages, it should release the joystick using the joyReleaseCapture function. If your application does not release the joystick before ending, the joystick is released shortly after the capture window is destroyed.
The joyReleaseCapture function has the following syntax:
WORD joyReleaseCapture(wID)
The wID parameter is the joystick ID of the captured joystick. You can use the constants JOYSTICKID1 or JOYSTICKID2.