vb.net在vs2010使用user32.dll和avicap32.dll连接摄像头时出错

miliermili 2013-01-13 10:32:21
vb.net在vs2010使用user32.dll和avicap32.dll连接摄像头。。。
代码如下:

hWndC = capCreateCaptureWindowA(lpszName, WS_CHILD Or WS_VISIBLE, mLeft, mTop, mWidth, mHeight, mControlPtr, 0)

SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0) // 1
SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0) // 2
SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0) // 3
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0) // 4
SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0) // 5
SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0) // 6
SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0) // 7
SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0) // 8
出现问题:
首次连接成功,后续连接时失败。。。。
经过检测是:
首次连接 1、2、3、4、5、6、7、8 返回值均为 true

而后续连接 1、2、3、5 返回值为true 4、6、7、8返回值为 false
且代码【3】执行时会出现以下提示框:



求指导啊………………………………
能否给一个可行的解决方案?
...全文
616 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
killer2530 2013-09-04
  • 打赏
  • 举报
回复
我也遇到这个问题 没解决了啊
miliermili 2013-01-13
  • 打赏
  • 举报
回复
引用 3 楼 hjywyj 的回复:
if (!SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0)) SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0); //这样就行了
请问为什么需要连接两次啊??
miliermili 2013-01-13
  • 打赏
  • 举报
回复
还是不行啊…… 似乎是第一次断开连接不彻底,后来接连不上了。。。(我猜的) 用这个断开连接:SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0)
  • 打赏
  • 举报
回复
if (!SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0)) SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0); //这样就行了
miliermili 2013-01-13
  • 打赏
  • 举报
回复
是因为不能建立连接吗?有什么解决的方案?
miliermili 2013-01-13
  • 打赏
  • 举报
回复
求大侠指教啊,为什么SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0)的返回值为false
真相重于对错 2013-01-13
  • 打赏
  • 举报
回复
getlasterror
miliermili 2013-01-13
  • 打赏
  • 举报
回复
还是不行啊!
#region 导入API函数 [DllImport("avicap32.dll")]//包含了执行视频捕获的函数,它给AVI文件I/O和视频、音频设备驱动程序提供一个高级接口 public static extern IntPtr capCreateCaptureWindow(string lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hwndParent, int nID); /************参数说明************* * * 函数:capCreateCaptureWindow * * lpszWindowName:标识窗口的名称 * dwStyle:标识窗口风格 * x、y:标识窗口的左上角坐标 * nWidth、nHeight:标识窗口的宽度和高度 * hWnd:标识父窗口句柄 * nID:标识窗口ID * * 返回值:视频捕捉窗口句柄。 * ********************************/ [DllImport("AVICAP32.dll", CharSet = CharSet.Unicode)] public static extern bool capGetDriverDescription(int wDriverIndex, StringBuilder lpszName, int cbName, StringBuilder lpszVer, int cbVer); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, FrameEventHandler lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref BITMAPINFO lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPDRIVERCAPS lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPTUREPARMS lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPSTATUS lParam); [DllImport("User32.dll")] public static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags); [DllImport("avicap32.dll")] public static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize); #endregion

7,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