GetTopLevelFrame in a dll

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?

LVL 11
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have you tried

CWnd* pWnd = AfxGetMainWnd();

CFrameWnd* pFrame = pWnd->GetTopLevelFrame();


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AgariciAuthor Commented:
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)

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
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.