GetTopLevelFrame in a dll

Posted on 2006-04-25
Last Modified: 2013-11-20
i have this problem:
when i call to GetTopLevelFrame from an other module then the one that contains my application's main frame it returns NULL

now, the main frame GetTopLevelFrame should return is located in a dll and used into an simple win app.

i have looked over GetTopLevelFrame implementation in mfc and i can see why it returns NULL (it looks for a CFrameWnd that has no parent and my main frame is empedded into an other window, so it has a parent and its parent is not a CFrameWnd).

does anyone know of a way to make this function work when the main window is located in a dll and this method is called from another module?

Question by:Agarici
    LVL 86

    Accepted Solution

    Have you tried

    CWnd* pWnd = AfxGetMainWnd();

    CFrameWnd* pFrame = pWnd->GetTopLevelFrame();

    LVL 11

    Author Comment

    first, thank you for the prompt reply

    no, i haven;t try your sugestion, and i cant do that, because the call is from a dll which i can not modify

    but basically that is what that code does.
    let me explain a litle: i am using a third party library
    from this library i am trying to create a modal dialog (which is implemented in that 3rd party dll).
    GetTopLevelFrame gets called from somewere in DoModal and it returns NULL (i think because my main frame is in a dll and not in the exe module)

    LVL 49

    Assisted Solution

    When you create the modal dialog, are you able to specify its parent?  The constructor for CDialog provides and optional parameter...  So instead of,,,
        CMyDlg dlg;
        CMyDlg dlg( pwndWhateverYouWantToBeTheParentInTheCallToGetTopLevelFrame );

    If you are using some other method to construct the CDialog-derived object, please post the code that you are using.

    -- Dan
    LVL 22

    Assisted Solution

    As suggested by Dan you may try it by setting parent of window explicitly.

    You may also use CWnd::SetParent() function for this..

    pWnd->SetParent(this); // attach current window as parent or pass whatever parent window handle is.


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
    Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now