lcjoyinfo=replicate([ ],4)The above statement allocates only 4 bytes, which is not sufficient for the JOYINFO structure:
typedef struct {
UINT wXpos;
UINT wYpos;
UINT wZpos;
UINT wButtons;
} JOYINFO;
Since the structure consists of four 4-byte unsigned integers, the statement should change tolcjoyinfo = REPLICATE(CHR(0), 16)Generally CHR(0) is a cleaner way of populating the buffer rather than stuffing it with the spaces (CHR(32)). For this API call this is probably not important, but for many others it is.