Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IsFileInUse
#1
Can you convert this function to QM?

Private Function IsFileInUse(sFile As String) As IsFileResults

Dim hFile As Long

If FileExists(sFile) Then

'note that FILE_ATTRIBUTE_NORMAL (&H80) has
'a different value than VB's constant vbNormal (0)!
hFile = CreateFile(sFile, _
GENERIC_READ, _
0, 0, _
OPEN_EXISTING, _
FILE_ATTRIBUTE_NORMAL, 0&)

'this will evaluate to either
'-1 (FILE_IN_USE) or 0 (FILE_FREE)
IsFileInUse = hFile = INVALID_HANDLE_VALUE

CloseHandle hFile

Else

'the value of FILE_DOESNT_EXIST in the Enum
'is arbitrary, as long as it's not 0 or -1
IsFileInUse = FILE_DOESNT_EXIST

End If
#2
Is it correct?

Function IsFileInUse
Code:
Copy      Help
function str'sFile

sFile.expandpath
if(!dir(sFile)) ret 0
int hFile=CreateFileW(@sFile GENERIC_READ 0 0 OPEN_EXISTING FILE_ATTRIBUTE_NORMAL 0)
CloseHandle hFile
ret hFile = INVALID_HANDLE_VALUE
#3
Correct.


Forum Jump:


Users browsing this thread: 1 Guest(s)