C++ Error - _ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse))
C++ Error - _ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse))
Author
Discussion

bholleran

Original Poster:

361 posts

244 months

Tuesday 31st July 2007
quotequote all
Help,

I am really strugling to get this working and I need to get it sorted asap.

I am using VS6, I am trying to get the CHtmlView to work, I have tried it in all sorts of ways and keey running into the same problem.

If I create a new MFC App wizard exe, and select SDI as the type and untick the doc view support. If I make no changes to it and run the application I get a SDI window OK, if i exit the application it exits without error. Great.

If I now add #include <afxhtml.h> into the stdafx.h, and change the following lines in the ChildView.h

class CChildView : public CWnd to class CChildView : public CHtmlView


and in the ChildView.cpp I change the following.

BEGIN_MESSAGE_MAP(CChildView,CWnd ) to BEGIN_MESSAGE_MAP(CChildView,CHtmlView )

and in the PreCreateWindow

if (!CWnd::PreCreateWindow(cs)) to if (!CHtmlView::PreCreateWindow(cs))

It all compiles and links ok. When I run the new version it opens up ok, but I keep getting an assertion, which in release mode then crashes the application.


I thought that the CChildView class was just a view anf I should be able to replace it with any CWnd derived view. i.e. CHtmlView

I have just tried and it also fails on just CView.


Any help would be appreciated.


Regards

Barry


boony

382 posts

268 months

Wednesday 1st August 2007
quotequote all
Out of interest, why are you unticking the doc/view support?

If you leave that ticked, at step 6 of the MFC app wizard, you can select CHTMLView as the base class and you end up with a working app out of the box. Is that any use?

bholleran

Original Poster:

361 posts

244 months

Wednesday 1st August 2007
quotequote all
boony said:
Out of interest, why are you unticking the doc/view support?

If you leave that ticked, at step 6 of the MFC app wizard, you can select CHTMLView as the base class and you end up with a working app out of the box. Is that any use?
Thanks for the response, but no it does not help. This is not really the problem I am having, I have an existing project which has been written without the doc support and I am trying to add the HtmlView to this HUGE project. It would not be practical to rewite the whole project. The example I gave does simulate the problem, with a very short amount of code.

To be fair, I have now fixed the problem after being up very late last night and a LOT of google searches.

On the CHtmlView class you need to add the virtual function called PostNcDestroy. This will give you a basic shell function like this.

void CReportListView::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class

CView::PostNcDestroy();
}

it still does not work at this point.

but if you comment out the CView::PostNcDestroy(); it fixes the problem. smile

I dont understand why or what other implications doing this might have but at least for the moment it lets me move on.

But thanks for the suggestion. Maybe someone else will have this problem in future and find this helpful.

JonRB

80,236 posts

303 months

Wednesday 1st August 2007
quotequote all
Last time I saw this runtime error was with accidentally calling into a DEBUG dll from a release exe, but I guess that's not really applicable here. smile

Edited by JonRB on Wednesday 1st August 10:39

dilbert

7,741 posts

262 months

Thursday 2nd August 2007
quotequote all
Somehow you are deleting the view from the heap twice.
That's specifically what that assetion means.
PostNCDestroy is normally tasked with that function, where a C++ window class is created on the heap. WM_NCDESTROY being the last message that any window receives.

Don't know why it doesn't work for CView, but I'm guessing that you've adjusted the usual ownership hierachy of windows. If you've ditched document view support then it's probably not working properly because you're not using CDocTemplate.

HTMLView just creates an instance of an OLE HTML server window, and you might be better off using OLE manually and getting a CView from an HWND at run time. At least then you'll know whats going on.

Personally I try to avoid MFC!!!