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?
 
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
0
 
perthgAuthor Commented:
For the second question, I should have specifically asked, how to create AutoPlay Event Handlers in windows XP with Delphi.

Thanks.
0
 
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
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
perthgAuthor Commented:
Thanks John,

but how can I make sure that the USB device is a digital camera and not a flash drive?
0
 
JohnjcesCommented:
Did this not help you?

Let me know or please accept.
0
 
perthgAuthor Commented:
Thanks, John
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.