Thread: CFrameWnd::AssertValid() fails in debug mode

  1. #1
    Registered User
    Join Date
    Feb 2003

    CFrameWnd::AssertValid() fails in debug mode

    I have Doc/View application.
    Upon one user command I create thread passing some user-defined data to it.

    This is the thread procedure:

    PHP Code:
    UINT ThreadLocalCopy(LPVOID pParam)
    ___BYTE type 0;
    ___// finish operation
    ___return 0;

    And here's DlgLocalCopy::LocalFolderCopy() funcion, which is called from the thread above:

    PHP Code:
    void DlgLocalCopy::LocalFolderCopy(LPCTSTR pthBYTE &typeTHREAD_COPY_PARAM *p_param)
    ___DlgOverwrite1 dov;
    ___DlgGetText dgt;
    ___DlgExpandSelection ds;
    ___CFileFind fff;
    ___CMainFramemf = (CMainFrame*) AfxGetApp()->GetMainWnd();
    ___CMyDocp_doc = (CMyDoc*) mf->GetActiveDocument();

    But calling CMyDoc* p_doc = (CMyDoc*) mf->GetActiveDocument()
    fails in CWnd::AssertValid()
    on this line:

    PHP Code:
    ASSERT((CWnd*)== 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

    PHP Code:
    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.


  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Calling a CWnd member function via pointer from a thread that did not create that object can cause assertion failures.......the handle table table for these objects is thread specific so referenceing them from other threads is a bad idea....not too sure if this is your problem....

    Try access the main frame by calling CWnd::FromHandle to get a pointer to that window....that might fix it.......

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using the Debug mode ((F10) V.S 2005
    By csonx_p in forum Windows Programming
    Replies: 21
    Last Post: 06-17-2008, 05:06 PM
  2. Why my code works only in debug mode?
    By pingpangpang in forum C++ Programming
    Replies: 3
    Last Post: 06-04-2007, 12:39 PM
  3. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 11:08 AM
  4. Debug Mode Vs. Release Mode
    By incognito in forum Tech Board
    Replies: 5
    Last Post: 12-18-2003, 04:06 PM
  5. 2min in debug mode, 3sec in release!
    By glUser3f in forum C++ Programming
    Replies: 9
    Last Post: 10-03-2003, 01:00 PM