C#导入代码:
[DllImport("ntdll.dll",ExactSpelling = true,SetLastError = true)]
public static extern long NtQueryVolumeInformationFile(IntPtr FileHandle,out IO_STATUS_BLOCK IoStatusBlock,IntPtr FsInformation,uint Length,FSINFOCLASS FsInformationClass);
FSINFOCLASS枚举:
public enum FSINFOCLASS
{
FileFsVolumeInformation,FileFsLabelInformation,FileFsSizeInformation,FileFsDeviceInformation,FileFsAttributeInformation,FileFsControlInformation,FileFsFullSizeInformation,FileFsObjectIdInformation,FileFsDriverPathInformation,FileFsVolumeflagsInformation,FileFsSectorSizeInformation,FileFsDataCopyInformation,FileFsMetadataSizeInformation,FileFsFullSizeInformationEx,FileFsMaximumInformation
}
它的调用方式:
var handlePtr = Win32.CreateFile(@"\\.\c:",Win32.GENERIC_READ,Win32.FILE_SHARE_READ | Win32.FILE_SHARE_WRITE | Win32.FILE_SHARE_DELETE,Win32.OPEN_EXISTING,0);
if (handlePtr == IntPtr.Zero - 1)
return 0;
var iosb = new Win32.IO_STATUS_BLOCK();
var buffer = Marshal.AllocHGlobal(273);
var result = Win32.NtQueryVolumeInformationFile(handlePtr,out iosb,buffer,273,Win32.FSINFOCLASS.FileFsVolumeInformation);
// result=0xC0000003,should be zero
代码以管理权限运行。
错误代码的描述为:STATUS_INVALID_INFO_CLASS
但是据我所知,信息类的枚举是正确的。
我想念什么?