DestroyWindow ASSERT problem....strange, strange!

Hi

I have derived a dialog-class in a DLL (shared MFC)
I can construct an object of this class in my app, and when overloading

DoModal() and adding an AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
call, I can see the CMyDialog dialog.

But here is the issue, I have a timer set for a certain time, it posts
a message and the dialog has to be killed - so I use CDialog::OnCancel.

Then DoModal calls DestroyWindow() -
Here a copy of the m_hWnd is made in hWndOrig.
#ifdef _DEBUG
		hWndOrig = m_hWnd;
#endif

Then m_hWnd gets set to Null by ::DestroyWndow (which calls
OnNcDestroy).
But later in DestroyWindow itself, there is a check:
#ifdef _DEBUG
	ASSERT(m_hWnd == hWndOrig);
#endif

And the program asserts here, which is expected as the ::DestroyWindow
call before this set the m_hWnd to NULL......this is strange!

Please advise, I saw similar queries posted before, but no answers..I
have pasted the Wincore.cpp DestroyWindow() code below for reference...

Thanks!


	if (m_hWnd != NULL)
	{
		pMap = afxMapHWND();
		ENSURE(pMap != NULL);
		pWnd = (CWnd*)pMap->LookupPermanent(m_hWnd);
#ifdef _DEBUG
		hWndOrig = m_hWnd;
#endif
	}

#ifdef _AFX_NO_OCC_SUPPORT
	if (m_hWnd != NULL)
		bResult = ::DestroyWindow(m_hWnd);
#else //_AFX_NO_OCC_SUPPORT
	if ((m_hWnd != NULL) || (m_pCtrlSite != NULL))
	{
		if (m_pCtrlSite == NULL)
			bResult = ::DestroyWindow(m_hWnd);
		else
			bResult = m_pCtrlSite->DestroyControl();
	}
