perkley
asked on
How do I eject two CD-Rom drives?
I am using Delphi 5, and I need to know how to eject both CD-ROM drives and also be able to close them using code.
TMediaPlayer has a problem with ejecting 2nd CD-ROM, but I would rather not use the TMediaPlayer anyways.
TMediaPlayer has a problem with ejecting 2nd CD-ROM, but I would rather not use the TMediaPlayer anyways.
ASKER
No that will not do the job. I want the second CD-ROM to open and I don't know how to get the correct handle to do so. That code is posted everywhere, I already knew about that, but I cannot get the second drive to open.
ASKER
Hey also if someone knows, is it possible to open a CD-ROM drive through the network? So in other words, if I had someone else's CD-ROM mapped as J: on my machine then I could open it on their machine running software on my machine.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
well excuse me for trying to help, get on with it then
regards
andy
regards
andy
ASKER
andysalih, don't take my response wrong. I was not upset, it's just that a lot of people don't seem to read the question very well lately. It is like everyone just wants to be the first accepted and they don't really understand what the problem is.
This is what I have found:
const // for the MCI calls
CD_OPEN = 'open cdaudio!%s: shareable';
CD_OPENDOOR = 'set %s: door open';
CD_CLOSEDOOR = 'set %s: door closed';
var {Global Variables}
err : integer;
returnString : array[0..4095] of Char;
TheDrive : char; // (a,b,c,d,e.....)
// Function to grant access to the drive
function TForm1.OpenCDMedia():boole an;
begin
err := mciSendString(pchar(format (CD_OPEN,[ TheDrive]) ),
returnString,sizeOf(return String),
handle);
if err = 0 then
result := true
else begin
MessageDlg('Error', mtWarning, [mbYes], 0);
result := false;
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
TheDrive := 'F';
OpenCDMedia;
// To open the door
err := mciSendString(pchar(format (CD_OPENDO OR,
[TheDrive])),
returnString,sizeOf(return String),
handle);
// to close the door
err := mciSendString(pchar(format (CD_CLOSED OOR,
[TheDrive])),
returnString,sizeOf(return String),
handle);
end;
This is what I have found:
const // for the MCI calls
CD_OPEN = 'open cdaudio!%s: shareable';
CD_OPENDOOR = 'set %s: door open';
CD_CLOSEDOOR = 'set %s: door closed';
var {Global Variables}
err : integer;
returnString : array[0..4095] of Char;
TheDrive : char; // (a,b,c,d,e.....)
// Function to grant access to the drive
function TForm1.OpenCDMedia():boole
begin
err := mciSendString(pchar(format
returnString,sizeOf(return
handle);
if err = 0 then
result := true
else begin
MessageDlg('Error', mtWarning, [mbYes], 0);
result := false;
end;
end;
procedure TForm1.Button1Click(Sender
begin
TheDrive := 'F';
OpenCDMedia;
// To open the door
err := mciSendString(pchar(format
[TheDrive])),
returnString,sizeOf(return
handle);
// to close the door
err := mciSendString(pchar(format
[TheDrive])),
returnString,sizeOf(return
handle);
end;
okey , well im not going to read your code but will this do for you
function GetCD_ID(WhichDrive: string): string;
var
VolumeName : array[0..255] of char;
FileSystemType : array[0..255] of char;
SerialNum : DWORD;
MaxFilenameLength : DWORD;
Flags : DWORD;
begin
if (GetVolumeInformation(PCha r(WhichDri ve),
VolumeName,
256,
@SerialNum,
MaxFilenameLength,
Flags,
FileSystemType,
256)) then
Result := (IntToHex(SerialNum shr 16, 3) +
IntToHex((SerialNum shl 16) shr 16, 4));
end;
function GetCD_Label(WhichDrive: string): string;
var
VolumeName : array[0..255] of char;
FileSystemType : array[0..255] of char;
SerialNum : DWORD;
MaxFilenameLength : DWORD;
Flags : DWORD;
begin
Result := 'No CD Present';
if (GetVolumeInformation(PCha r(WhichDri ve),
VolumeName,
256,
@SerialNum,
MaxFilenameLength,
Flags,
FileSystemType,
256)) then
Result := VolumeName;
end;
function FindFirstCDROM: shortstring;
var
AList : TStringList;
Counter : integer;
begin
Result := 'no CDROM present';
AList := TStringList.Create;
ListDrives(AList);
for Counter := 0 to AList.Count-1 do
if GetDriveType(PChar(Alist.S trings[Cou nter])) = DRIVE_CDROM then
Result := Alist.Strings[Counter]
end;
procedure ListDrives(Strings: TStringList);
const BufSize = 256;
var
Buffer : PChar;
P : PChar;
begin
GetMem(Buffer, BufSize);
try
Strings.BeginUpdate;
try
Strings.Clear;
if GetLogicalDriveStrings(Buf Size, Buffer) <> 0 then begin
P := Buffer;
while P^ <> #0 do begin
Strings.Add(P);
Inc(P, StrLen(P) + 1);
end;
end;
finally
Strings.EndUpdate;
end;
finally
FreeMem(Buffer, BufSize);
end;
end;
andy
function GetCD_ID(WhichDrive: string): string;
var
VolumeName : array[0..255] of char;
FileSystemType : array[0..255] of char;
SerialNum : DWORD;
MaxFilenameLength : DWORD;
Flags : DWORD;
begin
if (GetVolumeInformation(PCha
VolumeName,
256,
@SerialNum,
MaxFilenameLength,
Flags,
FileSystemType,
256)) then
Result := (IntToHex(SerialNum shr 16, 3) +
IntToHex((SerialNum shl 16) shr 16, 4));
end;
function GetCD_Label(WhichDrive: string): string;
var
VolumeName : array[0..255] of char;
FileSystemType : array[0..255] of char;
SerialNum : DWORD;
MaxFilenameLength : DWORD;
Flags : DWORD;
begin
Result := 'No CD Present';
if (GetVolumeInformation(PCha
VolumeName,
256,
@SerialNum,
MaxFilenameLength,
Flags,
FileSystemType,
256)) then
Result := VolumeName;
end;
function FindFirstCDROM: shortstring;
var
AList : TStringList;
Counter : integer;
begin
Result := 'no CDROM present';
AList := TStringList.Create;
ListDrives(AList);
for Counter := 0 to AList.Count-1 do
if GetDriveType(PChar(Alist.S
Result := Alist.Strings[Counter]
end;
procedure ListDrives(Strings: TStringList);
const BufSize = 256;
var
Buffer : PChar;
P : PChar;
begin
GetMem(Buffer, BufSize);
try
Strings.BeginUpdate;
try
Strings.Clear;
if GetLogicalDriveStrings(Buf
P := Buffer;
while P^ <> #0 do begin
Strings.Add(P);
Inc(P, StrLen(P) + 1);
end;
end;
finally
Strings.EndUpdate;
end;
finally
FreeMem(Buffer, BufSize);
end;
end;
andy
ASKER
Your example actually seems to be better than what I found. Anyway thanks for the excellent answer.
Uses MMSystem
Open CDROM Drive
mciSendString('Set cdaudio door open', nil, 0, handle);
Close CDROM Drive
mciSendString('Set cdaudio door closed', nil, 0, handle);
cheers
Andy