Link to home
Start Free TrialLog in
Avatar of DBTechnique
DBTechnique

asked on

CMultiDocTemplate::CreateNewFrame returns NULL the second time

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

Avatar of alb66
alb66
Flag of Italy image

Step into CreateNewFrame() and try to understand where it fails
Avatar of DBTechnique
DBTechnique

ASKER

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.
Avatar of AndyAinscow
How and where are you calling func() ?
Which version of visual studio ?
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.
>>>>> 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
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'
>>> Do you mean the MFC dll ?

No, your dll
Hello,
My DLL is loaded from the a subfolder of my application.
The ouput window is confirming that.
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.
May be you have some problems with loading resources
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()
ASKER CERTIFIED SOLUTION
Avatar of alb66
alb66
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Sorry, alb66, forgot to refresh befor I submitted this - please ignore ...
Hey Zoppo, don't worry ;-)
ehehe thanks a lot !
That's exactly what happened.
After I close the last view, the document is no more valid.
Thanks again Alb66 !