#endif //_AFX_NO_OCC_SUPPORT

	if (hWndOrig != NULL)
	{
		// Note that 'this' may have been deleted at this point,
		//  (but only if pWnd != NULL)
		if (pWnd != NULL)
		{
			// Should have been detached by OnNcDestroy
#ifdef _DEBUG
			ASSERT(pMap->LookupPermanent(hWndOrig) == NULL);
#endif
		}
		else
		{
#ifdef _DEBUG
			ASSERT(m_hWnd == hWndOrig);
#endif
		// Detach after DestroyWindow called just in case
			Detach();
		}

0
6/15/2006 9:39:06 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
1535 Views

Similar Articles

[PageSpeed] 26

Patanish wrote:
> Hi
>
> I have derived a dialog-class in a DLL (shared MFC)

What sort of DLL is it? Regular or MFC Extension? You should not use
AFX_MANAGE_STATE in a MFC Extension DLL.

> But here is the issue, I have a timer set for a certain time, it posts
> a message and the dialog has to be killed - so I use
> CDialog::OnCancel.

Is this the cause of it? In your OnClose, you should destroy the timer.


---
Ajay

0
ajaykalra (6842)
6/16/2006 2:31:50 AM
The KillTimer() is called before the Dialog::OnCancel.
I believe the problem is not with the timer, but with dialog window
handles?

Please advise. Has anyone has encountered similar problem with
DestroyWindow....
Thanks.

Ajay Kalra wrote:
> Patanish wrote:
> > Hi
> >
> > I have derived a dialog-class in a DLL (shared MFC)
>
> What sort of DLL is it? Regular or MFC Extension? You should not use
> AFX_MANAGE_STATE in a MFC Extension DLL.
>
> > But here is the issue, I have a timer set for a certain time, it posts
> > a message and the dialog has to be killed - so I use
> > CDialog::OnCancel.
>
> Is this the cause of it? In your OnClose, you should destroy the timer.
> 
> 
> ---
> Ajay

0
6/16/2006 5:29:12 AM
> Please advise. Has anyone has encountered similar problem with
> DestroyWindow....

No. This is MFC code and is called each time a modal dialog is
destroyed. You must be doing something different. You did not answer
about type of DLL this is.

---
Ajay

0
ajaykalra (6842)
6/16/2006 10:45:39 AM


<Bucefal> wrote in message news:20061215123618bucefal@vp.pl...
> The AFX_MANAGE_STATE(AfxGetStaticModuleState()) is a key. Call it before
DestroyWindow().

Why? Hopefully you are talking about for a MFC Regular DLL.

-- 
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


0
ajaykalra (6842)
12/15/2006 6:51:41 PM
Reply:

Similar Artilces:

G5 installation problem
I just received my new dual 2Ghz G5, but I can't get Office to install on it. I have taken off the "test drive" version of Office, but when I install my "real" version, none of the Office applications will launch. Every Office app crashes immediately when I double click on it. I can't even get to the screen where I enter my validation code. Any clues? Thanks. Diana > This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3149142613_7661167 Content-type: text/plain; charse...

Device Manager Problem with Vista
I have a two-fold problem actually. I am trying to perform a clean install of Vista. Vista is already on my laptop. I have a Toshiba Satellite P25-S5092 and I figured I would just boot from disk and go from there. The laptop will not boot from CD, even though the CD works fine after Vista drivers are installed. So I then try to install from Vista. Even the windows explorer sees my hard drive, the device manager does not and apparently the install disk checks the device manager. I am at my wits end. Someone please help. -- cupofjoe -----------------------------------...

POP3 access problem in Outlook XP / Windows XP
Using Outlook XP on Windows XP, when we tried to download mails from POP3 server, it is taking atlease 2 minutes to ask password or to start donloading message. Why is there a 2 minute delay? But the same is taking less than 1 minute in Outlook 97 + Windows 98 combination. This is a long shot, but try disabling the integration with Instant Messenger in Tools | Options | Other and see if that speeds things up. -- Jocelyn Fiorello MVP - Outlook *** Replies sent to my e-mail address will probably not be answered -- please reply only to the newsgroup to preserve the message thread. *** ...

Unicode problem
Given the following code snippet: WNetOpenEnum( dwScope, 0, 0, NULL, &hEnum ); struct hostent *host; DWORD Count = 0xFFFFFFFF; LPVOID Buffer = new char[16384]; DWORD BufferSize = 16384; WNetEnumResource(hEnum, &Count, Buffer, &BufferSize); NetResource = (NETRESOURCE *) Buffer; for (int i = 0; i < Count; i++, NetResource++) { CString strFullName = NetResource->lpRemoteName; ... host = gethostbyname((LPCTSTR) strFullName); } This works when I do *not* have _UNICODE and UNICODE defined. When I *do* define those directives, I get a compiler error on the call to the...

Problem with CListBox
I have a CListBox. I want it to have multiple columns, but I want it to scroll vertically, not horizontally. In the List-Box Styles, on MSDN there's LBS_MULTICOLUMN Specifies a multicolumn list box that is scrolled horizontally. The SetColumnWidth member function sets the width of the columns. I wonder if what options I have to make a multilcolumn list box that is scrolled vertically? Thanks for the help... Rachel Use CListCtrl in report mode instead of a CListBox. -- Cheers Check Abdoul [ VC++ MVP ] ----------------------------------- "Rachel" <orangepeach@yahoo.c...

Old password problem
I can't get rid of an old password. I've changed the password in Outlook and in Internet Explorer but from somewhere the old password keeps popping up. I reformatted the drive and reinstalled Windows and still that old password persists. Where is it coming from and how do I get rid of it? Bob What is this password for? What version of Outlook? -- PATRICK REED [Outlook - MVP]~~~~~~ -Microsoft Certified Professional (MCP) -Have you checked http://www.slipstick.com? -Please post your Outlook version! "rck" <musonthemt.SPAM_ME_NOT@earthlink.net> wrote in mess...

Debug Assertion failure....
I did a client server programming ...But when I executed this code,Debug Assertion Failure occur.How to solve this.?............. void CClientSocket::SendDetails() { CClientSocket Client; Client.Create(); if (0 == Client.Create()) { MessageBox(NULL,_T("Client Socket is not created"),_T("Client Socket"),0); } else MessageBox(0,_T("Client Socket is created successfully"),_T("Client Socket"),0); Client.Connect(_T("X36"),2000); CString szMessage=ObjCClientRRM.LoadInformation(); MessageBox(NULL,szMessage,"ClientDe...

a toolbar tooltip problem
Hi: I overload the CToolBar class , and process the default TBN_GETINFOTIP event to dynamicly changge its tooltips. ( ON_NOTIFY_REFLECT( TBN_GETINFOTIP, OnGetInfoTip) this way works well. Then I create a toolbar in the statusbar in one of my project, but this way doesn't work at all. I couldn't get the OnGetInfoTip event form the toolbar created in the statusbar now. Why? how could I do? Thanks Benben -- Thanks ...

Tab Key Problem
I have had two clients that have had this problem. They are both using GP10 with service pack 1. What could be causing it? If you hit the tab key, it doesn’t tab. It sits there. Other times it doesn't tab to the correct field, it will take you back to the first field on the window. Sometimes you have to close out of the program, get back in, try it and if it doesn’t work, you deal with it. The problem seems to resolve itself-not sure why or how. Has anyone else experienced this problem? What could be causing it? Thanks, Jocelyn I too have seen it and sometimes needed to ...

ASSERT problem in CWnd::DestroyWindow within a DLL
Hello, I've got a regular DLL (let's call A) with a custom control in it. This control uses a ToolTip control. I've got another regular DLL (let's call B) that contains a doc/view (the view is derived from CFormView and it has a CPropertySheet in it) to be imported from an App. I managed to import the doc/view template into the App and create new documents based on that template. In one of the property pages of the property sheet within the view there is an instance of the custom control contained in DLL A. The problem appears when the property page is destroyed (when closi...

problem with updating calendar appointments
Hi, I have a problem where sometimes a user will update an appointment in their calendar and send an update to all attendees. The updated information is accepted and show in the attendees calendar but when the user later checks the their calendar that updated information is missing. Has anyone else had this problem? Everyone is running Outlook 2007 with Exchange 2007. The user also has 1 Delegate with editor access to their calendar and meeting requests/responses sent to both delegate and themselves. Kind Regards I have the same problem with Outlook 2003 and Exchange 2003...

Problem with IF statement
I have a custom property Sex. Type 1, Format is M. F. I want to change the line color to blue or pink, so in Line Format I have: =IF(Prop.Sex="M",4,RGB(218,80,176)) It doesn't work!! what is the problem? Mike Never mind; I found out that I should have used: =IF(Prop.Sex=0,4,RGB(218,80,176)), since the relevant factor is not the name of the listed factors but their index no. Mike > "MikeM" wrote: > I have a custom property Sex. Type 1, Format is M. F. > > I want to change the line color to blue or pink, so in Line Format I have: > > =IF(Pr...

DestroyWindow function-help
hello, I have created a dialog based application.I have drawn a menu in it through which i plot another modeless dialog.I have created a class for the dialog called midialog.On in the menu handler i create pointer of this class and by allocating memory using new and using the create() function i create the modeless dialog.Do i need to explicitly call destroywindow in OnOk() and OnCancel()of my dialog?if yes how? coz i am creating dialog in the project's main dialog(thru menu) and then i will i have to pass a handle to destroy the dialog and its object in the OnOk() of my di...

share excel file problem
Hello , i am an italian technical i have this problem: - i have a server (windows2000) and one file excel - two users (user A and user B) scenario: user A open file excel user B open file excel and Excel DON'T SEE A MESSAGE FOR ALERT USER that user A work with this file. user b save the work and LOST IT !! thank and scuse for my english I had the same problem so on the workbook_open event I put this code: If Me.ReadOnly Then Result = MsgBox("Are you sure that you want to open this spreadsheet in Read_only? You won't be able to save any changes that you make!",...

outlook problem #10
i created a new message but minimised ot before sending later i tried to close the message window but was unable to close it. Also the system wont shut down unless i close all applications. Please note my OS is Win XP. Please help me as this message is recurring.. Thank you MPax. ...

Outlook Problem #53
I followed the discussion topics as I was receiving the extend.dat error and fixed that. Then, I went into "manage email accounts" and entered the login page http address for my godaddy email; however, once I entered that along with all other information (login, password, etc), outlook will not open at all so that I can fix anything. I don't even know if I set up the email account correctly as an HTTP either. Please help. http://help.godaddy.com/article/2649 "Bridgett" <Bridgett@discussions.microsoft.com> wrote in message news:C1000084-FAC0-4BB2-B5AC-1C...

Margin problem
Hello A work with Windows Vista. My problem is when I print the emails, the text is on the edge of the page. Sometimes it misses the 1st letter. How to shift slightly the text on the right to leave a margin on the left. My PC is a SONY VGN-CR31S Thank you for your help. Horizonbleu "Horizonbleu" <Horizonbleu@discussions.microsoft.com> wrote in message news:69F3529C-D9FF-49E1-B12F-1D51BF0D49FB@microsoft.com... > Hello > A work with Windows Vista. > My problem is when I print the emails, the text is on the edge of the > page. > Sometimes i...

Outlook 2003 Sound Problem
When I set the sound function for "New Mail Notification" in the control panel the sound will not play when new messages arrive in Outlook. Anyone else run into this problem? System is: Window XP Pro SP1 MSOffice 2003 See my reply to your post in microsoft.public.office.misc. -- Jocelyn Fiorello MVP - Outlook *** Messages sent to my e-mail address will NOT be answered -- please reply only to the newsgroup to preserve the message thread. *** In news:0a6d01c3d3b4$24aa9940$a601280a@phx.gbl, Bonrea wrote: > When I set the sound function for "New Mail Notification&qu...

Import Problems
I stopped using Money because everytime I download and then import my bank account from one institution, it imports into an old, rarely used account. I have been able to download statements correctly in the past. I don't know why this problem has started and what I should do. Money no longer asks which account to import into. Any ideas how to get it to ask? That would probably solve this problem. In microsoft.public.money, Dave wrote: >I stopped using Money because everytime I download and then import my bank >account from one institution, it imports into an old, rarely ...

Need help. Conditional formatting problems
I have setup a worksheet that contains QC information. I created a simple "form" for the techs to enter there data into and then that "form" is repeated at least 52 (52 weeks in a year) times on the same worksheet. Setting up conditional formatting is very time consuming and I need a faster easier way to do it. This is what my "form" looks like: ------------------------------------------------------------------------------------------------ Week 1 Date set _*12/28/09_ Organism tested (E.coli) Initials __DA___ Drug tested ...

PASSWORD PROBLEMS #4
I had considerable problems with my Windows Live ID/password with Essentials, with absolutely no releif. In reading other posts determined that I just needed to upgrade to Money Plus (so I did). STILL CANNOT LOG IN. Cannot even access the website through Money. ARGH! In microsoft.public.money, Eileen wrote: >I had considerable problems with my Windows Live ID/password with Essentials, >with absolutely no releif. In reading other posts determined that I just >needed to upgrade to Money Plus (so I did). STILL CANNOT LOG IN. Cannot >even access the website through Money...

Installation Problem
Hello, I am a licensed user of publisher97; lost my cd install key and just have the media. I also have the product ID; but when I go to submit a support incident it says that I've used all my support incidents up for that product. I've never called on that product before. Anyone know a way I can get my install key back from microsoft? My HDD died and I had to reformat, this is why I am reinstalling. Thanks Brian What kind of support do you need? If I remember correctly, the product ID is all you need to install. -- Mary Sauer MS MVP http://dgl.microsoft.com/ http://mvp...

Editing Problem with Outlook 2003
I just received a new computer with Vista and am using Outlook 2003. This is my third computer and on the others I had this problem infrequently so it did not bother me but now I have it with every e-mail that I write. When I have to make a change in the text the next part of the text deletes and keeps deleting as I am typing in another letter or word or making a change. This is most annoying as I find the only way to combat this is to cut and paste and it is very time consuming. How can I fix this quirk in the program so that I can make changes without having to cut and paste? Th...

Problem with Outlook 2003 OWA
Hi, When reading my email via OWA, I have a problem when I go to Forward it, Reply, etc... The email sort of hangs on the Reply, Forward attempt. It doesn't literally hang, but it doesn't completely fill-in when I hit Reply or Forward. Can anyone help? Sorry, the problem is sort of hard to explain. Darius Try posting this in an Exchange group - despite its name, OWA is not a part of Outlook but Exchange. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal...

Ending Balance Problems
I've been having serious problems trying to have my account information show correctly in MS Money 2006. I'm doing a fresh install and create a new setup. I log onto my Bank's websites and download a history of transactions in MS Money format. After following prompts, the accounts are created and transactions imported. I cannot for the life of me get the ending balance to show correctly. In microsoft.public.money, Brian wrote: >I've been having serious problems trying to have my account information show >correctly in MS Money 2006. > >I'm doing a fresh...