急救,用API调用摄像头来拍照时遇到的问题!

mrluoluo 2006-09-11 05:45:35
---
对 PInvoke 函数“getPicture!Video.VideoWork::SendMessage”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。
---

[DllImport("avicap32.dll")]
private static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);
[DllImport("avicap32.dll")]
private static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize );
[DllImport("User32.dll")]
private static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, long lParam);
/// <summary>
/// 开始显示图像
/// </summary>
public bool Start()
{
if (bWorkStart)
return bWorkStart;
byte[] lpszName = new byte[100];
//DeviceSelector ds = new DeviceSelector(s);
hWndC = capCreateCaptureWindowA(lpszName,WS_CHILD|WS_VISIBLE ,mLeft,mTop,mWidth,mHeight,mControlPtr,0);
if (hWndC.ToInt32() != 0)
{
SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
bWorkStart = true;
//Global.log.Write("SendMessage");
}
return bWorkStart;
}
用的这种方法,请高手帮帮忙!
...全文
957 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
VirtualDesktop 2006-09-13
  • 打赏
  • 举报
回复
private const int WM_USER = 0x0400;
private const int WM_CAP_START =WM_USER;
public static int WM_CAP_DLG_VIDEOSOURCE =(WM_CAP_START+ 42);

我不知道如何用程序选择,这个看来只能让用户手动选择
mrluoluo 2006-09-12
  • 打赏
  • 举报
回复
谢谢
VirtualDesktop(吴滂:欢迎到我的Blog转转 ^_^)
ohappy()
chaircat(chaircat)

第一个问题已经解决了,我现在是不知道怎么选择摄像头设备,我有两个摄像头,在什么地方,哪个参数是选择使用哪个设备的?
mrluoluo 2006-09-12
  • 打赏
  • 举报
回复
VirtualDesktop(吴滂:欢迎到我的Blog转转 ^_^)
SendMessage(m_hwnd,WM_CAP_DLG_VIDEOSOURCE,0,0);

---
中间的常量是多少?

如果可以选择了,哪个参数是设置要用的摄像头?
VirtualDesktop 2006-09-12
  • 打赏
  • 举报
回复
搞错了,应该是这个
SendMessage(m_hwnd,WM_CAP_DLG_VIDEOSOURCE,0,0);
VirtualDesktop 2006-09-12
  • 打赏
  • 举报
回复
你用SendMessage弹出那个视频属性对话框应该可以选择
SendMessage(m_hwnd,WM_CAP_DLG_VIDEOFORMAT,0,0);
chaircat 2006-09-11
  • 打赏
  • 举报
回复
.NET里面的long类型是64位的...不同于C++里面的long int...
ohappy 2006-09-11
  • 打赏
  • 举报
回复
托管声明有问题:第一个改为
[DllImport("avicap32.dll")]
private static extern IntPtr capCreateCaptureWindowA([ MarshalAs( UnmanagedType.ByValArray, SizeConst=100)]byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);

mrluoluo 2006-09-11
  • 打赏
  • 举报
回复
帮忙帮忙呀!!!!!!!
mrluoluo 2006-09-11
  • 打赏
  • 举报
回复
还有,用这种方式调用摄像头,在什么地方设置所用的是哪个设备?(假如有两个以上的视频输入设备)!!!
谢谢谢谢谢谢帮忙!
VirtualDesktop 2006-09-11
  • 打赏
  • 举报
回复
API声明有问题,改成下面的
private static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
mrluoluo 2006-09-11
  • 打赏
  • 举报
回复
我调试运行的时候出来这个错误,先生成,直接运行(不调试),就不会出现,请问是什么原因,问题严重吗?

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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