Click here to Skip to main content
15,885,757 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Sleep Function Pin
«_Superman_»3-Nov-10 6:29
professional«_Superman_»3-Nov-10 6:29 
Questionproblems with arrays Pin
rezen852-Nov-10 22:28
rezen852-Nov-10 22:28 
AnswerRe: problems with arrays Pin
Richard MacCutchan2-Nov-10 22:32
mveRichard MacCutchan2-Nov-10 22:32 
GeneralRe: problems with arrays Pin
rezen852-Nov-10 23:39
rezen852-Nov-10 23:39 
GeneralRe: problems with arrays Pin
Richard MacCutchan3-Nov-10 4:45
mveRichard MacCutchan3-Nov-10 4:45 
AnswerRe: problems with arrays Pin
ShilpiP2-Nov-10 22:45
ShilpiP2-Nov-10 22:45 
GeneralRe: problems with arrays Pin
rezen852-Nov-10 23:45
rezen852-Nov-10 23:45 
QuestionMDI with CDocument invalid pointer Pin
Pascal Pinchauret-Lamothe2-Nov-10 6:19
Pascal Pinchauret-Lamothe2-Nov-10 6:19 
Hi,

I am currently debugging an MDI application created with VC++ 6 which crashes randomly in debug configuration.
Sometimes, I get an assertion when a new document is created which comes from "Objcore.cpp / AfxAssertValidObject() / AfxIsValidAddress()" and says that the "pDocument" pointer is invalid.

I have created a second MDI test application that reproduces the architecture of the first application.
This application only allows one document at a time (a kind of SDI Smile | :) ).
Each time a document is closed, a new one is created automatically via a custom WM_COMMAND message and the new document is closed via ID_FILE_CLOSE.
All messages are sent using PostMessage.
The result is that the closing of the current document and the opening of the new document are not synchronized.

Here is the code added in the MDI test application:
#define ID_FILE_INFINITE		50000

// In CTestMDIApp

BEGIN_MESSAGE_MAP(CTestMDIApp, CWinApp)
    ON_COMMAND(ID_FILE_INFINITE, OnCommandOpenDoc)
END_MESSAGE_MAP()

void CTestMDIApp::InitInstance()
{
	m_pDocTemplateInfinite =  = new CMultiDocTemplate(...);
}

void CTestMDIApp::OnCommandOpenDoc()
{
	CTestMDIDoc* pDoc = static_cast< CTestMDIDoc* >(m_pDocTemplateInfinite->OpenDocumentFile(0));
	AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_FILE_CLOSE);
}

// In CTestMDIDoc

CTestMDIDoc::~CTestMDIDoc()
{
	TRACE(_T("PostMessage(WM_COMMAND, ID_FILE_INFINITE)\n"));
	AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_FILE_INFINITE);
}


When ID_FILE_CLOSE command param is processed, the following code is run:
CFrameWnd::OnClose()
    CDocument::OnCloseDocument()
        delete this; // calls ~CTestMDIDoc()
        ~CTestMDIDoc()
            AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_FILE_INFINITE);
        CDocument::~CDocument()
            m_pDocTemplate->RemoveDocument(this);


I know that PostMessage is asynchronous so my opinion is that in my test application,
a new document may be created before the previous one has finished its removing from m_pDocTemplate.
Is it the reason why a new document pointer becomes randomly invalid?
Thanks in advance for your answers.
Thanks and regards
Pascal

AnswerRe: MDI with CDocument invalid pointer Pin
Richard MacCutchan2-Nov-10 12:17
mveRichard MacCutchan2-Nov-10 12:17 
GeneralRe: MDI with CDocument invalid pointer Pin
Pascal Pinchauret-Lamothe25-Nov-10 4:22
Pascal Pinchauret-Lamothe25-Nov-10 4:22 
QuestionMulti-line List Control Pin
softwaremonkey2-Nov-10 5:06
softwaremonkey2-Nov-10 5:06 
AnswerRe: Multi-line List Control Pin
federico.strati2-Nov-10 5:39
federico.strati2-Nov-10 5:39 
AnswerRe: Multi-line List Control Pin
«_Superman_»2-Nov-10 7:06
professional«_Superman_»2-Nov-10 7:06 
QuestionXML parsing Pin
Benjamin Bruno2-Nov-10 3:19
Benjamin Bruno2-Nov-10 3:19 
AnswerRe: XML parsing Pin
CPallini2-Nov-10 3:25
mveCPallini2-Nov-10 3:25 
AnswerRe: XML parsing Pin
ShilpiP2-Nov-10 19:36
ShilpiP2-Nov-10 19:36 
QuestionAFX_EXT_CLASS Problem. Pin
002comp1-Nov-10 23:30
002comp1-Nov-10 23:30 
AnswerRe: AFX_EXT_CLASS Problem. Pin
Niklas L1-Nov-10 23:35
Niklas L1-Nov-10 23:35 
QuestionHelp me DisConnect Internet use Ras Pin
so0_lanhlung21-Nov-10 8:10
so0_lanhlung21-Nov-10 8:10 
AnswerRe: Help me DisConnect Internet use Ras Pin
«_Superman_»1-Nov-10 8:15
professional«_Superman_»1-Nov-10 8:15 
GeneralRe: Help me DisConnect Internet use Ras Pin
so0_lanhlung21-Nov-10 8:28
so0_lanhlung21-Nov-10 8:28 
GeneralRe: Help me DisConnect Internet use Ras Pin
«_Superman_»1-Nov-10 8:41
professional«_Superman_»1-Nov-10 8:41 
AnswerRe: Help me DisConnect Internet use Ras Pin
David Crow1-Nov-10 9:11
David Crow1-Nov-10 9:11 
AnswerRe: Help me DisConnect Internet use Ras Pin
Alain Rist1-Nov-10 10:15
Alain Rist1-Nov-10 10:15 
QuestionC2504 error using CMFCButton (or other CMFCFxxx classes) within a DLL Pin
Ralph1-Nov-10 6:51
Ralph1-Nov-10 6:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.