I have been editing the Delphi source that John handed out with the last release so I could add in removing the drive after exiting.(Like u3) I am getting an error code 5. Could someone with more Delphi knowledge help?
Here is the code I added into the imgCloseClick event procedure:
var h: THandle; i: integer; Drive: String; dw: dword; bback:Boolean; errorstr:String; sq:integer; begin //This part will eject the drive and exit, but will throw an error if it can't. Drive:= ExtractFileDrive(Application.ExeName); h:=CreateFile(PChar('\\.\'+Drive), 0, 0, nil,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if h=INVALID_HANDLE_VALUE then MessageBox(Application.Handle,'invalid','error',MB_APPLMODAL); bback:=DeviceIOControl(h,{IOCTL_STORAGE_EJECT_MEDIA,$90020}$2d4808 , nil, 0, nil, 0, dw, nil); i:=GetLastError; CloseHandle(h); if i=6 then errorstr:='Device In Use' else errorstr:='Error Code:'+IntToStr(i); if bback=false then begin MessageBox(Application.Handle,PChar(errorstr),'Error',MB_APPLMODAL); sq:=MessageBox(Application.Handle,'Still Quit?','quit?',MB_YESNO); end else begin bolFadeToExit := true; FadeInOut(false); end; if sq=IDYES then begin bolFadeToExit := true; FadeInOut(false); end; end;