Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CFrameWnd::AssertValid() fails in debug mode

CFrameWnd::AssertValid() fails in debug mode

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    s_k
    wrote on last edited by
    #1

    I have Doc/View application. Upon one user command I create thread passing some user-defined data to it. This is the thread procedure: UINT ThreadLocalCopy(LPVOID pParam) { ___THREAD_COPY_PARAM* p_info = (THREAD_COPY_PARAM*)pParam; ___BYTE type = 0; ___DlgLocalCopy::LocalFolderCopy("", type, p_info); ___// finish operation ___::SendMessage(p_info->h_wnd, WM_THREADFINISHED, 0, 0); ___return 0; } And here's DlgLocalCopy::LocalFolderCopy() funcion, which is called from the thread above: void DlgLocalCopy::LocalFolderCopy(LPCTSTR pth, BYTE &type, THREAD_COPY_PARAM *p_param) { ___DlgOverwrite1 dov; ___DlgGetText dgt; ___DlgExpandSelection ds; ___CFileFind fff; ___CMainFrame* mf = (CMainFrame*) AfxGetApp()->GetMainWnd(); ___CMyDoc* p_doc = (CMyDoc*) mf->GetActiveDocument(); ___. ___. ___. } But calling CMyDoc* p_doc = (CMyDoc*) mf->GetActiveDocument() fails in CWnd::AssertValid() on this line: ASSERT((CWnd*)p == this); // must be us Why? I think that the stuff I am doing here is thread-safe, isn't it? I am not passing any CWnd objects to thread, I just call AfxGetApp()->GetMainWnd()->GetActiveDocument() inside the thread and it is not forbidden, is it? Or if it is, how to achieve it another (safe) way? Any help would be gratefully appreciated. Standa.

    N 1 Reply Last reply
    0
    • S s_k

      I have Doc/View application. Upon one user command I create thread passing some user-defined data to it. This is the thread procedure: UINT ThreadLocalCopy(LPVOID pParam) { ___THREAD_COPY_PARAM* p_info = (THREAD_COPY_PARAM*)pParam; ___BYTE type = 0; ___DlgLocalCopy::LocalFolderCopy("", type, p_info); ___// finish operation ___::SendMessage(p_info->h_wnd, WM_THREADFINISHED, 0, 0); ___return 0; } And here's DlgLocalCopy::LocalFolderCopy() funcion, which is called from the thread above: void DlgLocalCopy::LocalFolderCopy(LPCTSTR pth, BYTE &type, THREAD_COPY_PARAM *p_param) { ___DlgOverwrite1 dov; ___DlgGetText dgt; ___DlgExpandSelection ds; ___CFileFind fff; ___CMainFrame* mf = (CMainFrame*) AfxGetApp()->GetMainWnd(); ___CMyDoc* p_doc = (CMyDoc*) mf->GetActiveDocument(); ___. ___. ___. } But calling CMyDoc* p_doc = (CMyDoc*) mf->GetActiveDocument() fails in CWnd::AssertValid() on this line: ASSERT((CWnd*)p == this); // must be us Why? I think that the stuff I am doing here is thread-safe, isn't it? I am not passing any CWnd objects to thread, I just call AfxGetApp()->GetMainWnd()->GetActiveDocument() inside the thread and it is not forbidden, is it? Or if it is, how to achieve it another (safe) way? Any help would be gratefully appreciated. Standa.

      N Offline
      N Offline
      Neville Franks
      wrote on last edited by
      #2

      MFC's handle maps are maintained on a per thread basis, so from your worker thread AfxGetApp()->GetMainWnd() won't work. One solution is to pass CMyDoc* to your thread creation function. Also it isn't a good idea to use SendMessage() from a thread, use PostMessage() instead or Events. Have a read of the Threading articles here on CP. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups