Как программно сделать eject для CD-ROM'a, ZIP'a?
BOOL EjectDrive95(char *path) { HANDLE hDevice; DWORD dw; BOOL fResult; DIOC_REGISTERS reg;
hDevice = CreateFile("\\\\.\\vwin32", 0, 0, NULL, 0, FILE_FLAG_DELETE_ON_CLOSE, NULL); if (hDevice == INVALID_HANDLE_VALUE) return FALSE; reg.reg_EAX = 0x440D; reg.reg_EBX = toupper(path[0]) - 'A' + 1; reg.reg_ECX = 0x0849; fResult = DeviceIoControl(hDevice, VWIN32_DIOC_DOS_IOCTL,®, sizeof(reg), ®, sizeof(reg), &dw, 0); CloseHandle(hDevice); return fResult; }
BOOL EjectDriveNT(char *path) { HANDLE hDisk; DWORD dwRc; TCHAR tsz[8]; SECURITY_ATTRIBUTES sa;
wsprintf(tsz, TEXT("\\\\.\\%c:"), TEXT('@') + toupper(path[0]) - 'A' + 1); sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; hDisk = CreateFile(tsz, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,&sa, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL); if (hDisk != INVALID_HANDLE_VALUE) { FlushFileBuffers(hDisk); return DeviceIoControl(hDisk, IOCTL_DISK_EJECT_MEDIA, NULL, 0, NULL, 0,&dwRc, NULL); } return FALSE; }
![](image/c005.gif)