This thread is a little old, but I came across it trying to solve a problem using a built-in webcam (as opposed to external usb-connected), and now that my code finally works I thought I'd share it in case anyone out there is still looking....
[Originally posted to the thread "Re: WM_CAP_DRIVER_CONNECT connects but black window?", but added here by request from pete]
The problem I had was with code almost identical to that listed here, which worked fine with a USB-attached webcam, but not with a built-in device. I noticed that the SendMessage was always failing, but could find no versions of this code which actually investigate WHY it fails; all they ever do is just give up and destroy the capture window.
After many attempts to find the actual error, I noticed that *occasionally*, maybe 1 time in 10, the code did actually work, for no good reason.
I had to give up on finding the error, as the code got less and less stable the more error-handling code I put in. BUT, I finally put some retry code in, and the whole application burst into life and now works 100% reliably!
What fixed it for me was to replace the single IF SendMessage line with the following:
Hope this helps someone, as it cost me a couple of frustrating days getting this to work!
Dim connectAttempts As Integer = 0
While Not CBool(SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, 0, Nothing))
connectAttempts += 1
If connectAttempts > 10 Then
Me.Cursor = Cursors.Default