private void EnumVolumes(IEnumVdsObject volumeEnum) { object iface; int fetched; while(0 == volumeEnum.Next(1, out iface, out fetched)) { var volume = iface as IVdsVolume; VdsVolumeProperties properties; Marshal.ThrowExceptionForHR(volume.GetProperties(out properties)); var volumeMF = volume as IVdsVolumeMF; } }
private void EnumDisks(IEnumVdsObject diskEnum) { object iface; int fetched; while(0 == diskEnum.Next(1, out iface, out fetched)) { var disk = iface as IVdsDisk; VdsDiskProperties properties; Marshal.ThrowExceptionForHR(disk.GetProperties(out properties)); Debug.WriteLine($"{properties.FriendlyName} {properties.DiskGuid} {properties.Status}"); } }
private void EnumDisks(IEnumVdsObject diskEnum) { object iface; int fetched; while(0 == diskEnum.Next(1, out iface, out fetched)) { var disk = iface as IVdsDisk; VdsDiskProperties properties; Marshal.ThrowExceptionForHR(disk.GetProperties(out properties)); Debug.WriteLine($"{properties.FriendlyName} {properties.DiskGuid} {properties.Status}"); } }
private void EnumPacks(IEnumVdsObject packEnum) { object iface; int fetched; while(0 == packEnum.Next(1, out iface, out fetched)) { var pack = iface as IVdsPack; IEnumVdsObject diskEnum; Marshal.ThrowExceptionForHR(pack.QueryDisks(out diskEnum)); EnumDisks(diskEnum); IEnumVdsObject volumeEnum; Marshal.ThrowExceptionForHR(pack.QueryVolumes(out volumeEnum)); EnumVolumes(volumeEnum); } }
private void EnumPacks(IEnumVdsObject packEnum) { object iface; int fetched; while(0 == packEnum.Next(1, out iface, out fetched)) { var pack = iface as IVdsPack; IEnumVdsObject diskEnum; Marshal.ThrowExceptionForHR(pack.QueryDisks(out diskEnum)); EnumDisks(diskEnum); IEnumVdsObject volumeEnum; Marshal.ThrowExceptionForHR(pack.QueryVolumes(out volumeEnum)); EnumVolumes(volumeEnum); } }
public static IEnumerable <T> EnumerateObjects <T>(IEnumVdsObject enumobject) where T : class { uint count; do { enumobject.Next(1, out IUnknown unknown, out count); if (count > 0) { T o; try { o = (T)unknown; } catch { throw new InvalidCastException("不支持的类型"); } yield return(o); } } while (count > 0); enumobject.Reset(); }
private void EnumVolumes(IEnumVdsObject volumeEnum) { object iface; int fetched; while(0 == volumeEnum.Next(1, out iface, out fetched)) { var volume = iface as IVdsVolume; VdsVolumeProperties properties; Marshal.ThrowExceptionForHR(volume.GetProperties(out properties)); var volumeMF = volume as IVdsVolumeMF; } }