我想使用kernel32.dll下的GetFileInformationByHandle函数来获取NTFS唯一文件标识符。 函数声明是这样的:
Declare Auto Function GetFileInformationByHandle Lib "kernel32.dll" _
(ByVal hFile As IntPtr, ByRef lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Boolean
我的问题可能听起来很愚蠢但是,如何在visual basic中获取给定文件名的文件句柄(hFile As IntPtr)?
答案 0 :(得分:4)
您可以使用FileStream.SafeFileHandle属性:
Using fs As FileStream = New FileStream("c:\test.txt", FileMode.Create, FileAccess.Write)
Dim hFile = fs.SafeFileHandle.DangerousGetHandle()
' do something
End Using