Capturing a Webcam Image using VB.Net

I have VB.Net application that captures an image from a webcam. I have used the following code for a number years without an issue:

       hWnd = capCreateCaptureWindowA("USB Camera",  WS_VISIBLE Or WS_CHILD, 0, 0, 0, _
            0, pbCtrl.Handle.ToInt32, 0)
       If SendMessage(hWnd, WM_CAP_DRIVER_CONNECT, CamSource, 0) Then
           SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
            Blar Blar Blar................
            '--error connecting to video source---
       End If

However moving to Windows 7 .Net 3.5 when 'SendMessage' is issued to open the 'CamSource' the dialogue 'Capture Source' -  'Select a Video Device' - 'USB Camera' appears. What I ever do in response to this dialogue the webcam doesn't open.

I have resolved this issue in the past by upgrading the Bison drivers to the latest version (from the version that came with Win 7 32 bit). I installed Win 7 32 bit on the PC and the Bison drivers where installed by default.

The problem I now have is on a tablet - running Win 7 32 bit. The built in webcam uses the 'USBVideo.sys' driver.

I have tried to use the Bison drivers - but can't change the driver from 'USBVideo.sys' (I am not too sure that would solve the problem - I just know the Bison drivers work fine) i.e. I uninstall, disable, kill the webcam - but as soon as it is available to Win 7 - then USBVideo.sys drivers are installed.

