?
Solved

CMultiDocTemplate::CreateNewFrame returns NULL the second time

Posted on 2010-04-07
16
Medium Priority
?
1,367 Views
Last Modified: 2013-11-20
Hello,
I am having a trouble with the CreateNewFrame function from CMultiDocTemplate.
The first time I use it, it works fine and my window opens correclty. If I try to open a new one, once again everything is fine and I can see my two windows.
Now if I close all the windows that were opened previously, I can't anymore create a new window since CreateNewFrame always returns NULL.
I am thinking I must miss something pretty dumb...
// Creation of the template
pDocTemplate = new CMultiDocTemplate(IDR_RESOURCE, 
                                pDoc->GetRuntimeClass(), 
				RUNTIME_CLASS(CMyWnd),
				RUNTIME_CLASS(CMyView));
AddDocTemplate(pDocTemplate);

void func()
{
  // Creation of one view
  CMyWnd* pMyWnd = (CMyWnd*)m_pDocTemplate->CreateNewFrame(pDoc, NULL);

  if (pMyWnd)		
      pDocTemplate->InitialUpdateFrame(pMyWnd, pDoc);
}

Open in new window

0
Comment
Question by:DBTechnique
  • 7
  • 6
  • 2
  • +1
16 Comments
 
LVL 19

Expert Comment

by:alb66
ID: 30090941
Step into CreateNewFrame() and try to understand where it fails
0
 

Author Comment

by:DBTechnique
ID: 30091132
Hello,
I did that but it seems that the code I go into is not the one I am viewing in the editor (the cursor just jump without any consistency to the code).
So no chance to get information from here.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 30091625
How and where are you calling func() ?
Which version of visual studio ?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:DBTechnique
ID: 30091928
Hello,
My version is VS2008, MFC 9.0.
All this code is in a DLL.
When I click the menu, my menu manager transfers the event to func().
Then in func, I first switch the resources to those of my DLL and then do the call the CreateNewFrame(...).
If it is of any importance, the document class is a "dumb" class derivated from CDocument with no special behaviour.
0
 
LVL 19

Expert Comment

by:alb66
ID: 30092118
>>>>> I did that but it seems that the code I go into is not the one I am viewing in the editor

Look in the output window in order to see form which path the dll is loaded
0
 

Author Comment

by:DBTechnique
ID: 30093092
Hello,
Do you mean the MFC dll ?
I have those information from the Output window :

