CFrameWnd::AssertValid() fails in debug mode

This is a discussion on CFrameWnd::AssertValid() fails in debug mode within the Windows Programming forums, part of the Platform Specific Boards category; I have Doc/View application. Upon one user command I create thread passing some user-defined data to it. This is the ...

  1. #1
    s_k
    s_k is offline
    Registered User
    Join Date
    Feb 2003
    Posts
    4

    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)
    {
    ___THREAD_COPY_PARAMp_info = (THREAD_COPY_PARAM*)pParam;
    ___BYTE type 0;
    ___DlgLocalCopy::LocalFolderCopy(""typep_info);
    ___// finish operation
    ___::SendMessage(p_info->h_wndWM_THREADFINISHED00);
    ___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:
    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.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    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, 06:06 PM
  2. Why my code works only in debug mode?
    By pingpangpang in forum C++ Programming
    Replies: 3
    Last Post: 06-04-2007, 01:39 PM
  3. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 12:08 PM
  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, 02:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21