Search code examples
vb6filehandlecreatefilewindow-handles

CreateFile Returns negative handle


Any ideas why the createfile() function would be returning -1.

Handle = CreateFile(filename, &H80000000, 0, 0, 3, &H80, 0)

This is run a few times. I was thinking perhaps maybe the file is not being closed properly?

EDIT

Err.LastllError returns 32.


Solution

  • You are probably right about not closing the file someplace. I would start by looking where I am opening the file and making sure I have an error handling routine in place. In the error handler I would check the value of "Handle" and if it's valid call CloseHandle(Handle). Also, since you are opening the file for read access, you could change you dwShareMode parameter to 1 to allow subsequent open for read operations on the same file.