Board index » delphi » D1, disk drive ready?

D1, disk drive ready?

How can I detect wether there is a disk inserted in a disk drive (or a hard
drive formatted etc.), just to know is the drive letter valid or not. I have
a nice bit of assembler which uses interupt $21, subcode $36 for this and it
works great in dos/protected mode, but when used in a Windows program always
a nag screen (Drive not ready, Continue, Cancel, Retry) comes up. I couldn't
find anything in the 16bit API to do this (there's a routine in the 32bit
API which works, but the target is Win3.1 yet).

Can anyone help?
    Andy

--
----------------------------------------------------------------------------
Andreas H"orstemeier                       | ..Our continuing mission:
email: a...@scp.de                           | to seek out knowledge of C,
       a...@farpoint.westend.de            | to explore strange unix
fido:     2:2442/4005.3 / 2:2452/108.3     | commands, and to boldly code
                                           | where no one has man page 4.
----------------------------------------------------------------------------  

 

Re:D1, disk drive ready?


Quote
In article <E26vJK....@scp.de>, an...@scp.de (Andreas H?rstemeier) wrote:

]-How can I detect wether there is a disk inserted in a disk drive (or a hard
]-drive formatted etc.), just to know is the drive letter valid or not. I have
]-a nice bit of assembler which uses interupt $21, subcode $36 for this and it
]-works great in dos/protected mode, but when used in a Windows program always
]-a nag screen (Drive not ready, Continue, Cancel, Retry) comes up. I couldn't
]-find anything in the 16bit API to do this (there's a routine in the 32bit
]-API which works, but the target is Win3.1 yet).
]-
]-Can anyone help?
]-    Andy
]-

Here's an old post I've saved which may help you out...

     Date[ 02/17/1996
   Author[ Duncan McNiven
  Address[ duncan.mcni...@lecs.inet.fi
  Subject[ Catching drive not ready errors
 Keywords[

 Question[

Quote
>One small problem, if I select a
>drive (say B, a floppy drive) that has no disk in it, I get this lovely
>system message saying 'Drive not ready'.

          ]

 Response[
Piper  Keairnes 73241,1540  posted the following source code on
Compuserve a while ago.  It seems to work well.   Piper placed the
code in the public domain.

unit DiskUtil;

interface

function DiskCheck( DriveLetter: char ): boolean;
function DiskCheckWithInsert( DriveLetter: char ): boolean;
function DriveValid( DriveLetter: char): boolean;

implementation

uses
  SysUtils, WinProcs, WinTypes, Forms, Controls, Dialogs, FileCtrl;

function DiskCheck( DriveLetter: char ): boolean;
var
  oldMode: cardinal;
begin
  if DriveLetter in ['a'..'z'] then
    Dec(DriveLetter, $20);
  if not (DriveLetter in ['A'..'Z']) then
    raise EConvertError.Create('Invalid drive id: ' + DriveLetter);
  oldMode := SetErrorMode( SEM_FAILCRITICALERRORS );
  try
    Result := not (DiskSize(Ord(DriveLetter) - $40) = -1);
  finally
    SetErrorMode(oldMode);
  end;
end;

function DiskCheckWithInsert( DriveLetter: char ): boolean;
var
  oldCursor: TCursor;
begin
  Result := True;
  oldCursor := Screen.Cursor;
  Screen.Cursor := crHourglass;
  try
    while not DiskCheck(DriveLetter) do
      begin
        Screen.Cursor := crDefault;
        if MessageDlg( 'Insert a formatted disk in drive ' +
                       UpperCase(DriveLetter) +
                       ' then press OK.', mtConfirmation,
                       [mbOK,mbCancel], 0) = mrCancel then
          begin
            Result := False;
            Exit;
          end;
        Screen.Cursor := crHourglass;
      end;
  finally
    Screen.Cursor := oldCursor;
  end;
end;

function DriveValid( DriveLetter: char): boolean;
var
  ret: integer;
begin
  if DriveLetter in ['a'..'z'] then
    Dec(DriveLetter, $20);
  if not (DriveLetter in ['A'..'Z']) then
    raise EConvertError.Create('Invalid drive id: ' + DriveLetter);
  ret := GetDriveType(Ord(DriveLetter) - $41);
  Result := ret <> 0;
end;

end.
          ]

Mark Vaughan

Other Threads