The usual culprit when errors like that arise is API declarations converted from VB6 without changing Long to Integer. I notice that the 'flags' argument is declared as type Long. I'm guessing that that is an oversight and it should be Integer. Try changing that declaration and see if it fixes the issue.