Aber vergiß dann nicht vorher abzufragen wieviele Partitionen vorhanden sind, denn du mußt ja mindestens für jede Partition da hinten Speicherplatz reservieren.
Da ich selber ums mir einfacher zu machen und Delphi die Verwaltung des Speicherplatzes aufzubrumen gerne Variablen verwende, hab ich das einfach so gelöst
mit Variable:
Delphi-Quellcode:
Type _DRIVE_LAYOUT_INFORMATION_EX = packed Record
PartitionStyle: _PARTITION_STYLE;
PartitionCount: LongWord;
Union: packed Record Case _PARTITION_STYLE of
PARTITION_STYLE_MBR: (Mbr: _DRIVE_LAYOUT_INFORMATION_MBR);
PARTITION_STYLE_GPT: (Gpt: _DRIVE_LAYOUT_INFORMATION_GPT);
End;
PartitionEntry: packed Array[0..31] of _PARTITION_INFORMATION_EX;
End;
Var DLI: _DRIVE_LAYOUT_INFORMATION_EX;
DeviceIoControl(Dh, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, nil, 0,
@DLI, SizeOf(_DRIVE_LAYOUT_INFORMATION_EX), W, nil);
...
über Pointer:
Delphi-Quellcode:
Type _DRIVE_LAYOUT_INFORMATION_EX = packed Record
PartitionStyle: _PARTITION_STYLE;
PartitionCount: LongWord;
Union: packed Record Case _PARTITION_STYLE of
PARTITION_STYLE_MBR: (Mbr: _DRIVE_LAYOUT_INFORMATION_MBR);
PARTITION_STYLE_GPT: (Gpt: _DRIVE_LAYOUT_INFORMATION_GPT);
End;
PartitionEntry: packed Array[0..0] of _PARTITION_INFORMATION_EX;
End;
pDRIVE_LAYOUT_INFORMATION_EX = _DRIVE_LAYOUT_INFORMATION_EX^;
Var pDLI: pDRIVE_LAYOUT_INFORMATION_EX;
DLI := GetMem(SizeOf(_DRIVE_LAYOUT_INFORMATION_EX)
+ SizeOf(_PARTITION_INFORMATION_EX) * (AnzahlDerPartitionen - 1));
Try
DeviceIoControl(Dh, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, nil, 0,
DLI, SizeOf(_DRIVE_LAYOUT_INFORMATION_EX), W, nil);
...
Finally
FreeMem(DLI);
End;
// -1 da Array[0..0] of _PARTITION_INFORMATION_EX bereits einmal _PARTITION_INFORMATION_EX einschließt