CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: AfxMessageBox

  1. #1
    Join Date
    Apr 1999
    Posts
    5

    AfxMessageBox

    Hi,

    I have problems with AfxMessageBox. It always give me the debug assertion failed message :
    File:appui1.cpp
    Line: 215

    This happens with the ff. scenario:
    I have multiple documents MFC application. That application uses a dll. In the dll, I call AfxMessageBox(); The said function works fine when no document is open and I try to open a documentfile and display that message. But then the above assertion failed problem occurs when a document file is already opened. I try to open another document file (with both the open function and recent file list files), so in my code, i close the childframe window plus document (in fact i just call my childframe::OnClose() function) then dispay that AfxMessageBox(). That's when the debug assertion failed. I found out that the debug assertion is triggered in the

    CFameWnd* PASCAL CCmdTarget::GetRoutingFrame_(){
    ASSERT_VALID(pFrame);




    so can u give me some ideas to solve this?
    thank you very much....




  2. #2
    Join Date
    Jun 1999
    Location
    A.P., INDIA
    Posts
    27

    Re: AfxMessageBox

    The 1st parameter for AfxMessageBox() should be either a pointer to a string (to be displayed)
    OR
    a unique ID used to reference the string (to be displayed) in the string table.
    Most probably the 1st parameter to AfxMessageBox()is neither of the two mentioned above. It would be helpful if we could see the exact code used for calling the AfxMessageBox() function along with the datatypes of each of its parameters.


  3. #3
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: AfxMessageBox

    Judging by where it asserted, it looks like it was told to use the child frame as a parent for the message box, but then the child frame was no longer valid. When you have no document open, the only frame (and therefore the one passed as the message box's parent, I assume) is the main frame, and so it remains valid. Perhaps you could show us the code where you call the message box and where you close the frame, to show us the order of things being done. It might give us a clue.


    --
    Jason Teagle
    [email protected]

  4. #4
    Join Date
    Apr 1999
    Posts
    5

    Re: AfxMessageBox


    Thank you very much for replying quickly. From what you said, I've gather that you are quite right. Anyweiz, we are using MDI but then everytime we open a documentfile, we close the other one then opne a new one. Here is my code:


    void CTeleButlerApp::OnFileOpen() {
    // TODO: Add your command handler code here
    CString szFilter;
    szFilter.LoadString(IDS_PROJECT_FILTER);
    CFileDialog ourDlg(TRUE,".jms",NULL,OFN_HIDEREADONLY | OFN_LONGNAMES,szFilter,NULL);
    int ret = ourDlg.DoModal();
    if (ret==IDCANCEL)
    return;


    // Closing the current child or view
    CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
    CChildFrame *pChild = (CChildFrame *)pFrame->GetActiveFrame();
    if (pChild!=(CChildFrame*)pFrame)
    {
    int ret = pChild->OnClose();
    if (!ret)
    return;
    }



    m_szFileName = ourDlg.GetPathName();
    int fh;
    if( (fh = _open( m_szFileName, _O_RDONLY, _S_IREAD)) != -1 )
    {
    if (_filelength( fh )==0)
    {
    AddToRecentFileList(m_szFileName);
    CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
    CChildFrame *pChild = (CChildFrame *)pFrame->GetActiveFrame();
    if (pChild!=(CChildFrame*)pFrame)
    {
    int ret = pChild->OnClose();
    if (!ret)
    return;
    }


    HCURSOR hourglass;
    hourglass = (HCURSOR)::LoadCursor(NULL,IDC_WAIT);
    SetCursor(hourglass);
    NewProj(m_szFileName);
    g_ModiCtr=0;
    pDocTemplate->CloseAllDocuments(FALSE);
    if (m_pDocManager != NULL)
    m_pDocManager->OnFileNew();

    pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
    pChild = (CChildFrame *)pFrame->GetActiveFrame();
    pChild->GetActiveDocument()->SetTitle(m_szFileName);
    _close(fh);
    return;
    }
    else {
    _close(fh);
    }


    // This will call a DLL which will show an AfxMessageBox when loading failed!!!
    /**********************************************************************/
    OnMtpOpen(m_szFileName,1);
    /**********************************************************************/


    }
    else {
    message.LoadString(IDS_FLOPERR);
    AfxMessageBox(message);
    }
    }




    Thank you


  5. #5
    Join Date
    Apr 1999
    Posts
    5

    Re: AfxMessageBox


    Thank you very much for your response. Anyweiz, the error doesn't occur in the AfxMessageBox() parameters since I am just passing there a string. The error occurs in the window that AfxMessageBox() will attached. Anyweiz, here is my code:


    void CTeleButlerApp::OnFileOpen() {
    // TODO: Add your command handler code here
    CString szFilter;
    szFilter.LoadString(IDS_PROJECT_FILTER);
    CFileDialog ourDlg(TRUE,".jms",NULL,OFN_HIDEREADONLY | OFN_LONGNAMES,szFilter,NULL);
    int ret = ourDlg.DoModal();
    if (ret==IDCANCEL)
    return;


    // Closing the current child or view
    CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
    CChildFrame *pChild = (CChildFrame *)pFrame->GetActiveFrame();
    if (pChild!=(CChildFrame*)pFrame)
    {
    int ret = pChild->OnClose();
    if (!ret)
    return;
    }



    m_szFileName = ourDlg.GetPathName();
    int fh;
    if( (fh = _open( m_szFileName, _O_RDONLY, _S_IREAD)) != -1 )
    {
    if (_filelength( fh )==0)
    {
    AddToRecentFileList(m_szFileName);
    CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
    CChildFrame *pChild = (CChildFrame *)pFrame->GetActiveFrame();
    if (pChild!=(CChildFrame*)pFrame)
    {
    int ret = pChild->OnClose();
    if (!ret)
    return;
    }


    HCURSOR hourglass;
    hourglass = (HCURSOR)::LoadCursor(NULL,IDC_WAIT);
    SetCursor(hourglass);
    NewProj(m_szFileName);
    g_ModiCtr=0;
    pDocTemplate->CloseAllDocuments(FALSE);
    if (m_pDocManager != NULL)
    m_pDocManager->OnFileNew();

    pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
    pChild = (CChildFrame *)pFrame->GetActiveFrame();
    pChild->GetActiveDocument()->SetTitle(m_szFileName);
    _close(fh);
    return;
    }
    else {
    _close(fh);
    }


    // This will call a DLL which will show an AfxMessageBox when loading failed!!!
    /**********************************************************************/
    OnMtpOpen(m_szFileName,1);
    /**********************************************************************/


    }
    else {
    message.LoadString(IDS_FLOPERR);
    AfxMessageBox(message);
    }
    }




    Thank you


  6. #6
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: AfxMessageBox

    I did not realise you were not passing in anything other than the string prompt to the DLL. How is your DLL getting the window to use as its parent? By default it tries to get the main window. I am surprised it works at all!

    I recommend passing in to the DLL a pointer to the main frame window, so that it has a valid parent to work with. In a DLL, there's no telling what it might do.



    --
    Jason Teagle
    [email protected]

  7. #7
    Join Date
    May 1999
    Posts
    54

    Re: AfxMessageBox

    I also faced the same problem with AfxMessageBox() ..But in my case the problem was the invalid memory.The string address which I was passing was pointing some invalid memory while running .. That leads to crash.
    But while debugging it was working fine.
    This may help U ...





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured