关于线程函数ResumeThread函数返回-1的问题

linda1984618 2015-09-02 01:27:22
pThrdModalDlg=::AfxBeginThread(CPublic::CallbackModalDlg,this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL);
ASSERT(pThrdModalDlg);
(CPublic::m_hEventModelDlgCreated)=CreateEvent(NULL,TRUE,FALSE,_T("ModalDlgCreated"));
::ResetEvent(CPublic::m_hEventModelDlgCreated);
int d=ResumeThread(pThrdModalDlg);
我是mfc新手,初次接触多线程,ResumeThread函数返回值总是为-1,请大家帮忙分析一下原因,谢谢!
...全文
227 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
原来身后 2015-09-17
  • 打赏
  • 举报
回复
使用GetlastError获取一下错误代码,使用错误查找工具对照一下具体哪里出问题了
linda1984618 2015-09-09
  • 打赏
  • 举报
回复
而且现在还有一个奇怪的现象,我在回调函数中用了一个domodal,希望主线程调回调函数的时候能domodal,然后响应OnCreate消息,可是怎么也不响应OnCreate消息,一直等到WAIT_OBJECT_0超时,才显示对话框,这是什么原因?
linda1984618 2015-09-09
  • 打赏
  • 举报
回复
引用 6 楼 schlafenhamster 的回复:
AfxBeginThread CWinThread* AfxBeginThread( AFX_THREADPROC pfnThreadProc, LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL ); CWinThread* AfxBeginThread( CRuntimeClass* pThreadClass, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL ); 你用 哪个 ?
第一个
schlafenhamster 2015-09-02
  • 打赏
  • 举报
回复
AfxBeginThread CWinThread* AfxBeginThread( AFX_THREADPROC pfnThreadProc, LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL ); CWinThread* AfxBeginThread( CRuntimeClass* pThreadClass, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL ); 你用 哪个 ?
linda1984618 2015-09-02
  • 打赏
  • 举报
回复
引用 2 楼 zgl7903 的回复:
pThrdModalDlg->ResumeThread(); 或者 ResumeThread(pThrdModalDlg->m_hThread)
我以前是用的您写的第一种方法,还是不行,总是-1,不知道是怎么回事
linda1984618 2015-09-02
  • 打赏
  • 举报
回复
引用 1 楼 oyljerry 的回复:
先看线程有没有创建成功
pThrdModalDlg有值,应该是创建成功了吧?
schlafenhamster 2015-09-02
  • 打赏
  • 举报
回复
Return Values If the function succeeds, the return value is the thread's previous suspend count. If the function fails, the return value is 0xFFFFFFFF. To get extended error information, call GetLastError.
zgl7903 2015-09-02
  • 打赏
  • 举报
回复
pThrdModalDlg->ResumeThread(); 或者 ResumeThread(pThrdModalDlg->m_hThread)
oyljerry 2015-09-02
  • 打赏
  • 举报
回复
先看线程有没有创建成功

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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