Another problem - DestroyWindow(hWnd) causes error

Started by
13 comments, last by joanusdmentia 19 years, 4 months ago
HWND is the type used by windows for window handles. It's what get's returned by CreateWindow() and is passed into DestroyWindow(). As for checking it, just set a breakpoint in your debugger and check the value of the variable in which you store the result of CreateWindow() (in VS you can just hold your mouse over the variable and it should show it's value). Also set a breakpoint just before you call DestroyWindow() and check that value that you pass in, it *should* be the same as what was returned by CreateWindow().

Post you're WinMain(), init and uninit code. It should help.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Advertisement
I think the debugger in Dev-C++ is not that useful... anyway, here is my CreateWindow call

hWnd=CreateWindowEx( dwExStyle, 	  // Die erweiterten Eigenschaften des    Fensters		szClass, // Der Name der Klasse		title, // Der Titel des Fensters		WS_CLIPSIBLINGS | // Wird von OpenGL benötigt		WS_CLIPCHILDREN | // Wird auch von OpenGL benötigt		dwStyle, // auch Eigenschaften des Fensters		0, 0, // Die Position des zu erstellenden Fensters		WindowRect.right-WindowRect.left, 		// Hier werden die ermittelten Werte für die Breite eingesetzt		WindowRect.bottom-WindowRect.top, // und hier für die Länge		NULL, // Es soll kein übergordnetes Fendster erstellt werden		NULL, // kein Menü		hInstance, // Die Instanz wird übergeben		NULL)


It is commented in German, sorry for that (now you know why my English is that bad ;) ).

And here is my de-init code:

	if (hRC) // Rendering Context (RC) vorhanden?	{		if (!wglMakeCurrent(NULL,NULL)) // Kann der DC und RC überhaupt 										// gelöscht werden?		{			MessageBox(NULL,"Entfernen des DC und RC fehlgeschlagen.","Fehler",MB_OK | MB_ICONINFORMATION);		};		if (!wglDeleteContext(hRC)) // Kann der RC gelöscht werden?		{			MessageBox(NULL,"Entfernen des RC fehlgeschlagen.","Fehler...",MB_OK | MB_ICONINFORMATION);		};		hRC=NULL; // Der RC wird NULL gesetzt, also entfernt	};	if (hDC && !ReleaseDC(hWnd,hDC)) // Kann der Device Context (DC) freigegeben werden?	{		MessageBox(NULL,"Freigabe des Device Context fehlgeschlagen.","Fehler",MB_OK | MB_ICONINFORMATION);		hDC=NULL; // Der DC wird entfernt	};	// ***** Here the program crashes as DestroyWindow is called ******	if (hWnd && !DestroyWindow(hWnd))	// Kann das Programmfenster geschlossen werden?	{		MessageBox(NULL,"Konnte hWnd nicht löschen.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);		hWnd=NULL; // Setze den hWnd auf NULL	};	if (!UnregisterClass(szClass,hInstance)) // Kann die Registrierung rückgängig gemacht werden?	{		MessageBox(NULL,"Konnte Klasse nicht entfernen.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);		hInstance=NULL; // Setze hInstance auf NULL	};[...]


Thanks for you patience so far.
Heureka, I got it! I have been so stupid I can not believe... After deinitialising the Window I have made a MessageBox-call to check if everything has been shut down correctly, and in that call I passed hWnd as first parameter, as the parent window. But of course the window was already destroyed and so this little MessageBox crashed the program.

So I am very sorry for wasting your time, but during the checking for memory lecks I have found some of them in some of my classes, so the whole thing also has its positive effect.

Again, thanks for you patience =)
I can't see anything wrong in the code you pasted... Anyway, you can use the GetLastError() and FormatMessage() functions to know why it is failing.
LPVOID lpMsgBuf;FormatMessage(     FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,    NULL,    GetLastError(),    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language    (LPTSTR) &lpMsgBuf,    0,    NULL );// Display the string.MessageBox( NULL, lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );// Free the buffer.LocalFree( lpMsgBuf );
theNestruoSyntax error in 2410Ok
Quote:Original post by Marco H
Heureka, I got it! I have been so stupid I can not believe... After deinitialising the Window I have made a MessageBox-call to check if everything has been shut down correctly, and in that call I passed hWnd as first parameter, as the parent window. But of course the window was already destroyed and so this little MessageBox crashed the program.

So I am very sorry for wasting your time, but during the checking for memory lecks I have found some of them in some of my classes, so the whole thing also has its positive effect.

Again, thanks for you patience =)

LOL! No worries [smile]
As a side note, you're english is a lot better than some native speakers of the language that I know....

Quote:Original post by theNestruo
Anyway, you can use the GetLastError() and FormatMessage() functions to know why it is failing.

Good suggestion in general, but the program was crashing so it wouldn't help in this case.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

This topic is closed to new replies.

Advertisement