Dev C++ Does Not Response

Posted By admin On 12.12.20
Dev C++ Does Not Response Rating: 8,0/10 2274 reviews

WxDev-C is an extension of Dev-C by Colin Laplace et. This program helps you to create dialogs and frames for wxWidgets visually using a form designer. With all the wonderful features of Dev-C, wxDev-C is still being actively developed.

-->

This note describes the use of the CWnd::PostNcDestroy method. Use this method if you want to do customized allocation of CWnd-derived objects. This note also explains why you should use CWnd::DestroyWindow to destroy a C++ Windows object instead of the delete operator.

If you follow the guidelines in this topic, you will have few cleanup problems. These problems can result from issues such as forgetting to delete/free C++ memory, forgetting to free system resources like HWNDs, or freeing objects too many times.

Note that Insight was not originally designed to work with Dev-C and may be a bit flaky under certain situations. If you are having too much trouble with Insight and are feeling adventurous, you can reinstall Dev-C and use the console-mode GDB debugger that comes with the program. For more Dev-C Tutorial for CSC 161 Students Page 4 of 7. The first step to getting the Dev C to work is to setup the compiler environment; this must be working before any work to setup Dev C can be done. This is not included here, but the basic steps are as follows: 1. Download a suitable distribution for your target processor 2. Hey guys, I'm trying to make a program that checks a specific internet address and gives me back the HTTP Status Code, I have to do it in C because it's a school project. I'm using the Cygwin compiler on a Windows 7 (64-bit version).

The Problem

Each windows object (object of a class derived from CWnd) represents both a C++ object and an HWND. C++ objects are allocated in the application's heap and HWNDs are allocated in system resources by the window manager. Because there are several ways to destroy a window object, we must provide a set of rules that prevent system resource or memory leaks. These rules must also prevent objects and Windows handles from being destroyed more than one time.

Destroying Windows

The following are the two permitted ways to destroy a Windows object:

  • Calling CWnd::DestroyWindow or the Windows API DestroyWindow.

  • Explicitly deleting with the delete operator.

The first case is by far the most common. This case applies even if your code does not call DestroyWindow directly. When the user directly closes a frame window, this action generates the WM_CLOSE message, and the default response to this message is to call DestroyWindow. When a parent window is destroyed, Windows calls DestroyWindow for all its children.

The second case, the use of the delete operator on Windows objects, should be rare. The following are some cases where using delete 3utools mac os x. is the correct choice.

Auto Cleanup with CWnd::PostNcDestroy

When the system destroys a Windows window, the last Windows message sent to the window is WM_NCDESTROY. The default CWnd handler for that message is CWnd::OnNcDestroy. OnNcDestroy will detach the HWND from the C++ object and call the virtual function PostNcDestroy. Some classes override this function to delete the C++ object.

The default implementation of CWnd::PostNcDestroy does nothing, which is appropriate for window objects that are allocated on the stack frame or embedded in other objects. This is not appropriate for window objects that are designed to be allocated on the heap without any other objects. In other words, it is not appropriate for window objects that are not embedded in other C++ objects.

Those classes that are designed to be allocated alone on the heap override the PostNcDestroy method to perform a delete this. This statement will free any memory associated with the C++ object. Even though the default CWnd destructor calls DestroyWindow if m_hWnd is non-NULL, this does not lead to infinite recursion because the handle will be detached and NULL during the cleanup phase.

Note

The system usually calls CWnd::PostNcDestroy after it processes the Windows WM_NCDESTROY message and the HWND and the C++ window object are no longer connected. The system will also call CWnd::PostNcDestroy in the implementation of most CWnd::Create calls if failure occurs. The auto cleanup rules are described later in this topic.

Auto Cleanup Classes

The following classes are not designed for auto-cleanup. They are typically embedded in other C++ objects or on the stack:

  • All standard Windows controls (CStatic, CEdit, CListBox, and so on).

  • Any child windows derived directly from CWnd (for example, custom controls).

  • Splitter windows (CSplitterWnd).

  • Default control bars (classes derived from CControlBar, see Technical Note 31 for enabling auto-delete for control bar objects).

  • Dialogs (CDialog) designed for modal dialogs on the stack frame.

  • All the standard dialogs except CFindReplaceDialog.

  • The default dialogs created by ClassWizard.

The following classes are designed for auto-cleanup. They are typically allocated by themselves on the heap:

  • Main frame windows (derived directly or indirectly from CFrameWnd).

  • View windows (derived directly or indirectly from CView).

If you want to break these rules, you must override the PostNcDestroy method in your derived class. To add auto-cleanup to your class, call your base class and then do a delete this. To remove auto-cleanup from your class, call CWnd::PostNcDestroy directly instead of the PostNcDestroy method of your direct base class.

