|
-
Dec 7th, 2011, 04:07 AM
#10
New Member
Re: Snapshot from webcam
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:
Code:
Dim connectAttempts As Integer = 0
While Not CBool(SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, 0, Nothing))
connectAttempts += 1
If connectAttempts > 10 Then
DestroyWindow(hHwnd)
Me.Cursor = Cursors.Default
Return False
End If
Threading.Thread.Sleep(1000)
End While
Hope this helps someone, as it cost me a couple of frustrating days getting this to work!
Ade
Last edited by lewisar; Dec 7th, 2011 at 09:31 AM.
Reason: Missing code tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|