GetFileInformationByHandle does not work

  • Thread starter Benjamin Lukner
  • Start date
B

Benjamin Lukner

Hi!

I need some help getting GetFileInformationByHandle to work...
I don't know why, but I'm still getting an empty result.

I tried to use the BY_HANDLE_FILE_INFORMATION structure and also a byte
array having the same size. The byte array works fine for FindFirstFile,
but GetFileInformationByHandle always returns '0'.

Perhaps somebody's got a hint for me:

'[DECLARES]

Private Structure FILETIME
Dim dwLowDateTime As Int32
Dim dwHighDateTime As Int32
End Structure

Private Structure BY_HANDLE_FILE_INFORMATION
Dim dwFileAttributes As Int32
Dim ftCreationTime As FILETIME
Dim ftLastAccessTime As FILETIME
Dim ftLastWriteTime As FILETIME
Dim dwVolumeSerialNumber As Int32
Dim nFileSizeHigh As Int32
Dim nFileSizeLow As Int32
Dim nNumberOfLinks As Int32
Dim nFileIndexHigh As Int32
Dim nFileIndexLow As Int32
Dim dwOID As Int32
End Structure

Private Declare Function GetFileInformationByHandle Lib "Coredll"
Alias "GetFileInformationByHandle" ( _
ByVal hFile As Int32, _
ByVal lpFileInformation() As Byte _
) As Int32

'Private Declare Function GetFileInformationByHandle Lib "Coredll"
Alias "GetFileInformationByHandle" ( _
' ByVal hFile As Int32, _
' ByVal lpFileInformation As
BY_HANDLE_FILE_INFORMATION _
' ) As Int32

Private Declare Function FindFirstFile Lib "Coredll" Alias
"FindFirstFileW" ( _
ByVal lpFileName As String, _
ByVal lpFindFileData() As Byte _
) As Int32

'[FUNCTION]

Public Sub GetSize()

Dim hFile As Int32 = INVALID_HANDLE_VALUE
Dim oInfo As BY_HANDLE_FILE_INFORMATION
Dim oData As WIN32_FIND_DATA
Dim yData() As Byte
Dim yInfo(55) As Byte
Dim lReturn As Int32

' Creating byte array from STRUCT
yData = WIN32_FIND_DATA__TO__BYTE(New WIN32_FIND_DATA)
hFile = FindFirstFile("\Application\r*", yData)
oData = BYTE__TO__WIN32_FIND_DATA(yData)

If hFile <> INVALID_HANDLE_VALUE Then
MsgBox(oData.cfileName)
lReturn = GetFileInformationByHandle(hFile, yInfo) ' RETURNS '0'
If lReturn <> 0 Then
MsgBox(BitConverter.ToInt32(yInfo, 36).ToString)
End If
FindClose(hFile)
End If

End Sub


Kind regards,

Benjamin Lukner
trinomix GmbH
 
B

Benjamin Lukner

Have you tried using an IntPtr as first parameter (the hFile)?

I just checked that.
It's still got the same behaviour:
FindFirstFile works
GetFileInformationByHandle with byte array returns '0'
GetFileInformationByHandle with BY_HANDLE_FILE_INFORMATION throws a
NotSupportedException :'-(

Does anyone have some working piece of code using the API function?
I've spent the last two days completely with working on this single code
line...

<Marvin> I think you ought to know that I'm feeling very depressed </Marvin>


Kind regards,

Benjamin Lukner
 
B

Benjamin Lukner

Benjamin said:
I just checked that.
It's still got the same behaviour:
FindFirstFile works
GetFileInformationByHandle with byte array returns '0'

Finally it works!
The handle from FindFirstFile doesn't work with GetFileInformationByHandle.
I have to use CreateFile instead.


Benjamin Lukner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top