C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-15-2002, 09:34 PM   #1
Registered User
 
Bajanine's Avatar
 
Join Date: Dec 2001
Location: The most peaks over 10,000 feet!
Posts: 388
Debug assertion failed

This program example from my Nitty Gritty book compiles without errors or warnings but when you click on the SYSTEM_FONT button I get this error:

Debug Assertion Failed!
Line 47
Expression _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
For info see asserts.



So I looked up asserts in one of my C++ books and it says:
" A macro that stringizes and displays as an error message the expression passed in as a parameter if that expression evaluates to false."

I did a search on this site and got 9 hits including this link that seems closely related but doesn't seem to help me:

Ask about Debug Assert Failed

Seeing line 47 in the error made me double check it but according to my book this is correct. So somewhere I must be 'passing in a false condition' but I do

not see an error.




Please shed some light on this for me!



Code:
#include <windows.h>

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

HINSTANCE hInstGlobal;
HWND hEdit;

int APIENTRY WinMain(HINSTANCE hInstance,
			  HINSTANCE hPrevInstance,
			  LPSTR lpCmdLine,
			  int nCmdShow)			// nShowCmd???
{
	hInstGlobal = hInstance;

	WNDCLASS WndClass;
	WndClass.style = 0;
	WndClass.cbClsExtra = 0;
	WndClass.cbWndExtra = 0;
	WndClass.lpfnWndProc = WndProc;
	WndClass.hInstance = hInstance;
	WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
	WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
	WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
	WndClass.lpszMenuName = 0;
	WndClass.lpszClassName = "WinProg";

	RegisterClass(&WndClass);

	HWND hWindow;
	hWindow = CreateWindow("WinProg", "Edit Field",
		WS_OVERLAPPED,
		0,0,640,400,NULL,NULL,
		hInstance, NULL);

	ShowWindow (hWindow, nCmdShow);

	UpdateWindow (hWindow);

	MSG Message;
	while (GetMessage(&Message, NULL, 0, 0))
	{
		DispatchMessage(&Message);
	}

	return (Message.wParam);
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)
{
	switch(uiMessage)
	{
	case WM_CREATE:
		HWND hButton, hButtonExit; 
		hButton = CreateWindow("BUTTON","SYSTEM_FONT",
			WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON,		// BS_PUSHBUTTON returns BN_CLICKED			
			10,320,140,20,
			hWnd, (HMENU) 1,

			hInstGlobal, NULL);
		hButtonExit = CreateWindow("BUTTON","EXIT",
			WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON,
			160,320,140,20,
			hWnd, (HMENU) 2,
			hInstGlobal, NULL);
		hEdit = CreateWindow("EDIT","SYSTEM_FONT",
			WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
			10,340,120,20,
			hWnd, (HMENU) 1,
			hInstGlobal, NULL);
		return 0;

	case WM_COMMAND:
	if(HIWORD(wParam) == BN_CLICKED)		// BN = Button Notification.  BS_PUSHBUTTON returns BN_CLICKED
		{
			if(LOWORD(wParam) == 1)
			{
				HDC hdc;
				hdc = GetDC (GetParent((HWND) lParam));
				HFONT hFont;
				hFont = (HFONT) GetStockObject(SYSTEM_FONT);
				
				char *string1;
				string1 = new char[255];
				SendMessage (hEdit, WM_GETTEXT, 256,(LPARAM) string1);
				bool FontDa;
				FontDa =0;
				if (lstrcmp (string1,"SYSTEM_FONT") == 0)
				{
					hFont = (HFONT) GetStockObject(SYSTEM_FONT);
					FontDa = 1;
				}
				if (lstrcmp (string1,"SYSTEM_FIXED_FONT") == 0)
				{
					hFont = (HFONT) GetStockObject(SYSTEM_FIXED_FONT);
					FontDa = 1;
				}
				if (lstrcmp (string1,"OEM_FIXED_FONT") == 0)
				{
					hFont = (HFONT) GetStockObject(OEM_FIXED_FONT);
					FontDa = 1;
				}
				if (lstrcmp (string1,"ANSI_VAR_FONT") == 0)
				{
					hFont = (HFONT) GetStockObject(ANSI_VAR_FONT);
					FontDa = 1;
				}
				if (lstrcmp (string1,"ANSI_FIXED_FONT") == 0)
				{
					hFont = (HFONT) GetStockObject(ANSI_FIXED_FONT);
					FontDa = 1;
				}
				if (lstrcmp (string1,"DEFAULT_GUI_FONT") == 0)
				{
					hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
					FontDa = 1;
				}
				if (FontDa == 0)
				{
					hFont = (HFONT) GetStockObject(SYSTEM_FONT);
					lstrcpy (string1, "SYSTEM_FONT");
				}
				SelectObject (hdc, hFont);
				RECT rect;
				SetRect (&rect, 0,0,480,280);
				HBRUSH hBrush;
				hBrush = CreateSolidBrush(RGB(255,255,255));
				FillRect (hdc, &rect, hBrush);
				TextOut (hdc, 340,10,string1, lstrlen(string1));
				delete [] string1;
				TEXTMETRIC tm;
				GetTextMetrics (hdc, &tm);
				int i;
				int ix,iy;
				ix = 0;
				iy = 0;
				char *string;
				string = new char[2];
				string[1] = 0;
				for(i=0;i<=255;i++)
				{
					string[0] = i;
					TextOut (hdc, ix, iy, string, lstrlen(string));
					iy = iy + tm.tmHeight;
					if ((iy/tm.tmHeight)==16)
					{
						iy = 0;
						ix = ix + 20;
					}
				}


				ReleaseDC (GetParent((HWND) lParam), hdc);
				delete [] string1;
			}
			if (LOWORD(wParam) == 2)
			{
				SendMessage (GetParent((HWND) lParam),	// hWnd is the handle of a window object to which the message is sent.
					WM_DESTROY ,0 ,0);					// Msg is the value which identifies the message.
			}											// wParam is the first parameter of the 

message.
		}												// lParam is the second parameter of the 

message.
		return 0;

	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	default:
	
		return DefWindowProc (hWnd, uiMessage, wParam, lParam);
	}
}
Compiling...
Edit Field.cpp
Linking...

