avicap32.dll WM_CAP_DRIVER_CONNECT problem RRS feed

  • Question

  • Dears

    I have a problem with WM_CAP_DRIVER_CONNECT message.
    It works only 1st time after system restart only (Windows 7 x64). Meanwhile it works fine always on another machine which is completely the same as mine. 

    Please find below the example of code.

    public void Attach(System.Windows.Forms.Control control)
                deviceHandle = Avicap32.capCreateCaptureWindow("", Constants.WS_VISIBLE | Constants.WS_CHILD, 0, 0, control.Width, control.Height, control.Handle, 0);

                if (User32.SendMessage(deviceHandle, Constants.WM_CAP_DRIVER_CONNECT, (IntPtr)deviceNumber, (IntPtr)0).ToInt32() > 0)
                    User32.SendMessage(deviceHandle, Constants.WM_CAP_SET_SCALE, (IntPtr)(-1), (IntPtr)0);
                    User32.SendMessage(deviceHandle, Constants.WM_CAP_SET_PREVIEWRATE, (IntPtr)0x42, (IntPtr)0);
                    User32.SendMessage(deviceHandle, Constants.WM_CAP_SET_PREVIEW, (IntPtr)(-1), (IntPtr)0);
                    User32.SetWindowPos(deviceHandle, new IntPtr(0), 0, 0, control.Width, control.Height, 6);

     public void Detach()
                if (deviceHandle.ToInt32() != 0)
                    User32.SendMessage(deviceHandle, Constants.WM_CAP_DRIVER_DISCONNECT, (IntPtr)deviceNumber, (IntPtr)0);
                deviceHandle = new IntPtr(0);


    I have tried several other examples, but the problem is the same always - WM_CAP_DRIVER_CONNECT fails after 1st successful run. 

    Where can be the problem? How to fix it?

    Thank you in advance

    Additional detail: when the message fails to connect then it shows dialog window "Video source" with drop down list which contains only one item - my build-in web camera. Anyway nothing works even if the item is choosen.

    • Edited by Alex0704 Friday, October 12, 2012 1:48 PM
    Friday, October 12, 2012 1:25 PM

All replies

  • Hi Alex0704,

      Welcome to MSDN Forum Support.

      We're doing research on this issue. It might take some time before we get back to you.


      Jason Wang

    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 15, 2012 3:29 AM
  • The code provided should work.  Since there is one machine that does not work, there is something different with that machine.  One thing to check is to run dxdiag from the good machine and from the bad machine, and then do a complete comparison of the files.  I suspect you will see some differences that will point to the component related to this.  We would need to diagnose a dump or trace of the process to attempt to really debug this, which would require a support case.

    If you cannot determine your answer here or on your own, consider opening a support case with us. Visit this link to see the various support options that are available to better meet your needs:  http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone.

    Trevor Hancock (Microsoft)
    Please remember to "Mark As Answer" the replies that help.

    Monday, October 22, 2012 6:14 PM
  • Finally I Found a solution for this
    The problem happen in Windows 7 / 8

    First you need this API function
    Private Declare Function GetTickCount Lib "kernel32" () As Long

    Then... after you call capCreateCaptureWindowA() you have to wait 1 second processing events, (note: sleep don't work the same)

    IniTime = GetTickCount()
    While GetTickCount() < (IniTime + 1000)

    then you call WM_CAP_DRIVER_CONNECT.. and THAT's IT.. no more Video Source dialog
    Thursday, October 2, 2014 9:47 PM