I think the problem is that another process (I can't see what the process this could be) already has the webcam 'locked' i.e. it can't be shared.

So at this point in time I am stuffed! Thoughts and solutions much appreciated.


Who is Participating?
BeagleDogConnect With a Mentor Author Commented:
I raised this issue the Microsoft - and got an excellent response. I have posted it here.............

Microsoft replied:

I’d like to inform you that, I’ve written a small C++ sample and used ‘capCreateCaptureWindow’ and ‘capDriverConnect’ APIs to access WebCamera on my Windows 7 system. I found both of these APIs are working fine on my Windows 7 System.

I’ve used ‘Microsoft LifeCam VX-6000. The issue could be with the Bison driver compatibility. I think it’s worth to give a try to re-install the driver in “Windows XP or Vista Compatible” mode on your Windows 7 system and then try with your existing code.

Please follow the steps as mentioned below:
1.      Uninstall the bison web cam driver from your system.
2.      Download the driver from the official website.
3.      Right click on the driver executable / installer file. A context menu will appear.
4.      Select ‘Properties’ menu item
5.      Click on the Compatibility tab.
6.      Check the option “Run this program in Compatibility mode for” and Select Windows XP (Service Pack 3).
7.      Then click on Apply and OK.
8.      Please right click again on the driver executable / installer file and Select the option “Run as Administrator”.
9.      Then follow instructions to install the driver on the system.
10.      Once installation is done, please restart the system and use your program to check if it’s working or not.
11.      Please ensure that you’re running the program in “Elevated mode”.

You can also test with Windows Vista compatibility mode using same steps.

Since, VFW is a very old technology, it’s good to consider moving to DirectShow. I’ll provide a separate email about DirectShow related stuff on 28th Feb 2011.

Please let me know how the thing goes after installing the driver in Compatibility mode.

I tried this. The following is my response:

Thanks for all this :

Tried the following but I didn’t succeed because:

1.      I hadn’t managed to install the Bison drive on this Table. The Webcam was using USBVideo.sys.
2.      I followed your instructions, but the drivers I had couldn’t install because the USBVideo.sys as already installed.
3.      The install for the Bison didn’t seem to have .inf file (I may have been doing something wrong also)

The other things I have tried.

1.      I found a C# DirectShow sample that did exactly what I wanted to do – show the video in preview, then snap the image into a second picture box window. Great!
2.      But I am an old VB programmer and our application is VB. I don’t seem to be able to get my head around C#. First attempted to convert the C# to VB but soon became lost.
3.      Decided to create a user control using the C# code – then include the control in the VB app. Good thinking! The only problem was returning the captured image from the control back to the VB app. However I decided to make sure the control could access the webcam correctly.
4.      When I tried this – yes it worked – I didn’t get the ‘Select A Video’ source message – but the video was very distorted. I suspect that this was a setting on the camera – a refresh rate or something……….
5.      Had a cup of coffee.

Rather than keep pursuing down this path (as I suspected it was going to take me nowhere – if I couldn’t retrieve the snap imaged). I decided to try a new video driver. Went to ‘DriversForFree’ and found a Bison driver for a generic USB webcam. This driver came with an .inf file. Was able to kick USBVideo.sys in the guts and install the Bison USB Webcam drivers.

Fired up my app – and it worked perfectly!!!!

It may not be the best solution – but at least gets me back up and running.

Comments – while DirectShow maybe the best solution – hell it complicated! Even with all this complication it still couldn’t deliver a picture from the WebCam (I accept it could be the driver or a setting).

If I go down the DirectShow path again – I will look for an OCX that saves me from the complications. I would look for an OCX that would do face recognition – software that would enhance the face – differentiate the face from the background (not to be able to recognise the face from a library of faces). If anyone knows of such an animal you like to know.

Again thanks for your support and interest in this problem – I really appreciate it.

If you want to feed me any more info re DirectShow – please do – otherwise please feel free to close this issue.

If there is anything else I can do to provide information on this problem please let me know.

Have you tried a safe or selective boot to eliminate the USBVideo.sys driver from the equation?
BeagleDogAuthor Commented:
I re-booted in safe mode. Under device manager and looked at the properties of the webcam 'Status is not available for this devicewhen Windows is running in Safe Mode'

Ran the application - and while I didn't get the 'Select Video Source' dialog - neither did I get a preview from the webcam.

Was that what you where thinking in 'try a safe or selective boot'?

Thanks for your response.

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Yeah I just wondered if you could selectively load drivers for boot time. Safe boot doesn't work, but you could also try typing msconfig in the Start | Search box and see if the driver for the webcam is listed there under services or startup. You would then be doing a selective startup to see if you can access the webcam with your code in the absence of the driver. msconfig will ask you to resart when you make your changes and close it down (sorry if I'm assuming you haven't done this before)

It may well be the case that you cannot access the camera with out the 'middleware' driver being in place, but it would be nice to know one way or the other. At least then you could possibly add some code to end the drivers process allowing you the access you need - but that is more your area of skill than mine!
BeagleDogAuthor Commented:
OK did this:
Only 8 services running:

DCOM Server.....
Group Policy Client
Plug and Play
Remote Proc Call
RPC EndPoint
Task Sched
User Profile
Software Protection

The application starts - but exactly the same symptoms
The PC comes with Camera software:

Video View - DirectShow Video Capture Sample Version 1.00
And this fires up and works perfectly...........

Yes - it feels like I need to have a another service running (as you say 'middleware') - it doesn't feel that it is a sharing conflict.

Again thanks for your help and your response.



Okay I'm not a programmer but I managed to apply myself and do the following using this script downloadable from a smarter guy named Ken Tucker from here:
I then realised I'd need to install some tools so I used express edition 2008 (the free one),
and somehow (trial & error) I managed to get it working.

Ken's script does what it says it does - lists the existing camera feed /driver sources on the machine you are using it on, shows you the feed in a window (the aspect ratio was off a bit) and allows for taking a picture.

Maybe examining Ken's code will point you towards a solution that works, if it tuns out that on that specific tablet your code requires more specific tailoring, that is also likely the case on other devices too.

It seems to be of limited value to bother with a selective startup proces if the above idea works on that tablet! Good luck, keep me posted.
BeagleDogAuthor Commented:
Resolved the issue through Microsoft and posted here for completeness. i.e. when you have a problem its great to pickup threads of like problems so that you can find and implement the best solution.
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.