您的位置:程序门 -> vc/mfc -> 图形处理/算法



vc程序异常退出


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vc程序异常退出
发表于:2008-01-14 21:25:57 楼主
我根据网上的代码做了一个摄像头显示图像程序
hwnd   ghwndcap; //捕获窗的句柄  
capdrivercaps   gcapdrivercaps; //视频驱动器的能力  
capstatus   gcapstatus; //捕获窗的状态  
char   szcapturefile[]   =   "mycap.avi";
char   gachbuffer[20];

连接摄像头
ghwndcap   =   capcreatecapturewindow((lpstr)"capture     window",
ws_child ¦ws_visible,
0,0,
300,240,
(hwnd)this-> m_hwnd,(int)0);  
capsetcallbackonerror(ghwndcap,   (farproc)errorcallbackproc);  
capsetcallbackonstatus(ghwndcap,   (farproc)statuscallbackproc);
capsetcallbackonframe(ghwndcap,   (farproc)framecallbackproc);
capdriverconnect(ghwndcap,   0);   //   将捕获窗同驱动器连接    

//获得驱动器的能力,相关的信息放在结构变量gcapdrivercaps中
capdrivergetcaps(ghwndcap,   &gcapdrivercaps,   sizeof(capdrivercaps));
cappreviewrate(ghwndcap,   66); //   设置preview模式的显示速率  
cappreview(ghwndcap,   true); //启动preview模式

if   (gcapdrivercaps.fhasoverlay) //检查驱动器是否有叠加能力  
capoverlay(ghwndcap,   true);   //启动overlay模式
if   (gcapdrivercaps.fhasdlgvideosource)
capdlgvideosource(ghwndcap);   //video   source   对话框  
if   (gcapdrivercaps.fhasdlgvideoformat)
capdlgvideoformat(ghwndcap);   //   video   format   对话框  
if   (gcapdrivercaps.fhasdlgvideodisplay)
capdlgvideodisplay(ghwndcap);   //   video   display   对话框

退出的时候
capsetcallbackonstatus(ghwndcap,   null);
capsetcallbackonerror(ghwndcap,   null);  
capsetcallbackonframe(ghwndcap,   null);
capcaptureabort(ghwndcap); //停止捕获  
capdriverdisconnect(ghwndcap); //将捕获窗同驱动器断开  


但是我不知道为什么过了一段时间它就自动退了
the   thread   0x5cc   has   exited   with   code   0   (0x0).
the   thread   0xa4c   has   exited   with   code   -1073741819   (0xc0000005).
the   thread   0x9c8   has   exited   with   code   -1073741819   (0xc0000005).
the   thread   0x5a0   has   exited   with   code   -1073741819   (0xc0000005).
the   thread   0xa50   has   exited   with   code   -1073741819   (0xc0000005).
the   program   'e:\vc\camera\debug\camera.exe'   has   exited   with   code   -1073741819   (0xc0000005).

意思应该是其中的线程退出了,但是我不知道哪个地方出问题了.请大家帮我看看.我现在想让它一直显示,该怎么做啊.
发表于:2008-01-14 22:29:131楼 得分:0
这个程序没有出现问题:
uint   threadfun(lpvoid   wparam)
{
ccapturedlg   *pdlg=(ccapturedlg*)wparam;
pdlg-> m_hvideownd=capcreatecapturewindow("capture",ws_popup,5,5,20,20,*pdlg,0);
if(pdlg-> m_hvideownd){
pdlg-> m_event.setevent();
msg   msg;
while(getmessage(&msg,pdlg-> m_hvideownd,0,0)){
translatemessage(&msg);
dispatchmessage(&msg);
}
return   msg.wparam;
}
return   0;
}
bool   ccapturedlg::oninitdialog()
{
cdialog::oninitdialog();

m_pthread=afxbeginthread(threadfun,(lpvoid)this);
m_event.resetevent();
::waitforsingleobject(m_event,infinite);

crect   rect;
getclientrect(&rect);
rect.deflaterect(1,1,1,1);

if(m_hvideownd){
if(capdriverconnect(m_hvideownd,0)==false){
messagebox("出错!");
return   0;
}
::setparent(m_hvideownd,*this);
::setwindowlong(m_hvideownd,gwl_style,ws_child);
::setwindowpos(m_hvideownd,null,rect.left,rect.top,rect.width(),rect.height(),swp_noredraw);
::showwindow(m_hvideownd,sw_show);
cappreviewrate(m_hvideownd,10);
cappreview(m_hvideownd,true);
capoverlay(m_hvideownd,true);
}
//   set   the   icon   for   this   dialog.     the   framework   does   this   automatically
//     when   the   application's   main   window   is   not   a   dialog
seticon(m_hicon,   true); //   set   big   icon
seticon(m_hicon,   false); //   set   small   icon

//   todo:   add   extra   initialization   here

return   true;    
}
发表于:2008-01-15 08:56:472楼 得分:0
我根据你的代码,又改了一些

dword   winapi   run(lpvoid   lpparam)
{
msg   msg;  
if((hwnd)lpparam)
{  
while(getmessage(&msg,(hwnd)lpparam,0,0))
{  
translatemessage(&msg);  
dispatchmessage(&msg);  
}  

}
return   0;
}

createthread(null,0,run,   ghwndcap,0,&tid);

这样也不行啊,还是自动退出
the   thread   0x9a0   has   exited   with   code   0   (0x0).
the   thread   0xf4   has   exited   with   code   -1073741819   (0xc0000005).
the   thread   0xa24   has   exited   with   code   -1073741819   (0xc0000005).
the   thread   0xab4   has   exited   with   code   -1073741819   (0xc0000005).
the   thread   0xc90   has   exited   with   code   -1073741819   (0xc0000005).
the   program   'g:\vc\camera\debug\camera.exe'   has   exited   with   code   -1073741819   (0xc0000005).
发表于:2008-01-15 09:45:553楼 得分:0
我完全按照你写的代码做了一个程序,但是窗口上的按钮全都不响应了,只能点右上角的关闭按钮才能关闭,这是为什么啊?
发表于:2008-01-15 11:48:054楼 得分:0
大哥,您重写一下它的退出消息,将:
capsetcallbackonstatus(ghwndcap,       null);  
capsetcallbackonerror(ghwndcap,       null);      
capsetcallbackonframe(ghwndcap,       null);  
capcaptureabort(ghwndcap);   //停止捕获      
capdriverdisconnect(ghwndcap);   //将捕获窗同驱动器断开      

加进去。


快速检索

最新资讯
热门点击