您的位置:程序门 -> vc/mfc -> 进程/线程/dll



奇怪,afxbeginthread创建ui线程失败,并抛出访问非法内存的异常


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


奇怪,afxbeginthread创建ui线程失败,并抛出访问非法内存的异常[已结贴,结贴人:songpingbo]
发表于:2007-07-03 19:37:15 楼主
m_pmsgprocthread   =   afxbeginthread(runtime_class(cmsgprocthread),
                                    thread_priority_normal,  
                                      0,
                                      create_suspended);

cmsgprocthread是cwinthread的子类,cmsgprocthread类的头文件中有
declare_dyncreate(cmsgprocthread)

cmsgprocthread的实现文件中有:
implement_dyncreate(cmsgprocthread,   cwinthread)


这么会出这样的事呢?查了半天的资料没有找到为什么啊?
发表于:2007-07-03 19:52:251楼 得分:20
你单步调试看看
发表于:2007-07-03 19:55:122楼 得分:0
单调调度的时候发现在是afxbeginthread()在调用creatthread的下面第二个verify出现的内存异常:

//   start   the   thread   just   for   mfc   initialization
verify(resumethread()   !=   (dword)-1);
verify(::waitforsingleobject(startup.hevent,   infinite)   ==   wait_object_0);
::closehandle(startup.hevent);
发表于:2007-07-03 20:29:013楼 得分:20
你什么时候resume的这个线程?
发表于:2007-07-03 20:51:484楼 得分:0
//启动超时管理线程
m_ptimermngrthread   =     afxbeginthread(runtime_class(ctimermngthread));
if   (!m_ptimermngrthread)
{
ca_trc_err(dbgw_log_ctrl_app_frame,   "启动超时管理器失败! ");
return   false;
}

m_ptimermngrthread-> m_bautodelete   =   false;

//启动事件调度线程;
m_heventdispatchthread     =   (handle)_beginthreadex(null,0,dispatchevent,(void   *)(&m_casdb[1]),0,null);
if   (!m_heventdispatchthread)
{
ca_trc_err(dbgw_log_ctrl_app_frame,   "启动事件调度失败! ");
return   false;
}

//启动消息处理线程
        m_pmsgprocthread   =   afxbeginthread(runtime_class(cmsgprocthread),
                                                            thread_priority_normal,  
                                                            0,
                                                            create_suspended);
if   (!m_pmsgprocthread)
{
ca_trc_err(dbgw_log_ctrl_app_frame,   "启动消息处理器失败! ");
return   false;
}

m_pmsgprocthread-> m_bautodelete   =   false;

cmsgprocthread::setcasdb(m_pmsgprocthread,m_casdb);
m_pmsgprocthread-> resumethread();
发表于:2007-07-04 08:29:025楼 得分:20
try   to   use   createthread
发表于:2007-07-06 01:18:166楼 得分:0
干什么这么麻烦,给个email,给你个比较稳定的线程封装类。
发表于:2007-07-06 09:31:267楼 得分:20
handle   hthread=createthread(null,0,(lpthread_start_routine)searchfile,null,0,null);
closehandle(hthread);

uint   searchfile(lpvoid   lpparam)
{
return   0;
}
发表于:2007-07-12 11:36:308楼 得分:20
刚创建线程对象就出错,莫非你的cmsgprocthread类构造函数中有非法访问内存语句?
发表于:2007-07-13 19:04:299楼 得分:0
mark   一下


快速检索

最新资讯
热门点击