|
Mark,
Thanks for the prompt response.I do nto remeber saying that it dies in DragAcceptFiles. If I did, I was wrong. Sorry about that. In any case, here is a partial listing of the routine it dies in.
<br />
CDocument* CSingleDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName,<br />
BOOL bMakeVisible)<br />
{<br />
CDocument* pDocument = NULL;<br />
CFrameWnd* pFrame = NULL;<br />
BOOL bCreated = FALSE;
BOOL bWasModified = FALSE;<br />
<br />
if (m_pOnlyDoc != NULL)<br />
{<br />
pDocument = m_pOnlyDoc;<br />
if (!pDocument->SaveModified())<br />
return NULL;
<br />
pFrame = (CFrameWnd*)AfxGetMainWnd();<br />
ASSERT(pFrame != NULL);<br />
ASSERT_KINDOF(CFrameWnd, pFrame);<br />
ASSERT_VALID(pFrame);<br />
}<br />
else<br />
{<br />
pDocument = CreateNewDocument();<br />
ASSERT(pFrame == NULL);
bCreated = TRUE;<br />
}<br />
<br />
if (pDocument == NULL)<br />
{<br />
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);<br />
return NULL;<br />
}<br />
ASSERT(pDocument == m_pOnlyDoc);<br />
The statement that is gennerating the message box is:
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
I am thinking that CreateNewDocument should not be returning NULL but it is.
Thanks
Bob
|
|
|
|
|
|
Mark,
Thanks for the response. The place it is dying in is:
if (pDocument == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
return NULL;
}
ASSERT(pDocument == m_pOnlyDoc);
That is, pDocument is NULL so the body of the if statment is entered and the call to AfxMessageBox happens. I hope this is clear.
Bob
|
|
|
|
|
Awesome, thanks.
It looks like the only way that can happen is if there's already
a document created at the time of the call (there can only be ONE document
in SDI, by definition.
I'm not sure where the pre-existing document is coming from...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Actually, I'm missing something - I'm not seeing where it's possible for the assertion
to fail.
What are the values of pDocument and m_pOnlyDoc when that line
(ASSERT(pDocument == m_pOnlyDoc);) is reached??
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Actually, I'm missing something - I'm not seeing where it's possible for the assertion
to fail.
Dude I don't think those base classes should be in those RUNTIME_CLASS macros CDocument , CFrameWnd
BobInNJ wrote: pDocTemplate = new CSingleDocTemplate (
IDR_MAINFRAME,
RUNTIME_CLASS (CDocument),
RUNTIME_CLASS (CFrameWnd),
RUNTIME_CLASS (MyView)
);
led mike
|
|
|
|
|
Rut roh - Good point.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
Thanks for the response. The code fragment we are talking about is:
<br />
if (pDocument == NULL)<br />
{<br />
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);<br />
return NULL;<br />
}<br />
ASSERT(pDocument == m_pOnlyDoc);<br />
The ASSERT statement is never reached due to the fact that pDocument is NULL. Whe the if statement is reached, m_pOnlyDoc is NULL also.
Bob
|
|
|
|
|
If you comment out that statement, does the program work otherwise?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
David,
Thanks for the response. Commenting out the statement:
m_pMainWnd->DragAcceptFiles();
has no effect. Is this (above) the statement you are refering to.
Bob
|
|
|
|
|
BobInNJ wrote: Is this (above) the statement you are refering to.
Yes. Can you use the debugger to step over each statement to find the offending one?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
David,
Thanks for the response. I have walked through with the debugger. The details of what I found are in my thread with Mark on this issue. Please look there.
Bob
|
|
|
|
|
But you then need to step into CreateNewDocument() .
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
David and/or Mark,
Please consider the following code fragement:
<br />
CObject* CRuntimeClass::CreateObject()<br />
{<br />
ENSURE(this);<br />
<br />
if (m_pfnCreateObject == NULL)<br />
{<br />
TRACE(traceAppMsg, 0,<br />
_T("Error: Trying to create object which is not ")<br />
_T("DECLARE_DYNCREATE \nor DECLARE_SERIAL: %hs.\n"),<br />
m_lpszClassName);<br />
return NULL;<br />
}<br />
When I trace through this, pfnCreateObject is NULL. Therefore, I am thinking that one of my classes
is not properly declared. Do you agree with my reasoning?
Bob
|
|
|
|
|
In addition to David Crow's comments -
you CAN step into MFC source code and put breakpoints in it
(just in case you didn't know )
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I found a problem:
Please consider the following code fragment:
<br />
CSingleDocTemplate* pDocTemplate;<br />
pDocTemplate = new CSingleDocTemplate (<br />
IDR_MAINFRAME,<br />
RUNTIME_CLASS (CDocument),<br />
RUNTIME_CLASS (MyWindow),<br />
RUNTIME_CLASS (MyView)<br />
);<br />
AddDocTemplate (pDocTemplate);<br />
RegisterShellFileTypes (TRUE);<br />
It should have been:
<br />
CSingleDocTemplate* pDocTemplate;<br />
pDocTemplate = new CSingleDocTemplate (<br />
IDR_MAINFRAME,<br />
RUNTIME_CLASS (MyDocument),<br />
RUNTIME_CLASS (MyWindow),<br />
RUNTIME_CLASS (MyView)<br />
);<br />
AddDocTemplate (pDocTemplate);<br />
RegisterShellFileTypes (TRUE);<br />
After making this change, the code bombs out later. Any other ideas?
Thanks
Bob
|
|
|
|
|
...and the reason for it not working was due to fact that MFC CDocument class has Runtime class information because it is declared using DECLARE_DYNAMIC whereas your MyDocument class actually has functionality to allow dynamic creation of objects using CRuntimeClass because of DECLARE_DYNCREATE/IMPLEMENT_DYNCREATE.
So where does it break now?
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
It now dies inside the following MFC routine:
<br />
void CSingleDocTemplate::SetDefaultTitle(CDocument* pDocument)<br />
{<br />
CString strDocName;<br />
if (!GetDocString(strDocName, CDocTemplate::docName) ||<br />
strDocName.IsEmpty())<br />
{<br />
ENSURE(strDocName.LoadString(AFX_IDS_UNTITLED));<br />
}<br />
pDocument->SetTitle(strDocName);<br />
}<br />
In particular, with the call to ENSURE. Here is the call stack when it dies:
> sdi1.exe!CSingleDocTemplate::SetDefaultTitle(CDocument * pDocument=0x003d95e8) Line 207 C++
sdi1.exe!CSingleDocTemplate::OpenDocumentFile(const wchar_t * lpszPathName=0x00000000, int bMakeVisible=1) Line 141 C++
sdi1.exe!CDocManager::OnFileNew() Line 848 C++
sdi1.exe!CWinApp::OnFileNew() Line 22 C++
sdi1.exe!CWinApp::ProcessShellCommand(CCommandLineInfo & rCmdInfo={...}) Line 26 C++
sdi1.exe!MainApp::InitInstance() Line 50 + 0xc bytes C++
sdi1.exe!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x00020908, int nCmdShow=1) Line 37 + 0xd bytes C++
sdi1.exe!wWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x00020908, int nCmdShow=1) Line 30 C++
sdi1.exe!__tmainCRTStartup() Line 263 + 0x2c bytes C
sdi1.exe!wWinMainCRTStartup() Line 182 C
kernel32.dll!7c817067()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
I am hoping somebody here can tell me what I am doing wrong. I am finding programs using the SDI model to be very hard to write and debug.
Thanks
Bob
|
|
|
|
|
BobInNJ wrote: I am finding programs using the SDI model to be very hard to write and debug.
I would start with a wizard-generated SDI app instead of
code from a book or author. Subtle changes between MFC versions
could make that problematic - the wizard code should run right away
so you can get right to working on actual code
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Bob,
I agree with Mark. Try generating simple SDI application code using the wizard (make sure you don't select any advanced feature options in the wizard).
Let us know if you still have problem.
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hi all,
I'm trying to refresh the content of a CDockablePane in order to update the values that appear in the panel at runtime anytime that it is necessary. But I'm don't able to find where and How I have to do this task. My code is this:
int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rectDummy;
rectDummy.SetRectEmpty ();
if (!m_wndPropList.Create (WS_VISIBLE | WS_CHILD, rectDummy, this, 1))
{
TRACE0("Failed to create Properies Grid \n");
return -1;
}
m_wndPropList.EnableHeaderCtrl (FALSE);
m_wndPropList.EnableDescriptionArea ();
m_wndPropList.SetVSDotNetLook ();
CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("Visibilità Livelli"),ids);
string s = "Livello";
CGOEView d;
int level = d.GetNumberOfLevel();
for(int j=0;j<5;j++)
{
TRACE(_T("ciao"));
stringstream st;
st<<s<<j;
string stra = st.str();
CString stri (d.level[2][j].c_str());
CString str (stra.c_str());
pGroup1->AddSubItem(new CMFCPropertyGridProperty(stri, (_variant_t) true, _T("Questa è una descrizione"),j));
}
m_wndPropList.AddProperty(pGroup1);
return 0;
}
For example I will want to erase the last subitem of pgroup1 (in the part of the text pointed out by bold text) in which way I can do this at runtime?
|
|
|
|
|
Its first time I use of New Message on this forum but I think this article is helpful for you(of course I think you aware of it but for other friends that dont know about it.
Loading a DLL from memory[^].
|
|
|
|
|
Doing advertising?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
No thanks. 
|
|
|
|
|
Hamid. wrote: Its first time I use of New Message on this forum
Want a medal?
Regards,
--Perspx
"I've got my kids brainwashed: You don't use Google, and you don't use an iPod." - Steve Ballmer
"Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen an angry penguin charging at them in excess of 100mph." - Linus Torvalds
|
|
|
|