0

I'm writing an application in Delphi. Its a file browser with copying, delete etc. for school project. When app is detecting removable devices, and I'm trying to copy file to one of them. I'm getting c0000013 error with parameters 76b6b7c 4 76b6b7c 76b6b7c.

I read that changing value ErrorMode to 2 fixes it. Yes it fixes but i can't change this variable directly from Delphi app. I know that one usb is usb ghost, but i don't know how to hide this one usb or skip it. I can't even check that because of this error.

Any other idea to fix it from app if it's needed ?

Renaissance
  • 798
  • 5
  • 15
  • Although it's a system global setting, MS shows where you turn off "system hard error message dialog box" in possibility of it popping up in an unattended environment: http://support.microsoft.com/kb/128642/en-us – Sertac Akyuz Sep 29 '13 at 12:20

1 Answers1

0

Error c0000013 means that there is no (readable) media the in location that you're accessing.
See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx

As such it is perfectly ok to check for the error and move on if there's no media.

You can get a list of all USB devices like so (see: Delphi - How to get list of USB removable hard drives and memory sticks?)

procedure GetUsbDrives(List: TStrings);
var
  DriveBits: set of 0..25;
  I: Integer;
  Drive: AnsiChar;
begin
  List.BeginUpdate;
  try
    Cardinal(DriveBits) := GetLogicalDrives;

    for I := 0 to 25 do
      if I in DriveBits then
      begin
        Drive := Chr(Ord('a') + I);
        if GetBusType(Drive) = BusTypeUsb then
          List.Add(Drive);
      end;
  finally
    List.EndUpdate;
  end;
end;

If you then access the drive and get the error, simply use a try-except to dectect if any problems occur, see: Delphi - how to get a list of all files of directory

function IsDevicePresent(DriveLetterOrPath: string): boolean;
const 
  success = 0;
  Win_DeviceIsPresent = true;
  Fail_DeviceNotPresent = false;
var 
  SearchRec: TSearchRec;
  Drive: string;
begin
  Drive:= ExtractFileDrive(DriveLetterOrPath);
  try
    Result:= (FindFirst(Drive, faAnyFile, SearchRec) = success);
  except 
    Result:= Fail_DeviceNotPresent;
  end; {try}
end;
Community
  • 1
  • 1
Johan
  • 74,508
  • 24
  • 191
  • 319
  • Thanks for reply, but it didn't helps, if i check each of pendrive connected, by if IsDevicePresent(drive) = TRUE then for ex. copying There is no error, but simply do not copy file on any of connected usb i chose. – Malcolm Cartney Sep 29 '13 at 16:45
  • @MalcolmCartney, of course it does not copy, that's the whole point of the code, You cannot copy to a stick that gives errors. That's obvious. Either the stick is damaged, or your windows needs a driver update. – Johan Sep 29 '13 at 19:00
  • But i mean that, now i can't copy even on the properly working usb flash. It always gives False i think. – Malcolm Cartney Sep 30 '13 at 14:28
  • Then you'll need to tweak the code a bit until it works the way you want. – Johan Oct 01 '13 at 03:31