ZifNab
asked on
to madshi ... lock CD?
Hi,
I tried your 'lock' cd-code.
But it isn't working..
The code always fails on this point :
(get an error of 2, odd(reg.reg_flags) = True)
if (not DeviceIoControl(hDevice, VWIN32_DIOC_DOS_IOCTL,
@reg, sizeof(reg), @reg, sizeof(reg), cb, nil)) or
odd(reg.reg_Flags) then begin
// error
TheError := GetLastError;
exit;
end;
I can raise the points if you want.
Zif.
I tried your 'lock' cd-code.
But it isn't working..
The code always fails on this point :
(get an error of 2, odd(reg.reg_flags) = True)
if (not DeviceIoControl(hDevice, VWIN32_DIOC_DOS_IOCTL,
@reg, sizeof(reg), @reg, sizeof(reg), cb, nil)) or
odd(reg.reg_Flags) then begin
// error
TheError := GetLastError;
exit;
end;
I can raise the points if you want.
Zif.
ASKER
Madshi, thanks for replying... I test it at home, so I'll give you the reg error when I'm at home. Zif.
ASKER
Madshi,
Thanks, I found it myself...
I want to give you the points if you explain me two things :
1. Why running twice the code?
begin
result:=ldoit; //first
if not result then result:=ldoit; //second
end;
2. When you lock the drive and then try to eject it :
Windows turns blue, speaks about drive in use and asks if drive may be opened or not. (press ESC or OK)
Is there a way to prevent this message?
-> so that when drive is lock, nothing happens, maybe only a message box : showmessage('drive locked!').
Regards, Zif.
Thanks, I found it myself...
I want to give you the points if you explain me two things :
1. Why running twice the code?
begin
result:=ldoit; //first
if not result then result:=ldoit; //second
end;
2. When you lock the drive and then try to eject it :
Windows turns blue, speaks about drive in use and asks if drive may be opened or not. (press ESC or OK)
Is there a way to prevent this message?
-> so that when drive is lock, nothing happens, maybe only a message box : showmessage('drive locked!').
Regards, Zif.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Madshi,
SetErrorMode doesn't work... Sending an Eject command still give s 'blue screen'
.Too bad... Though there must be a way.
Zif.
SetErrorMode doesn't work... Sending an Eject command still give s 'blue screen'
.Too bad... Though there must be a way.
Zif.
That's strange. I've no blue screens...
If you send me your eject sources I'll check it for you. (But give me some time...)
Madshi.
If you send me your eject sources I'll check it for you. (But give me some time...)
Madshi.
ASKER
Madshi,
here is the source, very small :
procedure TCDEvents.OpenDoor;
var
SetParms: TMCI_Set_Parms;
begin
FFlags := 0;
FFlags := mci_notify or mci_set_door_open;
SetParms.dwCallback := 0;
fErrCode := mciSendCommand(ID, mci_Set, FFlags, Longint(@SetParms));
end;
Thanks for any help, Zif.
here is the source, very small :
procedure TCDEvents.OpenDoor;
var
SetParms: TMCI_Set_Parms;
begin
FFlags := 0;
FFlags := mci_notify or mci_set_door_open;
SetParms.dwCallback := 0;
fErrCode := mciSendCommand(ID, mci_Set, FFlags, Longint(@SetParms));
end;
Thanks for any help, Zif.
ZifNab,
try ejecting your volume with IOCtl instead of mci:
Add to my lock/unlock sources:
case action of
0: begin
s2:='Sperren des Volumes "'+drive+':".';
reg.reg_EAX:=$440D; // IOCTL for block devices
reg.reg_EBX:=ord(drive)-or d('A')+1; // zero-based drive ID
reg.reg_ECX:=$0848; // Lock / Unlock Volume command
reg.reg_EDX:=DWORD(@pb); // Paramblock
pb.operation:=0; // Lock
end;
1: begin
s2:='Entsperren des Volumes "'+drive+':".';
reg.reg_EAX:=$440D; // IOCTL for block devices
reg.reg_EBX:=ord(drive)-or d('A')+1; // zero-based drive ID
reg.reg_ECX:=$0848; // Lock / Unlock Volume command
reg.reg_EDX:=DWORD(@pb); // Paramblock
pb.operation:=1; // Unlock
end;
2: begin
s2:='Herauswerfen des Volumes "'+drive+':".';
reg.reg_EAX:=$440D; // IOCTL for block devices
reg.reg_EBX:=ord(drive)-or d('A')+1; // zero-based drive ID
reg.reg_ECX:=$0849; // Eject Media command
end;
end;
But unfortunately you can't close the door again with IOCtl. :-(
(You can do this with mci, can't you?)
Madshi.
try ejecting your volume with IOCtl instead of mci:
Add to my lock/unlock sources:
case action of
0: begin
s2:='Sperren des Volumes "'+drive+':".';
reg.reg_EAX:=$440D; // IOCTL for block devices
reg.reg_EBX:=ord(drive)-or
reg.reg_ECX:=$0848; // Lock / Unlock Volume command
reg.reg_EDX:=DWORD(@pb); // Paramblock
pb.operation:=0; // Lock
end;
1: begin
s2:='Entsperren des Volumes "'+drive+':".';
reg.reg_EAX:=$440D; // IOCTL for block devices
reg.reg_EBX:=ord(drive)-or
reg.reg_ECX:=$0848; // Lock / Unlock Volume command
reg.reg_EDX:=DWORD(@pb); // Paramblock
pb.operation:=1; // Unlock
end;
2: begin
s2:='Herauswerfen des Volumes "'+drive+':".';
reg.reg_EAX:=$440D; // IOCTL for block devices
reg.reg_EBX:=ord(drive)-or
reg.reg_ECX:=$0849; // Eject Media command
end;
end;
But unfortunately you can't close the door again with IOCtl. :-(
(You can do this with mci, can't you?)
Madshi.
ASKER
Madshi,
Why using IOCtl, is it better then using mci commands?
Thanks, Zif.
Why using IOCtl, is it better then using mci commands?
Thanks, Zif.
ZifNab,
Probably the same. But I hope no blue screens... :-)
Madshi.
Probably the same. But I hope no blue screens... :-)
Madshi.
ASKER
Madshi,
With IOCTL I still get this blue screen!
When pressing ESC. The Procedure fails, when pressing OK the drive is ejected.
So, with your OS, this blue screen doesn't appear???
Any ideas?
2de) Do you know a way, how to easely check if drive is locked?
Regards, zif.
With IOCTL I still get this blue screen!
When pressing ESC. The Procedure fails, when pressing OK the drive is ejected.
So, with your OS, this blue screen doesn't appear???
Any ideas?
2de) Do you know a way, how to easely check if drive is locked?
Regards, zif.
ZifNab,
I don't understand it...
But another try: Perhaps it works if you "flush" the drive before ejecting. In win95 flushing is not possible directly (as far as I know). So we use a little trick...
Add the following lines to the DosIOCTL function. "3" locks the drive for formatting. "4" unlocks it again. As a result the drive is flushed. But unfortunately it doesn't work always...
If the blue screen is still "alive", give me your eMail and I will send you a little test program (binary).
3: begin
s2:='Reservieren des Volumes "'+drive+':".';
reg.reg_EAX:=$440D; // IOCTL for block devices
reg.reg_EBX:=ord(drive)-or d('A')+1; // zero-based drive ID
reg.reg_ECX:=$084A;
reg.reg_EDX:=0;
end;
4: begin
s2:='Freigeben des Volumes "'+drive+':".';
reg.reg_EAX:=$440D; // IOCTL for block devices
reg.reg_EBX:=ord(drive)-or d('A')+1; // zero-based drive ID
reg.reg_ECX:=$086A;
end;
Regards, Madshi.
P.S: I suppose you don't have OSR-2 installed, have you? I'm asking because OSR-2 is a little bit more blue screen save.
P.P.S: I didn't implement a "test if locked" function. I don't know anymore (I wrote these routines a long time ago) if it wasn't possible or if there were other problems. I have in mind, that sometimes there was a lock count and sometimes there was not. In my programs my eject function has a parameter "force". If it is true, I unlock the drive (several times) until the unlock function returns an error.
I don't understand it...
But another try: Perhaps it works if you "flush" the drive before ejecting. In win95 flushing is not possible directly (as far as I know). So we use a little trick...
Add the following lines to the DosIOCTL function. "3" locks the drive for formatting. "4" unlocks it again. As a result the drive is flushed. But unfortunately it doesn't work always...
If the blue screen is still "alive", give me your eMail and I will send you a little test program (binary).
3: begin
s2:='Reservieren des Volumes "'+drive+':".';
reg.reg_EAX:=$440D; // IOCTL for block devices
reg.reg_EBX:=ord(drive)-or
reg.reg_ECX:=$084A;
reg.reg_EDX:=0;
end;
4: begin
s2:='Freigeben des Volumes "'+drive+':".';
reg.reg_EAX:=$440D; // IOCTL for block devices
reg.reg_EBX:=ord(drive)-or
reg.reg_ECX:=$086A;
end;
Regards, Madshi.
P.S: I suppose you don't have OSR-2 installed, have you? I'm asking because OSR-2 is a little bit more blue screen save.
P.P.S: I didn't implement a "test if locked" function. I don't know anymore (I wrote these routines a long time ago) if it wasn't possible or if there were other problems. I have in mind, that sometimes there was a lock count and sometimes there was not. In my programs my eject function has a parameter "force". If it is true, I unlock the drive (several times) until the unlock function returns an error.
ASKER
Madshi,
I still have the same problem, but because I've little time now, for my own projects I'll grade this question. You've given me a lot of information, thanks fo this!
Regards, Zif.
I still have the same problem, but because I've little time now, for my own projects I'll grade this question. You've given me a lot of information, thanks fo this!
Regards, Zif.
ZifNab, thanx.
please tell me the "reg" error, not the "GetLastError":
case reg.reg_EAX of
$01: s1:='Function not supportet.';
$05: s1:='Access denied or no medium in drive.';
$B0: s1:='Volume is not locked.';
$B1: s1:='Volume is locked.';
$B2: s1:='Volume is not removable.';
$B4: s1:='Lock count overflow.';
$B5: s1:='Eject error.';
else s1:=IntToStr(reg.reg_EAX);
end;
P.S: On my test computers (Win95,Win98,WinNT4) it works...
Madshi.