Link to home
Start Free TrialLog in
Avatar of perthg
perthg

asked on

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

Avatar of perthg
perthg

ASKER

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

Thanks.
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
Avatar of perthg

ASKER

Thanks John,

but how can I make sure that the USB device is a digital camera and not a flash drive?
ASKER CERTIFIED SOLUTION
Avatar of Johnjces
Johnjces
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did this not help you?

Let me know or please accept.
Avatar of perthg

ASKER

Thanks, John