Page 2 of 2
Re: Web Camera in Windows 8.1
Posted: Mon Dec 15, 2014 8:25 am
by JHPJHP
Hi akee,
I wrote an example using the Microsoft documentation including Structures and Functions, but it resulted in the same black window.
http://msdn.microsoft.com/en-us/library ... s.85).aspx
As others have experienced, the camera connected the first time the example ran, but for subsequent connections a reboot was required.
-
http://www.vbforums.com/showthread.php? ... indows-8-1
I did have marginal success, but only when the camera was continuously initialized using a third party tool

- using OpenCV to initialize the camera:
VfW (Video for Windows)
-----------------------------------------------------------------------------------------------
On another note:
PureBasic Interface to OpenCV can be stripped down to only the essential parts required by your project.
- OpenCV does not include audio
OpenCV is a bit of an overkill for my project.
Re: Web Camera in Windows 8.1
Posted: Mon Dec 29, 2014 10:53 pm
by akee
Just wondering if the problem could be because of Windows blocking the driver or maybe because of Unicode? I tried both the functions "capCreateCaptureWindowW" and "capCreateCaptureWindowA". Same result.
Re: Web Camera in Windows 8.1
Posted: Tue Dec 30, 2014 1:29 am
by JHPJHP
Hi akee,
Did you try this:
VfW (Video for Windows)?
- context menu available for additional options
akee wrote:Just wondering if the problem could be because of Windows blocking the driver or maybe because of Unicode? I tried both the functions "capCreateCaptureWindowW" and "capCreateCaptureWindowA". Same result.
http://www.vbforums.com/showthread.php? ... indows-8-1
I'm sure that it stems from the fact that "Video for Windows" support on modern versions of Windows is emulated through shim libraries that match the old APIs to the newer WDM capture drivers. The idea was that VfW and AviCap were only left in there for backward compatibility.
Re: Web Camera in Windows 8.1
Posted: Thu Jan 01, 2015 9:27 pm
by akee
Hi JHPJHP,
As my program works if I initiate another program like MS-Camera to get the driver working first, I get 100% success so I did not use the VfW libs. I'm concerned using compiled codes for future development. Thanks for your replies.
Anyway, let's throw the code in for discussion. For the program to work, run MS-Camera first, then tun this. The screen turns green on my PC. After that close MS-Camera and control will then be passed to the program.
Code: Select all
Prototype.i PxCapCreateCaptureWindow(lpszWindowName.s, dwStyle.l, x.l, y.l, nWidth.l, nHeight.l, hWndParent.l, nId.l)
Prototype.b PxCapGetDriverDescription(wIndex.w, *lpszName, cbName.l, *lpszVer, cbVer.l)
Global var_avicap32_lib
var_avicap32_lib = OpenLibrary(#PB_Any, "avicap32.dll")
If var_avicap32_lib
CompilerIf #PB_Compiler_Unicode
Global capCreateCaptureWindow.PxCapCreateCaptureWindow = GetFunction(var_avicap32_lib, "capCreateCaptureWindowW")
Global capGetDriverDescription.PxCapGetDriverDescription = GetFunction(var_avicap32_lib, "capGetDriverDescriptionW")
CompilerElse
Global capCreateCaptureWindow.PxCapCreateCaptureWindow = GetFunction(var_avicap32_lib, "capCreateCaptureWindowA")
Global capGetDriverDescription.PxCapGetDriverDescription = GetFunction(var_avicap32_lib, "capGetDriverDescriptionA")
CompilerEndIf
EndIf
Procedure capDriverConnect(lwnd.l, nDevice.l = 0)
ProcedureReturn SendMessage_(lwnd, #WM_CAP_DRIVER_CONNECT, nDevice, 0)
EndProcedure
Procedure capSetPreview(lwnd.l, lTrue.l = #True)
ProcedureReturn SendMessage_(lwnd, #WM_CAP_SET_PREVIEW, lTrue, 0)
EndProcedure
Procedure capSetPreviewRate(lwnd.l, wMS.l)
ProcedureReturn SendMessage_(lwnd, #WM_CAP_SET_PREVIEWRATE, wMS, 0)
EndProcedure
#CAM_W = 640
#CAM_H = 480
OpenWindow(0, 0, 0, #CAM_W, #CAM_H, "Camera")
cam_handle = capCreateCaptureWindow("Camera", #WS_CHILD | #WS_VISIBLE, 0, 0, #CAM_W, #CAM_H, WindowID(0), 0)
Debug cam_handle
Debug capDriverConnect(cam_handle, 0)
Debug capSetPreview(cam_handle, #True)
Debug capSetPreviewRate(cam_handle, 30)
Repeat: Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Web Camera in Windows 8.1
Posted: Thu Jan 01, 2015 9:55 pm
by JHPJHP
Hi akee,
There are no VFW libs, the OpenCV libs are only to initiate the webcam; automating the process and making it unnecessary for a user to "run the MS-Camera first".
akee wrote:As my program works if I initiate another program like MS-Camera to get the driver working first, I get 100% success so I did not use the VfW libs.
Sorry for repeating myself, but did you try this:
VfW (Video for Windows)? The example you provided is nearly identical to the one in the link just less comprehensive.
Your concern for future development is warranted, and it may be time to consider moving to the new WDM capture drivers.
akee wrote:I'm concerned using compiled codes for future development.
Happy New Year!
Re: Web Camera in Windows 8.1
Posted: Sat Jan 03, 2015 10:29 pm
by akee
Thanks JHPJHP,
I have decided to drop PureBasic as my project's development platform.
Re: Web Camera in Windows 8.1
Posted: Mon Jun 13, 2016 8:29 pm
by xxfreshman
I know he is already gone, but i must say i found a good working solution.
DO the initialisation 2 times, and it works.
SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEW, #True, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEWRATE, 1, 0)
SendMessage_(hWndC, #WM_CAP_SET_SCALE, #True, 0)
SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEW, #True, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEWRATE, 10, 0)
SendMessage_(hWndC, #WM_CAP_SET_SCALE, #False, 0)