Camera Capture with WIA, C# and Win 7 -


i try take picture webcam wia 2.0, c#, .net 4.0 on windows 7. tried many different samples, nothing works. exception: "comexception unhandled" exception hresult: 0x80210015". code wia_s_no_device_available. checked, if wia-service running , if cam shows in scanners , camera. have no idea whats wrong here! can help?

exception thrown on line:

device d = class1.showselectdevice(wiadevicetype.cameradevicetype, true, false);:

here code

string deviceid;      const string wiaformatbmp = "{b96b3cab-0728-11d3-9d7b-0000f81ef32e}";     const string wiaformatpng = "{b96b3caf-0728-11d3-9d7b-0000f81ef32e}";     const string wiaformatgif = "{b96b3cb0-0728-11d3-9d7b-0000f81ef32e}";     const string wiaformatjpeg = "{b96b3cae-0728-11d3-9d7b-0000f81ef32e}";     const string wiaformattiff = "{b96b3cb1-0728-11d3-9d7b-0000f81ef32e}";       class wia_dps_document_handling_select     {         public const uint feeder = 0x00000001;         public const uint flatbed = 0x00000002;     }      class wia_dps_document_handling_status     {         public const uint feed_ready = 0x00000001;     }      class wia_properties     {         public const uint wia_reserved_for_new_props = 1024;         public const uint wia_dip_first = 2;         public const uint wia_dpa_first = wia_dip_first + wia_reserved_for_new_props;         public const uint wia_dpc_first = wia_dpa_first + wia_reserved_for_new_props;         //         // scanner device properties (dps)         //         public const uint wia_dps_first = wia_dpc_first + wia_reserved_for_new_props;         public const uint wia_dps_document_handling_status = wia_dps_first + 13;         public const uint wia_dps_document_handling_select = wia_dps_first + 14;     }      class wia_errors     {         public const uint base_val_wia_error = 0x80210000;         public const uint wia_error_paper_empty = base_val_wia_error + 3;     }       public void adfscan()     {          //choose scanner         commondialogclass class1 = new commondialogclass();         device d = class1.showselectdevice(wiadevicetype.cameradevicetype, true, false);         if (d != null)         {             this.deviceid = d.deviceid;         }         else         {             //no scanner chosen             return;         }            wia.commondialog wiacommondialog = new commondialogclass();          bool hasmorepages = true;         int x = 0;         int numpages = 0;         while (hasmorepages)         {             //create devicemanager             devicemanager manager = new devicemanagerclass();             device wiadev = null;             foreach (deviceinfo info in manager.deviceinfos)             {                 if (info.deviceid == this.deviceid)                 {                     wia.properties infoprop = null;                     infoprop = info.properties;                      //connect scanner                     wiadev = info.connect();                       break;                 }             }                //start scan              wia.imagefile img = null;             wia.item item = wiadev.items[1] wia.item;              try             {                  img = (imagefile)wiacommondialog.showtransfer(item, wiaformatjpeg, false);                   //process image:                 //one image processing here                 //                  //save file                 string varimagefilename = "c:\\test" + x.tostring() + ".jpg";                 if (file.exists(varimagefilename))                 {                     //file exists, delete                     file.delete(varimagefilename);                 }                 img.savefile(varimagefilename);                 numpages++;                 img = null;              }             catch (exception ex)             {                 messagebox.show("error: " + ex.message);             }                         {                 item = null;                 //determine if there more pages waiting                 property documenthandlingselect = null;                 property documenthandlingstatus = null;                 foreach (property prop in wiadev.properties)                 {                     if (prop.propertyid == wia_properties.wia_dps_document_handling_select)                         documenthandlingselect = prop;                     if (prop.propertyid == wia_properties.wia_dps_document_handling_status)                         documenthandlingstatus = prop;                   }                  hasmorepages = false; //assume there no more pages                 if (documenthandlingselect != null)                 //may not exist on flatbed scanner required feeder                 {                     //check document feeder                     if ((convert.touint32(documenthandlingselect.get_value()) & wia_dps_document_handling_select.feeder) != 0)                     {                         hasmorepages = ((convert.touint32(documenthandlingstatus.get_value()) & wia_dps_document_handling_status.feed_ready) != 0);                     }                 }                 x++;             }         }      } 

thanks help!

this typical example of non-documented error microsoft... error code means no device has been found, either not connected or not-wia recognized.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -