Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a simple WebCam monitor in VisualBasic. The complete program is below. The Form contains a Panel called VideoPanel and a ComboBox. The compiler also contains references to DirectX.Capture.dll (V 1.0.1313.24984) and DshowNET.dll (V 1.0.0.1)

Amazingly this simple program actually works! The trouble is it does not work on every computer. On some computers the line 'ListOfDevices = New Filters()' fails to find any devices and throws up the error message 'No devices of the category' even when there are video devices present.

Imports DirectX.Capture

Public Class Form1

  Dim ListOfDevices As New Filters
  Dim Camera As Filter
  Dim CaptureInfo As Capture

  Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    ComboBox1.Items.Clear()
    Try
      ListOfDevices = New Filters()
    Catch ex As Exception
      MsgBox(ex.Message) : End
    End Try
    Dim f As Filter
    For j = 0 To ListOfDevices.VideoInputDevices.Count - 1
      f = ListOfDevices.VideoInputDevices(j)
      ComboBox1.Items.Add(f.Name)
    Next
  End Sub

  Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    Camera = ListOfDevices.VideoInputDevices(ComboBox1.SelectedIndex)
    CaptureInfo = New Capture(Camera, Nothing)
    CaptureInfo.PreviewWindow = VideoPanel
    CaptureInfo.Start()
  End Sub
End Class


What I have tried:

It would appear that this has been a long running problem and I have not been able to find a definitive answer on the web. It has been suggested that the problem could be fixed by setting the target platform to x86 but my version of Visual Basic is already set to that. (I am using Visual Basic 2010 Express)

Any new suggestions would be welcome!
Posted
Updated 11-Mar-21 0:54am
v5
Comments
[no name] 9-Mar-21 14:25pm    
You should "develop" under Windows 10, not the other way around.
Richard Deeming 10-Mar-21 9:38am    
Sounds like your application is crashing with an unhandled exception. You need to log the details of that exception before you can begin to diagnose the problem.
public static void Main(string[] args)
{
    Application.ThreadException += UIThreadException;
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
    Application.Run(new Form1());
}

private static void UIThreadException(object sender, ThreadExceptionEventArgs e)
{
    ...
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    ...
}
Application.SetUnhandledExceptionMode Method (System.Windows.Forms) | Microsoft Docs[^]
Member 15092484 11-Mar-21 5:38am    
I am sure you are right. I have spent hours trying to get the application to send data to the Application Event Log but sadly without success. I get error messages at every turn. BTW I am using VB not C so the above code is of little use to me. Thanks anyway.
Richard Deeming 11-Mar-21 5:40am    
If you look at the Microsoft Docs link I sent you, you can select the language for the code samples in the top-right corner of the page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900