The most common use of changing auto cleanup behavior is to create a modeless dialog that can be allocated on the heap.

When to Call delete

We recommend that you call DestroyWindow to destroy a Windows object, either the C++ method or the global DestroyWindow API.

Do not call the global DestroyWindow API to destroy a MDI Child window. You should use the virtual method CWnd::DestroyWindow instead.

For C++ Window objects that do not perform auto-cleanup, using the delete operator can cause a memory leak when you try to call DestroyWindow in the CWnd::~CWnd destructor if the VTBL does not point to the correctly derived class. This occurs because the system cannot find the appropriate destroy method to call. Using DestroyWindow instead of delete avoids these problems. Because this can be a subtle error, compiling in debug mode will generate the following warning if you are at risk.

In the case of C++ Windows objects that do perform auto-cleanup, you must call DestroyWindow. If you use the delete operator directly, the MFC diagnostic memory allocator will notify you that you are freeing memory two times. The two occurrences are your first explicit call and the indirect call to delete this in the auto-cleanup implementation of PostNcDestroy.

After calling DestroyWindow on a non-auto-cleanup object, the C++ object will still be around, but m_hWnd will be NULL. After calling DestroyWindow on an auto-cleanup object, the C++ object will be gone, freed by the C++ delete operator in the auto-cleanup implementation of PostNcDestroy.

See also

Technical Notes by Number
Technical Notes by Category

How to Install Dev-C++ and the GLUT Libraries
for Compiling OpenGL Programs with ANSI C

(version of July 16, 2009)

These notes explain how to compile programs written in ANSI C with OpenGL and GLUT using the Dev-C++ compiler.

Bloodshed Dev-C++ is a free C++ compiler and development environment for Windows operating systems. Like most C++ compilers, it also can be used to compile ANSI C. By installing the GLUT header and library files, it can be used to write programs that use OpenGL. This is needed to run programs for Edward Angel's textbook, Interactive Computer Graphics 5th edition and possibly other computer graphics texts.

These notes do not explain how to compile OpenGL with C++ . The 6th edition of Angel's book uses C++ which will not work with these notes.

These instructions have been tested on a small variety of Windows 2000 and Windows XP systems. These systems come with the files needed for OpenGL, but not the files needed for GLUT.

Dev-C++ does not work well with Microsoft's Vista. The problem, and a possible fix, is discussed here: http://aresio.blogspot.com/2007/06/vista-and-dev-cpp.html but I have not tested this information.

I. Download Dev-C++ from http://www.bloodshed.net/dev/devcpp.html and install it.

Details:

Get Dev-C++ 5.0 beta 9.2 (4.9.9.2) (9.0 MB) with Mingw/GCC 3.4.2 Although this is a 'beta' version, it works perfectly fine. Click on SourceForge to go to a list of download sites and pick one. The file will be something like devcpp4.9.9.2_setup.exe. Save this file in a place like C:Temp.

When the download is complete, click on the 'open' button to start the installation process. (Or go to C:Temp andDouble click on devcpp4.9.9.2_setup.exe). You will see a few screens that ask you to pick a language (English) and to agree to the license terms. Choose a 'typical' installation.

Accept the suggested destination for the installation:

Many subdirectories and files are extracted to the destintion:

Answer 'yes' when it asks if you wish to install Dev-cpp for all users. Note: if the installation fails, re-install and try 'no' for this.

A screen says the installation is complete:

Keep the check mark in the box. Click on 'Finish'. A first-time configuration screen appears:

Pick 'English' and 'New Look'. In the next several screens, hit 'Yes' for its suggestions.

Eventually you are done. Click 'OK'.

II. DEV-C++ starts up. Try out the installation with a simple C program.

Details:

The program starts up automatically.

Click File/New/Project. Pick a name for the project (such as 'myProject'). Click 'C Project'. Click on 'Empty Project'. Click 'OK'.

In 'Create New Project', click 'save' (later on you will probably want to create separate subdirectories for your various projects.).

Click 'File/New/Source File' and in 'Add source file to current project' click 'Yes'. You now get a screen where you can edit the source file.

Type in a simple C program, as below. Now click 'File/Save As' and save the file as 'hello.c' (or other name.) Important: be sure that the file extension is .c. With any other extension (such as the suggested .cpp) you will have problems compiling.

Now click 'Execute/Compile and Run'

The program will (hopefully) compile, run, and write its output to a DOS window. If you have the system('pause') statement in your program, the output will stay in the window until you hit a key. Another way to run the program (after it has been compiled) is to start a DOS window outside of the Dev-Cpp system, then navigate to the subdirectory that holds your project, and type hello.exe.

