Visual C + + development experience and debugging skills

Source: Internet
Author: User

Their usual collection of some skills and experience, here to share, to popularize knowledge.

  

1. How to debug in release state
project->setting=>projectsetting dialog box, select the release status. The category Selection general,optimizations disable (Debug), debut info Select program Database. Select the Generate Debug Info check box in the Link tab.

Note: Just a debug and release in the middle of the state, all the Assert, verify do not work, the function call mode is a real call, but not the table, but this state QuickWatch, call queue tracking function is still valid, and the same as the debug version.

2. What is the difference between release and debug?
Release version is called the release version, the debug version is called the Debug version.
Debug can be single-step execution, tracking and other functions, but the resulting executable file is larger, the code runs slower. The release version runs faster and has smaller executables, but cannot perform debugging functions under its compilation conditions.

The exe file for release is linked to the standard MFC DLL (use MFC in a shared or static DLL). These DLLs are configured when Windows is installed, so these programs can run on a machine that does not have Visual C + + 6.0 installed. The debug version of EXE links the debug version of the MFC DLL file, and cannot be run on a machine that does not have visual c++6.0 installed because the corresponding DLL is missing, unless the use static DLL is selected when link.

3. What is the difference between assert and verify?
The content in the assert is not compiled in release version, the content inside the verify is still translated, but no longer judged true or false. So the latter is a little more secure.
For example, assert (file. Open (strFileName)).

Once in the release version, this line is ignored, file is not open (), and there is no error message. If you use verify () There will be no problem.

What is the relationship between 4.Workspace and project

Each workspace can include several project, but only one is in the active state, and each project can have a dependency between project setting. Can be set in, for example, the active state of project can depend on other static libraries that provide their function calls.

5. How to use ClassWizard in non-MFC programs

Create a new empty in the project directory. RC file, and then add it to the project.

6. How to set breakpoints
Press F9 to add a breakpoint at the current cursor and cancel a breakpoint.

In addition, in the edit state, press Ctrl+b to pop up the breakpoint Settings dialog box. Then click the "Condition ..." button to set the dialog box to set the breakpoint condition.

7. A member variable or function cannot be displayed in edit state how to open the display function
This appears to be a bug in this version of Visual C + + 6.0, which can be made normal as follows:
(1) Close Project
(2) Delete the "project name. NCB" file

(3) Re-opening the project

8. How to completely remove a class generated by ClassWizard

First select the class's. h and. cpp files in the FileView of the workspace, press DELETE to delete, and then delete the two files in the File Manager, then run ClassWizard, if you want to remove the class prompt, select Remove.

9. How to find a class that disappears in workspace

Open the corresponding header file of the class, and then change its class name to a random, this time the workspace will appear new classes, and then change the class back to the original name.

10. How to clear all breakpoints

Menu "Edit", "Breakpoints ...", open the Breakpoints dialog box, click the "Remove All" button. The shortcut key is "Ctrl + Shift + F9".

11. How to select unlisted information in ClassWizard

Open the ClassWizard dialog box, and then switch to the Class Info page. Change the message filter, such as Select window, and the "message" page will show the window information.

12. How to detect if the parentheses in the program match

Move the cursor in front of the parentheses you want to detect, and press the shortcut key "Ctrl +". If the parentheses match correctly, the cursor jumps to the matching brackets, or the cursor does not move, and the chassis horn emits a warning.

13. How to view the definition of a macro (or variable, function)

Move the cursor to a macro you want to see, such as the most common declare_map_message click on the F12 (or the context menu in the context menu), if you do not create a browse file, the prompt dialog will appear, press the "OK" button, and then jump to the macro (or variable, function) Define the place.

14. How to add Lib files to the current project

Click the menu "Project", "Settings ..." to bring up the project Setting dialog, switch to the "Link" tab, enter the Lib file name at "object/library modules", Between the different Lib with the open space.

15. How to quickly delete temporary files in the Debug folder under Project

Select the corresponding item in the FileView view of the workspace, right-click the popup menu, and choose the "clean (selection only)" menu.

16. How to quickly generate an existing project in addition to the project name is identical to the new project
In the new project's "New" dialog box, select the "Custom Appwizard" entry, enter the name of the new project, and click the "OK" button. The "Custom AppWizard" entry appears, enter the name of the new project, and click the "OK" button. When the "Custom Appwizard-step 1 of 2" dialog box appears, select the "an existing project" Item and click the "Next" button. The Custom appwizard-step 2 of 2 dialog box appears, select the project file name for the existing project, and then click the Finish button. After compiling, a project AppWizard that is the same as the existing project but can be re-named is generated.

Now you can use this custom Wizard as an MFC AppWizard. If you do not want to use it, you can delete the. awx and. pdb files for the wizard in the Common\msdev98\template directory under the Visual C + + 6.0 installation directory.

17. How to troubleshoot Visual C + + 6.0 incorrect connection
Situation: Obviously changed a file, but the whole project to recompile the link once. Just link, a run, and prompted to recompile the link once.

This is due to the presence of future files (modification and creation times are later than system time). You can do this: find the debug directory under the project folder, delete both the creation and modification times than the system time file, and then the new "Rebuild all" once.

