avicap32 disconnect

  • Thread starter Thread starter josh_bauer2020
  • Start date Start date
J

josh_bauer2020

Guest
I use below class for avicap32.dll


using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;

namespace www
{
public class WebCam
{
private const int WM_CAP_DRIVER_CONNECT = 0x40a;
private const int WM_CAP_DRIVER_DISCONNECT = 0x40b;
private const int WM_CAP_SET_PREVIEW = 0x432;
private const int WM_CAP_SET_PREVIEWRATE = 0x434;
private const int WM_CAP_SET_SCALE = 0x435;
private const int WS_CHILD = 0x40000000;
private const int WS_VISIBLE = 0x10000000;
private const short SWP_NOMOVE = 0x2;
private short SWP_NOZORDER = 0x4;
private short HWND_BOTTOM = 1;
int WM_CAP_GT_FRAME = 1084;
int WM_CAP_COPY = 1054;

[DllImport("avicap32.dll")]
protected static extern bool capGetDriverDescriptionA(short wDriverIndex,[MarshalAs(UnmanagedType.VBByRefStr)]ref String lpszName, int cbName, [MarshalAs(UnmanagedType.VBByRefStr)] ref String lpszVer, int cbVer);
[DllImport("avicap32.dll")]
protected static extern int capCreateCaptureWindowA([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, int hWndParent, int nID);
[DllImport("user32")]
protected static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
[DllImport("user32", EntryPoint = "SendMessageA")]
protected static extern int SendMessage(int hwnd, int wMsg, int wParam, [MarshalAs(UnmanagedType.AsAny)] object lParam);
[DllImport("user32")]
protected static extern bool DestroyWindow(int hwnd);

int DeviceID = 0;
int hHwnd = 0;
public bool OpenConnection(int _DeviceID, PictureBox Container)
{
DeviceID = _DeviceID;
string DeviceIndex = Convert.ToString(DeviceID);
hHwnd = capCreateCaptureWindowA(ref DeviceIndex, WS_VISIBLE | WS_CHILD, 0, 0, 640, 480, Container.Handle.ToInt32(), 0);
if (SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, DeviceID, 0) != 0)
{
SendMessage(hHwnd, WM_CAP_SET_SCALE, -1, 0);
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, -1, 0);
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, Container.Height, Container.Width, SWP_NOMOVE | SWP_NOZORDER);
return true;
}
else
{
DestroyWindow(hHwnd);
return false;
}
}
public void CloseConnection()
{
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, DeviceID, 0);
DestroyWindow(hHwnd);
}
}


I do not want to use CloseConnection() method but I want to disconnect avicap32 from

all devices or restart avicap32. How can I close all connections without knowing any handle?

Continue reading...
 
Back
Top