locked
AfxGetMainWnd() return NULL RRS feed

  • Question

  • I have a problem. 

    This code this within a thread. 
     
    CFrameWnd *pFrame = (CFrameWnd*)AfxGetMainWnd(); 
     
    if (pFrame != NULL) 
     

     
    .... 
     

     
    For some reaso, AfxGetMainWnd() returns NULL. Why is that?  
     
    Same code is working fine in evc . 

    Need  the window to send a message 

    Thanks for ur help

    Thursday, November 23, 2006 2:21 PM

Answers

  • You get this when you try to call AfxGetMainWnd () from an other thread (has to do with thread local storage)

    Try AfxGetApp ()->GetMainWnd () instead.

     

    Friday, November 24, 2006 9:37 AM

All replies

  • You get this when you try to call AfxGetMainWnd () from an other thread (has to do with thread local storage)

    Try AfxGetApp ()->GetMainWnd () instead.

     

    Friday, November 24, 2006 9:37 AM
  • This was very helpfull to me. This works as explained, when called from another thread and in my case a delegate function, getting the main app and then the window worked, and no more unhandled exception. Thanks, jonesap5
    Thursday, February 10, 2011 10:30 PM