Re: problems accessing compact flash card
From: Nicolai Hansen (nic_at_aub.dk)
Date: 11/22/04
- Next message: Maarten Wiltink: "Re: Spaces"
- Previous message: VBDis: "Re: Spaces"
- In reply to: Marco van de Voort: "Re: problems accessing compact flash card"
- Next in thread: AlanGLLoyd: "Re: problems accessing compact flash card"
- Reply: AlanGLLoyd: "Re: problems accessing compact flash card"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 21 Nov 2004 23:23:50 -0800
Marco van de Voort <marcov@stack.nl> wrote in message news:<slrncpopef.ddp.marcov@turtle.stack.nl>...
> On 2004-11-18, Nicolai Hansen <nic@aub.dk> wrote:
> > I am working on an application storing data on a compact flash card. I
> > want to eject this card after the data is saved.
> > The eject function works fine when it is used alone, but when I save
> > some data to the card, the CreateFile part returns an invalid handle.
> > As if the drive is in use.
> > I tried to flush all files before closing them but this does not work.
> > Anyone got a clue about this?
>
> - After closing it can take up to seconds before locks are removed.
> - do you start programs from that cf?
I found the problem. There was a drivecombobox pointing to the CF
drive :)
In case anyone ever need to eject a CF from Delphi, this is how I've
done it (this took me hours and hours to figure out):
var
h: THandle;
dw: DWORD;
begin
...
if SaveForm.EjectCF then
begin
repeat
t:=0;
repeat
sleep(100);
h:=CreateFile(PChar('\\.\'+SaveForm.Drive+':'), GENERIC_ALL,
0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if integer(h)<0 then // wtf happened to if h=INVALID_HANDLE?
CloseHandle(h);
inc(t);
until (integer(h)>-1) or (t=100);
DeviceIOControl(h, {IOCTL_STORAGE_EJECT_MEDIA}$2d4808, nil, 0,
nil, 0, dw, nil); // will just fail if h is invalid
i:=GetLastError;
CloseHandle(h);
until (i=0) or (MessageDlg('Failed to eject CF', mtWarning,
[mbAbort, mbRetry], 0)=mrAbort);
end;
end;
- Next message: Maarten Wiltink: "Re: Spaces"
- Previous message: VBDis: "Re: Spaces"
- In reply to: Marco van de Voort: "Re: problems accessing compact flash card"
- Next in thread: AlanGLLoyd: "Re: problems accessing compact flash card"
- Reply: AlanGLLoyd: "Re: problems accessing compact flash card"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|