18. What are the common errors that cause LNK2001?
The main LNK2001 errors encountered are: unresolved external symbol "symbol"
This error message is generated if the linker cannot find the referenced function, variable, or label in all libraries and destination files.
In general, there are two reasons for an error: One is the referenced function, the variable does not exist, is spelled incorrectly, or an error is used, and a different version of the link library may be used next. The following are the possible causes of LNK2001 errors:
<1> LNK2001 errors due to coding errors
(1) does not match the program code or module definition (. DEF) file causes LNK2001. For example, if a variable "var1" is declared within a C + + source file, it attempts to access the change in the variable "var1" within another file.
(2) If the inline function that is used is defined within a. cpp file, instead of being defined within the header file, the LNK2001 error will result.
(3) A LNK2001 error is generated when calling a function that does not match the type of the parameter used and when the header function is declared.
(4) Attempting to invoke a virtual function from a constructor or destructor of a base class will result in a LNK2001 error.
(5) To pay attention to the common function and variables, only the global variables, functions are common. static functions and static variables have the same usage scope restrictions. Any static variables that are not declared inside the file will result in a compilation error or a LNK2001 error when attempting to position from outside the file.
<2> LNK2001 Errors due to compilation and online Setup
(1) If the/nod (/noderaultlib) option is used at compile time, the runtime and MFC required by the program will get the compiler to write to the target file module, but these libraries will not be linked into the project file unless they are explicitly included in the file. Using/nod in this case will result in a LNK2001 error
(2) If the program entry is not set for wWinMainCRTStartup, the LNK2001 error message "unresolved external on [email protected]" will appear when using Unicode and MFC.
(3) When compiling with the/MD option, since all runtimes are kept within the dynamic link library, references to "Func" in the source file are referred to as "__imp__func" in the target file. If you attempt to link using a static library LIBC.LIB or LIBCMT.LIB, a LNK2001 error will occur on the __imp__func. If you do not compile with the/MD option, a LNK2001 error occurs when you use the MSVCxx.LIB link.
(4) When compiling with the/ML option, a LNK2001 error occurs on _errno if the LIBCMT.LIB link is used.
(5) When compiling the debug version of the application, if the release version of the modal library to link also generates LNK2001 errors, as well, the use of the debug version of the modal library linked to the release of the application will also produce the same error.
(6) Mixed use of different versions of libraries and compilers can also cause problems, as the new version of the library may contain symbols and descriptions that were not available in previous versions.
(7) Using inline and non-inline compilation options in different modules can cause LNK2001 errors. If you open a function inline (/ob1 or/OB2) when you create a C + + library, but you close the function inline (without the inline keyword) in the corresponding header file that describes the function, you just get an error message. To avoid this problem, you should use the inline keyword flag in the corresponding header file as an inline function.

(8) Incorrect/subsystem or entry settings can also cause LNK2001 errors.

19. How to debug a DLL called by an EXE file without source code

In Visual C + + 6.0, go to the Project Setting dialog box and select the Debug tab page. Usually Visual Studio default "executable for debug session" is the executable file name, but you can change him to any program you want. You can even specify a different working directory and pass parameters to your program. This technique is commonly used to debug DLLs, namespace extensions, COM objects, and other plug-in programs that are called from some EXE and from a third party's EXE.

What are the project files in the Visual C + + 6.0 project?
. OPT: An engineering parameter file on the development environment. Information such as the location of the tool bar.
. APS (AppStudio file) resource auxiliary files, in binary format, are generally not necessary to control it. The
. Clw:classwizard information file, which is actually an INI file format, is interesting to look at. Sometimes ClassWizard out a problem, manual modification CLW file can be solved. If this file does not exist, you should always use ClassWizard to prompt for rebuilding.
. DSP (Developstudio Project): Project file, text format, but not familiar with manual modification.
. DSW (Developstudio Workspace): is a workspace file, other features are similar to. dsp.
. PLG: is a compile information file, compile-time error and warning information file (actually an HTML file), generally not very useful. There is an option to control the generation of this file in the dialog box that pops up by clicking Menu Tool, option.
. HPJ (Help Project): is a project that generates a helper file, which can be processed with Microsoft Assistance compiler.
. MDP (Microsoft DevStudio Project): is an older version of the project file, and if you want to open the file, you will be prompted whether to convert to a new. DSP format.
. BSC: is used for browsing project information and must have this file if it is brower with source. If you don't use this feature, you can remove the Generate Browse Info File from the project options, which speeds up the compilation.
. Map is the image information log file that executes the file, and this file is generally unnecessary unless it is on the bottom of the system.
. PCH (pre-compiled file): Is and compiles the file, can speed up the compilation speed, but the file is very large.
. PDB: Records some of the program's data and debugging information, which may be useful when debugging.
. Exp: It is only generated when compiling DLLs, and some information about DLL files is not normally used.
. NCB: No compile browse file (no compile browser). You can delete this file when the AutoComplete feature is faulty. It is automatically generated when the project is compiled.

Visual C + + development experience and debugging techniques

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.