Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
Available now!
Buy at Amazon US or
Buy at Amazon UK


» Windows API reference
» Webcam streaming in VB.NET
» Remoting with firewalls
» RSA from first principles
» Key & MouseLogger in .NET
» Networking Resource Kit for .NET
» Migrating VB6 Winsock to VB.NET
» Migrating C++ sockets to C#
» RFC Reference guide
» COM Reference guide
» WMI Reference guide
» SQL stored procedures
» TCP & UDP port reference
» NET Framework reference
» Ethernet Type codes
» MAC address assignments
» DLL entry point reference
» Boost SQL performance
» Free SMS UK
» Free SMS Ireland
» Free SMS South Africa
» Internet Explorer

Contact us

Streaming WebCam video with VB.NET

No DirectX, No ActiveX/COM, No Intermediary file, just live video stream at speeds up to 30 FPS.

This project is a bare-bones implementation of a webcam (web camera) viewer using VB.NET code. It uses the VFW (Video for windows) API, which is built into all versions of windows (95 and up). It is used to map the output of any VFW compliant Webcam to a window handle, such as that of a VB.NET picture box.

Most Webcams are VFW compliant, this does exclude some Intel models that are incompatible with this demonstration. As most web cam users are aware, this application cannot run in tandem with another application that is accessing the same camera driver. Unfortunately, most Webcams developed Post-Windows-XP, all use the same WDM (Windows Driver Model) driver, and therefore cannot run concurrently with any other modern webcam. However it is possible to run two Non-WDM Webcams using VFW drivers simultaneously, by changing the wDriver parameter in capGetDriverDescriptionA.

To begin coding this application, start a new VB.NET application project in Visual Studio .NET, and then drag a picture-box named camSrc to the form. It should be 320 pixels wide, and 240 pixels high. Double click on the form, and add the following code

Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal _

eventArgs As System.EventArgs) Handles MyBase.Load

MapWebcamToWindow(camSrc.Width, camSrc.Height, _


End Sub

Next, select the ‘closed’ event from the drop down list, and type the following code:

Private Sub Form1_Closed(ByVal eventSender As System.Object, ByVal _

 eventArgs As System.EventArgs) Handles MyBase.Closed


End Sub

These two subs, used to start and stop the webcam are implemented in a separate module, which we add to the project by right clicking on solution explorer and selecting new module. This new module, I have called WebcamCapture

To the top of this module, we add a public variable lwndC, which keeps track of a handle to the capture window. We also define a few constants, which are used as parameters to some API calls, which we shall see later.

Public lwndC As Integer

Public Const WS_CHILD As Integer = &H40000000

Public Const WS_VISIBLE As Integer = &H10000000

Public Const SWP_NOMOVE As Short = &H2S

Public Const SWP_NOZORDER As Short = &H4S

Public Const WM_USER As Short = &H400S

Page 2  Page 3  Page 4 


Copyright 2019 Infinite Loop Ltd.