Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. selecting a device without UI

selecting a device without UI

Scheduled Pinned Locked Moved C / C++ / MFC
designhelpquestion
29 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Cedric Moonen

    These webcams are USB devices ? Do you have drivers provided with them ? Or what driver are you using. What do you need to do to communicate with your webcam when only one is installed (using CreateFile to open the driver for example) ? I will try to help you but I'm not sure at all I can provide you a solution.

    V Offline
    V Offline
    V_shr
    wrote on last edited by
    #5

    the webcams connect with USB port , and their drivers are installed , I looked msdn an I found this :

    Call "CoCreateInstance" to retrieve a pointer to the "IWiaDevMgr" interface.
    Use the "IWiaDevMgr::EnumDeviceInfo" method of the "IWiaDevMgr" interface to obtain a pointer to the "IEnumWIA_DEV_INFO" interface.
    Use "IEnumWIA_DEV_INFO" interface to obtain "IWiaPropertyStorage" interface pointers for each WIA device enumerated.
    Use "IWiaPropertyStorage" interface to inspect the device information properties of each device and save the "WIA_DIP_DEV_ID" property from the desired device.
    Use the "DeviceID" property with the "IWiaDevMgr::CreateDevice" method in the "IWiaDevMgr" interface to create a WIA device object. The "IWiaDevMgr::CreateDevice method" provides the application with the pointer to the IWiaItem interface of the root item of the specified device.

    example for create a device :

    HRESULT CreateWiaDevice( IWiaDevMgr *pWiaDevMgr, BSTR bstrDeviceID, IWiaItem **ppWiaDevice )
    {
    //
    // Validate arguments
    //
    if (NULL == pWiaDevMgr || NULL == bstrDeviceID || NULL == ppWiaDevice)
    {
    return E_INVALIDARG;
    }

        //
        // Initialize out variables
        //
        \*ppWiaDevice = NULL;
    
        //
        // Create the WIA Device
        //
        HRESULT hr = pWiaDevMgr->CreateDevice( bstrDeviceID, ppWiaDevice );
    
        //
        // Return the result of creating the device
        //
        return hr;
    }
    

    I know that this is what I need , but I cant understand it . plz help me

    1 Reply Last reply
    0
    • V V_shr

      I need to choose 1 webcam from webcames connected to computer without UI.

      J Offline
      J Offline
      Justin Tay
      wrote on last edited by
      #6

      What are you doing exactly? Choose it to do what? Are you using DirectShow? If so just get the System Device Enumerator and use the ICreateDevEnum interface to enumerate the CLSID_VideoInputDeviceCategory. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directshow/htm/usingthesystemdeviceenumerator.asp[^]

      V 1 Reply Last reply
      0
      • J Justin Tay

        What are you doing exactly? Choose it to do what? Are you using DirectShow? If so just get the System Device Enumerator and use the ICreateDevEnum interface to enumerate the CLSID_VideoInputDeviceCategory. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directshow/htm/usingthesystemdeviceenumerator.asp[^]

        V Offline
        V Offline
        V_shr
        wrote on last edited by
        #7

        // Activate (with the Default/first device) SelCapDrvProc(hwndMain,WM_COMMAND,SELCAPDRVDLG_BUTTON,0); and this actives the default (first) camera and I want to change the default .

        J 1 Reply Last reply
        0
        • V V_shr

          // Activate (with the Default/first device) SelCapDrvProc(hwndMain,WM_COMMAND,SELCAPDRVDLG_BUTTON,0); and this actives the default (first) camera and I want to change the default .

          J Offline
          J Offline
          Justin Tay
          wrote on last edited by
          #8

          From google it looks like you are making reference to some code in some project available on Planet Source Code? Edit: I've found the source from Planet Source Code. It uses Video For Windows, so I'm not sure what your previous post was about. For reference the source is located at http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2679&lngWId=3[^] You would like to use this and just change it to use a particular webcam? You could just modify EnumCapDrv and only add that particular webcam to the listbox. The code for the project in general looks like it could be a little buggy, but I think it already demonstrates everything you want to know? Like getting devices using capGetDriverDescription()? -- modified at 5:34 Thursday 4th May, 2006

          V 1 Reply Last reply
          0
          • J Justin Tay

            From google it looks like you are making reference to some code in some project available on Planet Source Code? Edit: I've found the source from Planet Source Code. It uses Video For Windows, so I'm not sure what your previous post was about. For reference the source is located at http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2679&lngWId=3[^] You would like to use this and just change it to use a particular webcam? You could just modify EnumCapDrv and only add that particular webcam to the listbox. The code for the project in general looks like it could be a little buggy, but I think it already demonstrates everything you want to know? Like getting devices using capGetDriverDescription()? -- modified at 5:34 Thursday 4th May, 2006

            V Offline
            V Offline
            V_shr
            wrote on last edited by
            #9

            this is the link to download code: http://www.planet-source-code.com/upload_PSC/ftp/My_Webcam853695202002.zip[^] note : if you haven't CBuilder you can open main.cpp and main.h with notepad .

            J 1 Reply Last reply
            0
            • V V_shr

              this is the link to download code: http://www.planet-source-code.com/upload_PSC/ftp/My_Webcam853695202002.zip[^] note : if you haven't CBuilder you can open main.cpp and main.h with notepad .

              J Offline
              J Offline
              Justin Tay
              wrote on last edited by
              #10

              Looks like it's based on the project that I found. Look at the edited post above this one for comments. As I mentioned earlier look at EnumCapDrv, it calls capGetDriverDescription() to get devices. From looking at the API again though, my initial idea is wrong. Looks like you specify the device from the index.

              for (i=0; i<10; i++)
              {
              if(capGetDriverDescription(i, szDeviceName, sizeof(szDeviceName),
              szDeviceVersion, sizeof(szDeviceVersion)) )
              {
              if(strcmp(szDeviceName, "MyDeviceName") == 0)
              {
              SendMessage( hwndVideo, WM_CAP_DRIVER_CONNECT, i, 0L);
              }
              }
              }

              Anyway i think the code is a bit buggy.

              // get the selected driver
              SendMessage( hwndSelCapDrvDlg_LBox, LB_GETSELITEMS, 1, sel);

              Shouldn't it be

              // get the selected driver
              SendMessage( hwndSelCapDrvDlg_LBox, LB_GETSELITEMS, 1, &sel);

              Actually I think he should have just used a single selection listbox and use the LB_GETCURSEL message to get the current selection. Anyway, if it happens that your problem was that you couldn't select anything other than the first device, then this might be the reason. -- modified at 5:26 Thursday 4th May, 2006

              V 1 Reply Last reply
              0
              • J Justin Tay

                Looks like it's based on the project that I found. Look at the edited post above this one for comments. As I mentioned earlier look at EnumCapDrv, it calls capGetDriverDescription() to get devices. From looking at the API again though, my initial idea is wrong. Looks like you specify the device from the index.

                for (i=0; i<10; i++)
                {
                if(capGetDriverDescription(i, szDeviceName, sizeof(szDeviceName),
                szDeviceVersion, sizeof(szDeviceVersion)) )
                {
                if(strcmp(szDeviceName, "MyDeviceName") == 0)
                {
                SendMessage( hwndVideo, WM_CAP_DRIVER_CONNECT, i, 0L);
                }
                }
                }

                Anyway i think the code is a bit buggy.

                // get the selected driver
                SendMessage( hwndSelCapDrvDlg_LBox, LB_GETSELITEMS, 1, sel);

                Shouldn't it be

                // get the selected driver
                SendMessage( hwndSelCapDrvDlg_LBox, LB_GETSELITEMS, 1, &sel);

                Actually I think he should have just used a single selection listbox and use the LB_GETCURSEL message to get the current selection. Anyway, if it happens that your problem was that you couldn't select anything other than the first device, then this might be the reason. -- modified at 5:26 Thursday 4th May, 2006

                V Offline
                V Offline
                V_shr
                wrote on last edited by
                #11

                I looked my code , it was the correct one . and my problem isn't that I change the default device but it doesn't change , my problem is that I dont know how to change that .

                J 1 Reply Last reply
                0
                • V V_shr

                  I looked my code , it was the correct one . and my problem isn't that I change the default device but it doesn't change , my problem is that I dont know how to change that .

                  J Offline
                  J Offline
                  Justin Tay
                  wrote on last edited by
                  #12

                  Reread my previous posts (I might have modified them after you read them) and tell me which part you don't understand. What do you mean by "your code was the correct one"? Setting the device just involves setting the index 'i' in the WM_CAP_DRIVE_CONNECT message.

                  SendMessage( hwndVideo, WM_CAP_DRIVER_CONNECT, i, 0L);

                  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_wm_cap_driver_connect.asp[^] As I said before use capGetDriverDescription() to figure out which index your device corresponds to. -- modified at 6:21 Thursday 4th May, 2006

                  V 1 Reply Last reply
                  0
                  • J Justin Tay

                    Reread my previous posts (I might have modified them after you read them) and tell me which part you don't understand. What do you mean by "your code was the correct one"? Setting the device just involves setting the index 'i' in the WM_CAP_DRIVE_CONNECT message.

                    SendMessage( hwndVideo, WM_CAP_DRIVER_CONNECT, i, 0L);

                    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_wm_cap_driver_connect.asp[^] As I said before use capGetDriverDescription() to figure out which index your device corresponds to. -- modified at 6:21 Thursday 4th May, 2006

                    V Offline
                    V Offline
                    V_shr
                    wrote on last edited by
                    #13

                    I cant find similarity of our sources , and when you refer to somthing in code I cant find where you are saying . and because I didn't work on devices befor this I cant guess what are you saying. can you say it simpler ? thank you

                    J 1 Reply Last reply
                    0
                    • V V_shr

                      I cant find similarity of our sources , and when you refer to somthing in code I cant find where you are saying . and because I didn't work on devices befor this I cant guess what are you saying. can you say it simpler ? thank you

                      J Offline
                      J Offline
                      Justin Tay
                      wrote on last edited by
                      #14

                      More like working with Video For Windows API in this case. Devices is too generic a term. In fact most people do this using DirectShow instead of VFW these days. My suggestion to how to get the device index that you want.

                      for (i=0; i<10; i++)
                      {
                      if(capGetDriverDescription(i, szDeviceName, sizeof(szDeviceName), szDeviceVersion, sizeof(szDeviceVersion)) )
                      {
                      if(strcmp(szDeviceName, "MyDeviceName") == 0)
                      {
                      SendMessage( hwndVideo, WM_CAP_DRIVER_CONNECT, i, 0L);
                      break;
                      }
                      }
                      }

                      Look at this to see how he enumerates the Video For Windows devices main.cpp: Line 185

                      int TForm1::EnumCapDrv() // enumerate the installed capture drivers

                      main.cpp: Line 118

                      SendMessage( hwndVideo, WM_CAP_DRIVER_CONNECT, sel, 0L);

                      main.cpp: Line 115

                      SendMessage( hwndSelCapDrvDlg_LBox, LB_GETSELITEMS, 1, sel);

                      Should be

                      SendMessage( hwndSelCapDrvDlg_LBox, LB_GETSELITEMS, 1, &sel);

                      Or it will only set the device to index 0, as sel was initialised to 0.

                      V 1 Reply Last reply
                      0
                      • J Justin Tay

                        More like working with Video For Windows API in this case. Devices is too generic a term. In fact most people do this using DirectShow instead of VFW these days. My suggestion to how to get the device index that you want.

                        for (i=0; i<10; i++)
                        {
                        if(capGetDriverDescription(i, szDeviceName, sizeof(szDeviceName), szDeviceVersion, sizeof(szDeviceVersion)) )
                        {
                        if(strcmp(szDeviceName, "MyDeviceName") == 0)
                        {
                        SendMessage( hwndVideo, WM_CAP_DRIVER_CONNECT, i, 0L);
                        break;
                        }
                        }
                        }

                        Look at this to see how he enumerates the Video For Windows devices main.cpp: Line 185

                        int TForm1::EnumCapDrv() // enumerate the installed capture drivers

                        main.cpp: Line 118

                        SendMessage( hwndVideo, WM_CAP_DRIVER_CONNECT, sel, 0L);

                        main.cpp: Line 115

                        SendMessage( hwndSelCapDrvDlg_LBox, LB_GETSELITEMS, 1, sel);

                        Should be

                        SendMessage( hwndSelCapDrvDlg_LBox, LB_GETSELITEMS, 1, &sel);

                        Or it will only set the device to index 0, as sel was initialised to 0.

                        V Offline
                        V Offline
                        V_shr
                        wrote on last edited by
                        #15

                        I use two webcams in my project and want to switch between them without oppenning UI window . kindly ask to send the code for switching between two cameras .

                        J 1 Reply Last reply
                        0
                        • V V_shr

                          I use two webcams in my project and want to switch between them without oppenning UI window . kindly ask to send the code for switching between two cameras .

                          J Offline
                          J Offline
                          Justin Tay
                          wrote on last edited by
                          #16

                          Does sending the WM_CAP_DRIVER_CONNECT message not work?

                          SendMessage(hwndVideo, WM_CAP_DRIVER_CONNECT, camIndex, 0L);

                          or the macro

                          capDriverConnect(hwndVideo, camIndex);

                          What problems are you facing?

                          V 1 Reply Last reply
                          0
                          • J Justin Tay

                            Does sending the WM_CAP_DRIVER_CONNECT message not work?

                            SendMessage(hwndVideo, WM_CAP_DRIVER_CONNECT, camIndex, 0L);

                            or the macro

                            capDriverConnect(hwndVideo, camIndex);

                            What problems are you facing?

                            V Offline
                            V Offline
                            V_shr
                            wrote on last edited by
                            #17

                            when I put camIndex , nonzero , it doesn't work , but windows recognizes both of webcams .

                            J 1 Reply Last reply
                            0
                            • V V_shr

                              when I put camIndex , nonzero , it doesn't work , but windows recognizes both of webcams .

                              J Offline
                              J Offline
                              Justin Tay
                              wrote on last edited by
                              #18

                              Um. Windows recognizes both webcams as in... they both have VFW drivers? Did you see the webcams listed in the listbox of this application?

                              V 1 Reply Last reply
                              0
                              • J Justin Tay

                                Um. Windows recognizes both webcams as in... they both have VFW drivers? Did you see the webcams listed in the listbox of this application?

                                V Offline
                                V Offline
                                V_shr
                                wrote on last edited by
                                #19

                                Yes I can choose between two webcams in windows UI dialog . but as mentioned above when I put the camIndex=1 it doesn't recognize it.

                                J 1 Reply Last reply
                                0
                                • V V_shr

                                  Yes I can choose between two webcams in windows UI dialog . but as mentioned above when I put the camIndex=1 it doesn't recognize it.

                                  J Offline
                                  J Offline
                                  Justin Tay
                                  wrote on last edited by
                                  #20

                                  What windows UI dialog? Is it present in the SelCapDrvDlg in this application? Set a breakpoint in main.cpp line 199. What are the indexes of the 2 webcams you are interested in?

                                  V 1 Reply Last reply
                                  0
                                  • J Justin Tay

                                    What windows UI dialog? Is it present in the SelCapDrvDlg in this application? Set a breakpoint in main.cpp line 199. What are the indexes of the 2 webcams you are interested in?

                                    V Offline
                                    V Offline
                                    V_shr
                                    wrote on last edited by
                                    #21

                                    it reaches the breakpoint when i=0 and it doesn't reach in i=1

                                    J 1 Reply Last reply
                                    0
                                    • V V_shr

                                      it reaches the breakpoint when i=0 and it doesn't reach in i=1

                                      J Offline
                                      J Offline
                                      Justin Tay
                                      wrote on last edited by
                                      #22

                                      And there we have it. One of your webcams only has a WDM driver. You would have to write a DirectShow application.

                                      V 1 Reply Last reply
                                      0
                                      • J Justin Tay

                                        And there we have it. One of your webcams only has a WDM driver. You would have to write a DirectShow application.

                                        V Offline
                                        V Offline
                                        V_shr
                                        wrote on last edited by
                                        #23

                                        how can I write a DirectShow program , If you have time , please tell me . thank you

                                        J 3 Replies Last reply
                                        0
                                        • V V_shr

                                          how can I write a DirectShow program , If you have time , please tell me . thank you

                                          J Offline
                                          J Offline
                                          Justin Tay
                                          wrote on last edited by
                                          #24

                                          If you have VC7+, download and install the latest Platform SDK. Go to http://tmhare.mvps.org/downloads.htm[^] to get the project files for the samples since Microsoft has for some reason stripped it out. Then go have a look at the PlayCap sample application in "..\Program Files\Microsoft Platform SDK\Samples\Multimedia\DirectShow\Capture\PlayCap" If you have VC6 though, you would have to grab an old DirectX SDK, maybe 2003 or 2004.

                                          V 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups