I can't quite see the problem here, but why don't you just set the length of the FJoyCaps array before the loop? Also, are you supposed to zero the memory for the TDIDevCaps structure before setting the dwSize?