Loaded 'C:\Windows\System32\ntdll.dll'
Loaded 'C:\Windows\System32\kernel32.dll'
Loaded 'C:\Windows\System32\KernelBase.dll'
Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugmfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_2f2cc1b4522cec06\mfc90ud.dll', Symbols loaded.
Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_2a4cbfc25558bcd3\msvcr90d.dll', Symbols loaded.
Loaded 'C:\Windows\System32\user32.dll'
Loaded 'C:\Windows\System32\gdi32.dll'
Loaded 'C:\Windows\System32\lpk.dll'
Loaded 'C:\Windows\System32\usp10.dll'
Loaded 'C:\Windows\System32\msvcrt.dll'
Loaded 'C:\Windows\System32\shlwapi.dll'
Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16385_none_421189da2b7fabfc\comctl32.dll'
Loaded 'C:\Windows\System32\msimg32.dll'
Loaded 'C:\Windows\System32\oleaut32.dll'
Loaded 'C:\Windows\System32\ole32.dll'
Loaded 'C:\Windows\System32\rpcrt4.dll'
Loaded 'C:\Windows\System32\ws2_32.dll'
Loaded 'C:\Windows\System32\nsi.dll'
Loaded 'C:\Windows\System32\advapi32.dll'
Loaded 'C:\Windows\System32\sechost.dll'
Loaded 'C:\Windows\System32\shell32.dll'
Loaded 'C:\Windows\System32\wsock32.dll'
Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_4bf5400abf9d60b7\mfc90u.dll', Symbols loaded.
Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_508ed732bcbc0e5a\msvcr90.dll'
Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_508ed732bcbc0e5a\msvcp90.dll'
Loaded 'C:\Windows\System32\version.dll'
Loaded 'C:\Windows\System32\comdlg32.dll'
Loaded 'C:\Windows\System32\apphelp.dll'
Loaded 'C:\Windows\AppPatch\AcLayers.dll'
Loaded 'C:\Windows\System32\sspicli.dll'
Loaded 'C:\Windows\System32\userenv.dll'
Loaded 'C:\Windows\System32\profapi.dll'
Loaded 'C:\Windows\System32\winspool.drv'
Loaded 'C:\Windows\System32\mpr.dll'
Loaded 'C:\Windows\System32\imm32.dll'
Loaded 'C:\Windows\System32\msctf.dll'
Loaded 'C:\Windows\System32\avgrsstx.dll'
Loaded 'C:\Windows\System32\uxtheme.dll'
Loaded 'C:\Windows\System32\dwmapi.dll'
Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.mfcloc_1fc8b3b9a1e18e3b_9.0.30729.4148_none_4973eb1d754a9dc9\MFC90ENU.DLL', Binary was not built with debug information.
Loaded 'C:\Windows\System32\icmp.dll'
Loaded 'C:\Windows\System32\IPHLPAPI.DLL'
Loaded 'C:\Windows\System32\winnsi.dll'
Loaded 'C:\Windows\System32\cryptbase.dll'
Loaded 'C:\Windows\System32\ntmarta.dll'
Loaded 'C:\Windows\System32\Wldap32.dll'
Loaded 'C:\Windows\System32\perfproc.dll'
Unloaded 'C:\Windows\System32\perfproc.dll'
Loaded 'C:\Windows\System32\mswsock.dll'
Loaded 'C:\Windows\System32\WSHTCPIP.DLL'
Loaded 'C:\Windows\System32\clbcatq.dll'
Loaded 'C:\Windows\System32\IME\IMEJP10\IMJPTIP.DLL'
Loaded 'C:\Windows\System32\oleacc.dll'
Loaded 'C:\Windows\System32\IMJP10K.DLL'
Loaded 'C:\Windows\System32\IME\shared\IMETIP.DLL'
Loaded 'C:\Windows\System32\IME\shared\imecfm.dll'
Loaded 'C:\Windows\System32\IME\IMEJP10\IMJPAPI.DLL'
Loaded 'C:\Windows\System32\IME\shared\IMJKAPI.DLL'
Loaded 'C:\Windows\System32\opengl32.dll'
Loaded 'C:\Windows\System32\ddraw.dll'
Loaded 'C:\Windows\System32\dciman32.dll'
Loaded 'C:\Windows\System32\setupapi.dll'
Loaded 'C:\Windows\System32\cfgmgr32.dll'
Loaded 'C:\Windows\System32\devobj.dll'
Loaded 'C:\Windows\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7600.16385_none_72fc7cbf861225ca\GdiPlus.dll'
0
 
LVL 19

Expert Comment

by:alb66
ID: 30093343
>>> Do you mean the MFC dll ?

No, your dll
0
 

Author Comment

by:DBTechnique
ID: 30093413
Hello,
My DLL is loaded from the a subfolder of my application.
The ouput window is confirming that.
0
 

Author Comment

by:DBTechnique
ID: 30095873
Hello,
I have some more information.
I can't remember what I did and when I look at the code, only the view class has changed, but now, instead of not opening the window, it crash when trying to do it.
Still in the CreateNewFrame function.
The crash happens when calling the CMDIChildWnd::LoadFrame function.
0
 
LVL 19

Expert Comment

by:alb66
ID: 30096793
May be you have some problems with loading resources
0
 

Author Comment

by:DBTechnique
ID: 30098168
Hello,
Yes it seems so, but I don't understand why it doesn't happen the first time.
I could create more than 40 windows without problems, but as soon as they are all closed, then I can't make a new one.
Also the crash is occuring within the function CDocument::AddView, when trying to call CPtrList::AddTail()
0
 
LVL 19

Accepted Solution

by:
alb66 earned 2000 total points
ID: 30098456
If you have other views opened on a document, the document is opened.
When you close the last view the document object is closed too, so may be that pDoc parameter is no more valid.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 30098579
Hi,

where does the 'pDoc' come from you use in the 'func'?

Do you re-use that 'pDoc' in all frames/views? If so simply the 'pDoc' maybe deleted when the last frame/view is destroyed and creating a new one fails since 'pDoc' points to nirwana ...

ZOPPO
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 30098612
Sorry, alb66, forgot to refresh befor I submitted this - please ignore ...
0
 
LVL 19

Expert Comment

by:alb66
ID: 30098739
Hey Zoppo, don't worry ;-)
0
 

Author Comment

by:DBTechnique
ID: 30098863
ehehe thanks a lot !
That's exactly what happened.
After I close the last view, the document is no more valid.
Thanks again Alb66 !
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

607 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