Edit Field.exe - 0 error(s), 0 warning(s)

/code
Bajanine is offline   Reply With Quote
Old 10-15-2002, 11:49 PM   #2
Registered User
 
Join Date: Apr 2002
Posts: 1,571
Worked fine on my computer. Windows 2000 Professional.
MrWizard is offline   Reply With Quote
Old 10-16-2002, 05:11 PM   #3
Registered User
 
Bajanine's Avatar
 
Join Date: Dec 2001
Location: The most peaks over 10,000 feet!
Posts: 388
XP Problem then?

I'm running Win XP Pro with MS VC++ 6.0.

I suppose this could be a XP problem? When I get back home I could load Visual Studio on my desktop(Win2k Pro and Win 98) and see how it runs there.

Thanks for trying this on your system MrWizard.
Bajanine is offline   Reply With Quote
Old 10-16-2002, 06:57 PM   #4
Troll Hunter
 
xds4lx's Avatar
 
Join Date: Nov 2001
Posts: 619
I compiled it in MSVC6 and .NET and ran it under XP pro and it ran fine.
xds4lx is offline   Reply With Quote
Old 10-17-2002, 04:34 PM   #5
Registered User
 
Bajanine's Avatar
 
Join Date: Dec 2001
Location: The most peaks over 10,000 feet!
Posts: 388
Talking I found a work around.

I just ran it under compatibility mode for Win2k and it works great I'll have to remember this for future reference.
Bajanine is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Debug Assertion Failed! IndioDoido C Programming 31 03-25-2008 11:07 AM
debug assertion failed! chintugavali C++ Programming 5 12-21-2007 04:05 AM
Visual Studio 2005 Debug Assertion Failed natmas C++ Programming 7 07-17-2007 04:28 PM
debug assertion failed ! blue_gene C++ Programming 2 05-09-2004 11:23 AM
debug assertion failed?!? ichijoji C++ Programming 3 08-30-2003 03:23 PM


All times are GMT -6. The time now is 06:58 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22