Drive Letter of Digital Camera

Hi,

How can I get the drive letter of USB drive of my Digital camera?

When the camera drive is activated I get the usual windows menu dialog for the drive. Same as the dialog when you insert a CD (Print Pictures, View SlideShow, Take no Action etc.) . My second question is,  how can I programatically insert a menu for my own application in the dialog?

regards,
Partha

perthgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

perthgAuthor Commented:
For the second question, I should have specifically asked, how to create AutoPlay Event Handlers in windows XP with Delphi.

Thanks.
JohnjcesCommented:
First, since this is a USB device, you will need a USB routine to check for devices plugged in and removed. That can be found at:

http://www.swissdelphicenter.ch/torry/showcode.php?id=2211

Next, you will want to gather up all your existing removable drives when your application starts. Then when you plug in your camera or a USB memory stick, you will be able to get the drive letter.

I do it this way in  TAppName.create

 for Drive := 'a' to 'z' do
  if GetDriveType(PChar(Drive+':\')) = DRIVE_REMOVABLE then
   DriveList.Add(Drive);

I will set a timer as well toe nsure that everything is loaded up before I go and check what removable drives my system has.

Next, when a USB device is inserted, I start a thread using a thread component like abfThreadComponent and do thesame thing... same check, but I do it twice to ensure that it the drive, gets initialized. I do it like:

procedure deviceinserted(sender: tobject);  // procedure in the USB unit
begin
InsertThread.Execute;
end;

//My thread execute routine:
 for X := 1 to 2 do
 begin
 for Drive := 'd' to 'z' do
    if GetDriveType(PChar(Drive+':\')) = DRIVE_REMOVABLE then
      begin
     if not DriveInList(Drive) then
      DriveList.Add(Drive);
      USBDrive := Drive;
      end;
 delay(1000);
 end;

Of course I make a drive list and keep track and search there for my drives and check DriveInList to ensure that what was pluged in is not in the list and is therefoe my newest removable drive. Drive = my USB stick.

DriveInList is:

function DriveInList(Drive:Char) : Boolean;
var
 X : Integer;
begin
 result := False;
 // Check to see if drive already exists.
 For X := 0 to DriveList.Count -1 do
   if DriveList.Strings[x] = Drive then
    result := true;
end;

The second part of your question should really be asked in a seperate thread since that is a seperate topic. And, where do you want this menu item? In explorer? If you want USB autoplay, that will be a search of some program or file on the memory stick/camera and if found, run it.

I hope this made sense to you and helps.

John
perthgAuthor Commented:
Thanks John,

but how can I make sure that the USB device is a digital camera and not a flash drive?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

JohnjcesCommented:
The only way to know for sure is that all digital cameras that are capable of showing up as a removable drive will have a directory in the root called

\DCIM

under this directory will be another directory that is an abrevation of the camera make such as

1002OLYM for an Olympus camera. Under this directory will be your pictures in some form of date-PicNum.jpg

With a FindFile routine or component, (search Torry or DelphiPages for FindFile for D5, works well from D5 to D7), find the DCIM directory.

I do it like:

procedure CheckDCIM;
begin
 StatusBar1.Panels[1].Text := '';
 if DirectoryExists(USBDrive + ':\DCIM') then
  begin
   PictureList := TStringList.Create;
   FindFile1.Path := USBDrive + ':\DCIM\';
   FindFile1.FileMask := '*.jpg';
   PictureList.AddStrings(FindFile1.SearchForFiles);
   FindFile1.FileMask := '*.jpeg';
   PictureList.AddStrings(FindFile1.SearchForFiles);
   FindFile1.FileMask := '*.tif';
   PictureList.AddStrings(FindFile1.SearchForFiles);
   FindFile1.FileMask := '*.tiff';
   PictureList.AddStrings(FindFile1.SearchForFiles);
  if PictureList.Count > 0 then
    begin
     Screen.Cursor := crHourGlass;
     PictureDirectory := ExtractFileDir(PictureList.Strings[PictureList.Count - 1]);
     ImageViewer.Directory := PictureDirectory;
     ImageViewer.LoadImages;
    end
     else
      begin
       StatusBar1.Panels[1].Text := 'No pictures were found in camera!';
       StatusBar1.Panels[0].Text := ' Pictures in Camera: 0'
      end;
   PictureList.Free;
   Delay(1250);
   Screen.Cursor := crDefault;
  end;
end;

By the way, Delay is a dealy routine I like so things appear nicer to the end user. SOmetimes "things" can go too quickly!

Delay:

procedure Delay(MSecs: Cardinal);
var
 FirstTick, CurrentTick : Cardinal;
 Done : Boolean;
begin
 Done := FALSE;
 FirstTick := GetTickCount;
 While Not Done do
  begin
   Application.ProcessMessages;
   CurrentTick := GetTickCount;
   If Int64(CurrentTick) - Int64(FirstTick) < 0 Then
    begin
     If CurrentTick >= (Int64(FirstTick) - High(Cardinal) + MSecs) Then
      Done := TRUE;
       End
        Else
         If CurrentTick - FirstTick >= MSecs Then
          Done := TRUE;
  end;
end;

This should get you started very well!

John

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JohnjcesCommented:
Did this not help you?

Let me know or please accept.
perthgAuthor Commented:
Thanks, John
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.