There should be no problem using "mmsystem" with "windows". Indeed, the error in the screen shot in the question is not like a compiler error. Rather, the IDE cannot find the executable. Perhaps the antivirus software may delete the executable file, or I don’t know ..
DeviceIoControl . Delphi SO:
function CtlCode(DeviceType, _Function, Method, Access: Integer): DWORD;
begin
Result := DeviceType shl 16 or Access shl 14 or _Function shl 2 or Method;
end;
procedure ejectDisk(driveLetter: Char);
const
FILE_DEVICE_FILE_SYSTEM = $00000009;
FILE_DEVICE_MASS_STORAGE = $0000002d;
METHOD_BUFFERED = 0;
FILE_ANY_ACCESS = 0;
FILE_READ_ACCESS = $0001;
IOCTL_STORAGE_BASE = FILE_DEVICE_MASS_STORAGE;
// bogus constants below, rather CTL_CODEs should be pre computed.
FSCTL_LOCK_VOLUME = 6;
FSCTL_DISMOUNT_VOLUME = 8;
IOCTL_STORAGE_EJECT_MEDIA = $0202;
var
tmp: string;
handle: THandle;
BytesReturned: DWORD;
begin
tmp := Format('\\.\%s:', [driveLetter]);
handle := CreateFile(PChar(tmp), GENERIC_READ, FILE_SHARE_WRITE, nil,
OPEN_EXISTING, 0, 0);
DeviceIoControl(handle,
CtlCode(FILE_DEVICE_FILE_SYSTEM, FSCTL_LOCK_VOLUME, METHOD_BUFFERED,
FILE_ANY_ACCESS), nil, 0, nil, 0, BytesReturned, nil);
DeviceIoControl(handle,
CtlCode(FILE_DEVICE_FILE_SYSTEM, FSCTL_DISMOUNT_VOLUME, METHOD_BUFFERED,
FILE_ANY_ACCESS), nil, 0, nil, 0, BytesReturned, nil);
DeviceIoControl(handle,
CtlCode(IOCTL_STORAGE_BASE, IOCTL_STORAGE_EJECT_MEDIA, METHOD_BUFFERED,
FILE_READ_ACCESS), nil, 0, nil, 0, BytesReturned, nil);
CloseHandle(handle);
end;