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

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

alb66Commented:
Step into CreateNewFrame() and try to understand where it fails
0
DBTechniqueAuthor Commented:
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
AndyAinscowFreelance programmer / ConsultantCommented:
How and where are you calling func() ?
Which version of visual studio ?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

DBTechniqueAuthor Commented:
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
alb66Commented:
>>>>> 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
DBTechniqueAuthor Commented:
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
alb66Commented:
>>> Do you mean the MFC dll ?

No, your dll
0
DBTechniqueAuthor Commented:
Hello,
My DLL is loaded from the a subfolder of my application.
The ouput window is confirming that.
0
DBTechniqueAuthor Commented:
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
alb66Commented:
May be you have some problems with loading resources
0
DBTechniqueAuthor Commented:
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
alb66Commented:
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

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
ZoppoCommented:
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
ZoppoCommented:
Sorry, alb66, forgot to refresh befor I submitted this - please ignore ...
0
alb66Commented:
Hey Zoppo, don't worry ;-)
0
DBTechniqueAuthor Commented:
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
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.