4

WIA 2 on Windows 7 doesn't detect my camera while WIA 1 on Windows XP detects it.

I try to run my program as admin.

My camera is :

Asus usb2 webcam.

Delphi return the message:

(like this) not available any wia devices from specified type

or

Access Violation at address ...... in module ......

I use this code:

procedure TForm1.Button9Click(Sender: TObject);
Const
   wiaFormatBMP ='{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}';
var
   CommonDlg: ICommonDialog;
   AImage: IImageFile;
   ImagePath: String;
   DeviceManager1 :iDeviceManager;
begin
   CommonDlg := createOleObject('WIA.CommonDialog') as ICommonDialog;
   DeviceManager1 := createOleObject('WIA.DeviceManager') as  iDeviceManager;
   edit1.Text:=  inttostr( DeviceManager1.DeviceInfos.Count);
   AImage := CommonDlg.ShowAcquireImage(UnspecifiedDeviceType,UnspecifiedIntent,
                                        MaximizeQuality,wiaFormatBMP,true,False,True);
   ImagePath := 'C:\temp\test.bmp';
   AImage.SaveFile(ImagePath);
end;
Hailei
  • 42,163
  • 6
  • 44
  • 69
Ahmad
  • 41
  • 1
  • 5
  • in this lin return 0 – Ahmad May 06 '12 at 17:35
  • and in this line AImage := CommonDlg.ShowAcquireImage(UnspecifiedDeviceType,UnspecifiedIntent, MaximizeQuality,wiaFormatBMP,true,False,True); return message :not available any wia devices from specified type – Ahmad May 06 '12 at 17:35
  • 2
    Have you checked if your camera is present and enabled in the *Control Panel / Device Manager / Imaging devices* ? I could simulate what you've described (without the access violation though), it's (obviously :-) enough to disable all imaging devices. About the AV, it's always better to add at least a check like this `if not VarIsEmpty(Variable) then Variable.DoSomething` before you access the late binded interface variable (it might be undefined or in some erroneous state). – TLama May 06 '12 at 19:12
  • 1
    thank you TLama this device is present and enabled , the win xp is run on VMW (virtual machine) at same computer as win 7 that means the device is Works well , no variables in this sentence just constants : CommonDlg.ShowAcquireImage(UnspecifiedDeviceType ,UnspecifiedIntent, MaximizeQuality , wiaFormatBMP , true , False , True); 1-UnspecifiedDeviceType or cameraDeviceType or ScannerDeviceType 2-UnspecifiedIntent or ColorIntent or ... 3-MaximizeQuality or MinimizeSize 4-wiaFormatBMP 5-true =AlwaysSelectDevice 6-false = use user interface 7- true = cancel error – Ahmad May 07 '12 at 14:21
  • in [Shared Samples](http://msdn.microsoft.com/en-us/library/ms630826%28v=vs.85%29.aspx#SharedSample003) of msdn just add CommonDialog and DeviceManager from toolbox but in delphi it is not existing so i create it by ** ::: CommonDlg := createOleObject('WIA.CommonDialog') as ICommonDialog;::: ** ** :::DeviceManager1 := createOleObject('WIA.DeviceManager') as iDeviceManager;:::** then i try this **:::CommonDlg.ShowSelectDevice(UnspecifiedDeviceType,true,true);::::** but it is dont work – Ahmad May 07 '12 at 16:53
  • You can consider this [answer](http://stackoverflow.com/a/2015497/744588) posted on SO, still related to [tag:delphi] and [tag:wia]. – menjaraz May 08 '12 at 10:09
  • **tank you menjaraz - but i don't find anything helpful about wia2 - delphi - i see the [question here](http://stackoverflow.com/questions/2012630/how-to-control-a-camera-with-delphi/10519442#10519442) abouot wia1 with win xp and delphi *and i ansuar that question - please if anybody know about wia2 with delphi please answer me** – Ahmad May 10 '12 at 00:10
  • Sorry, I didn't pay much attention to that relevant detail. – menjaraz May 10 '12 at 05:02

1 Answers1

-1

I recently had a similar experience with WIA and Win7.

What I eventually ended up using was a DirectX solution.

Delphi Basics - DirectX webcam capture

I don't remember how I originally found this project, but under Win7 it just works even with older webcams that I found lying around the office.

I recommend you look at Demo3 in the download file as that had the best, simple, example of what I needed. YMMV.

(Edit) My WIA problem extended from the fact that the webcam maker did not support WIA or Twain under Win7.

Vivian Mills
  • 2,552
  • 14
  • 19
  • 1
    This doesn't answer the question asked, which was why WIA 2 on Win 7 didn't work while the same code with WIA 1 on XP did. "Why did my Ford car stop?" "I bought a Chevy" isn't really an answer. – Ken White Jun 14 '12 at 18:27
  • @ken white I understand that. thus the edit stating that i believe the problem to be the driver from the manufacturer and the suggestion for workaround. is this not a good use of the site? – Vivian Mills Jun 15 '12 at 05:22