public static void DiskCreateDiskMBR(SafeHandle handle, uint Signature) { CREATE_DISK r = new CREATE_DISK(); r.PartitionStyle = PARTITION_STYLE.MBR; r.Mbr.Signature = Signature; var bufSize = Marshal.SizeOf(r); var buf = Marshal.AllocHGlobal(bufSize); Marshal.StructureToPtr(r, buf, false); uint bytesReturned = 0; var b = DeviceIoControl(handle.DangerousGetHandle(), IOCTL_DISK_CREATE_DISK, buf, (uint)bufSize, IntPtr.Zero, 0, ref bytesReturned, IntPtr.Zero); Marshal.FreeHGlobal(buf); if (!b) { throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); } }
public static extern Boolean DeviceIoControl(SafeFileHandle hDevice, Int32 dwIoControlCode, ref CREATE_DISK lpInBuffer, int nInBufferSize, IntPtr lpOutBuffer, Int32 nOutBufferSize, ref Int32 lpBytesReturned, IntPtr lpOverlapped);