At this point, the compiler and development environment has been installed. You should find Dev-C++ listed under 'Programs' on the 'Start' menu and will now be able to write, compile, and run C (and C++) programs. You will have include files, libraries, and dll's for OpenGL (and all other standard packages) but not GLUT. GLUT manages the windows and other user interface components needed for OpenGL programming, and needs to be separately installed.

If you do not need GLUT , you can quit now.

III. Download and install GLUT

To run OpenGL with GLUT (which is what the programs in Angel's book use), you need to get three files and place each file in its proper directory. All the files you need (and more) are contained in one zip file.

Details:

Download GLUT files from http://chortle.ccsu.edu/Bloodshed/glutming.zip Download the file glutming.zip Save the zip file in some convenient location (perhaps C:temp).

Double click on glutming.zip (or otherwise unzip it). You will see the files that are in the zip archive. (Your un-zipping program will probably be diferent than the one shown here, but should work about the same.)

Click on 'Extract' to extract all the subdirectories and files. Pick some convenient directory to extract them to (perhaps C:tempglutming). You only need three files, but extract all of them anyway.

Only three of the files in the various subdirectories are needed. Each of the three files should be put in a subdirectory with other files of its type. Use Explorer to move the files to where they are needed.

Auto tune the news run n tell that. Note: If you only see some of these files listed in Explorer, click on 'View/Options/View' and then select the radio button 'Show all Files'.

glut.h -- copy this file to C:Dev-CppincludeGL

Copy from your 'unzipped' subdirectories (wherever they are):

To here:

Dev C++ Does Not Response Mean

libglut32.a -- copy this file from your unzipped directories to C:Dev-Cpplib

There may be a newer version of this file there, already. Replace that version with the one you unzipped (if you keep the newer version your programs will not link correctly.)

Copy from your 'unzipped' subdirectories:

To here:

glut32.dll -- move this file to C:WINNTSystem32, or similar location.

The location for this file depends on your operating system. The directory where it goes is the directory that holds the dynamic load libraries (*.dll). An easy way to find where it should go is to look for glu32.dll (use 'Search' from the start menu).

The directory to use should also have the files glu32.dll and opengl32.dll. These should have come with your operating system.

IV. Test Dev-cpp with GLUT

The essential step in compiling and running a C program that contains OpenGL and GLUT functions is to tell the linker where the libraries are. This is done by clicking Project/Project Options/Parameters/Add Library or Options and then navigating to the libraries you need to include: libopengl32.a, libglu32.a, and libglut32.a. The libraries should be added in that order.

Details:

a. Create a subdirectory for a project. Do this first, before you start Dev-Cpp. Create a new subdirectory with 'Explorer' by clicking 'File/New/Folder'.

For example, create a folder C:GLproject.

b. Start Dev-cpp:

c. Start a new project by clicking File/New/Project. In the panel that pops up, name the project something like 'rectangle', click on 'empty project' and 'C': Click OK.

Note: For compiling with OpenGL you must create a project. You need to have a project (not just a single C file) in order to link in the OpenGL libraries.

d. In the next panel, navigate to your folder C:GLproject, and click 'Save'.

e. In Dev-C++, click 'File/New/Source File' and then in the next panel 'Add to Project' click 'yes'. Click 'File/Save As' and then give the file a name. Navigate to your project subdirectory to save the file in it. Name the file something like 'rectangle.c'

Be sure that the file names ends with '.c' anything else will cause big problems.

f. Click and drag your mouse over the following program so that it is highlighted, then click 'Edit/Copy' from the browser's menu bar.

g. Now click in the editing window of Dev-cpp and then click 'Edit/Paste' in its menu bar. The program will appear in the editing window.

Dev C Does Not Response Video

h. Click 'File/Save'. The file in your project directory should now contain an OpenGL program.

i. Tell Dev-cpp what libraries need to be linked. Click 'Project/Project Options'.

j. Now click 'Parameters'. Click the 'Add Library or Object' button and navigate to the libraries that should be added, found under C:Dev-cpplib

  • ./lib/libopengl32.a
  • ./lib/libglu32.a
  • ./lib/libglut32.a

Add them in that order (only). Notice that the slashes will appear in Unix style '/' rather than DOS-style '.

When you are done adding the three libaries, you should see:

Dev C++ Does Not Response Test

The exact pattern of '././.' you see depends on how deep in the directory structure your source file lies.

Click 'OK'.

k. Click 'Execute/Compile and Run'. The program should compile, link, and run:

If things don't work (very common) click on the 'Compile Log' tab for some confusing error messages. If you see something like the following, it means that you made a mistake in adding the libraries to the project:

Dev C++ Does Not Response Work

Try to fix the list of libraries, or perhaps start over from scratch.

You now are finished, or have given up.