VC ++ common knowledge

Source: Internet
Author: User

I. Preprocessing macros

1. General macros

In vc6.0:

Project setting à C/C ++ à Preprocessor Definitions

In vc2005:

Project property à configuration property à C/C ++ à pre-processor Definition

 

Win32: Indicates the Windows 32-bit system compiler, which is generally used for platform recognition.

_ MBCS/_ Unicode: Specifies the character set used by the Project (Multi-Byte Character Set/Unicode ).

There will be a/D "_ MBCS" or/D "_ Unicode" switch in "project setting à C/C ++ à project options" of vc6.0.

Select "use multi-Byte Character Set" or "use Unicode Character Set" in "project property configuration property standard project default value character set" in vc2005 "; select "yes" or "no" in "Project Properties configure properties to use Unicode response Files ". There will be a/D "_ MBCS" or/D "_ Unicode"/D "Unicode" switch in "Project Properties à configure properties à C/C ++ à command line.

When a file in a project has a unicode path (such as a Chinese path, the "use Unicode response file" switch should be enabled in "Project Properties à C/C ++ à regular" and "Project Properties à linker à regular.

_ Console/_ WINDOWS: Specifies the application type (console Program/Windows Window application ).

_ Debug/ndebug: Indicates the compiled version (debug/release ).

In addition, different project types of VC have some specific macros to differentiate project types in the compiler.

2. Special macros

(1) Win32 static library project

In vc6.0:

Project setting à C/C ++ (Category: General) à Preprocessor definitions: _ lib

If you select MFC support, _ WINDOWS, _ afxdll

In vc2005:

Project property à regular à configuration type à static library (. Lib)

Project attribute à C/C ++ à Preprocessor à pre-processor definition: _ lib

(2) Win32 dynamic-Link Library Project

In vc6.0:

Project setting à C/C ++ à Preprocessor definitions: _ WINDOWS, _ usrdll, DLL _Exports

In vc2005:

Project property à regular à configuration type à dynamic library (. dll)

Project attribute à C/C ++ à Preprocessor à pre-processor definition: _ windows; _ usrdll; DLL _Exports

(3) mfc dll Project

<1> regular DLL with MFC statically linked (Rule DLL with static link to MFC)

In vc6.0:

Project setting à C/C ++ à Preprocessor definitions: _ WINDOWS, _ Windll, _ usrdll

In vc2005:

Project attribute à C/C ++ à Preprocessor à pre-processor definition: _ windows; _ usrdll

<2> regular DLL using shared mfc dll (use the rule DLL that shares the mfc dll)

In vc6.0:

Project setting à C/C ++ à Preprocessor definitions: _ WINDOWS, _ Windll,_ Afxdll, _ Usrdll

In vc2005:

Project attribute à C/C ++ à Preprocessor à pre-processor definition: _ windows; _ usrdll

<3> MFC extension DLL (using shared mfc dll) (MFC extension DLL)

In vc6.0:

Project setting à C/C ++ à Preprocessor definitions: _ WINDOWS, _ Windll,_ Afxdll, _ Usrdll

In vc2005:

Project attribute à C/C ++ à Preprocessor à pre-processor definition: _ windows;_ Afxext

In the DLL project,_ UsrdllMACRO: generate export Lib!

 

For the VC compiler preprocessing macros, refer:

Predefined macros (vc6.0)

C/C ++ Preprocessor reference-predefined macros (vc8.0)

What's the difference between the Win32 and _ Win32 defines in C ++

 

Ii. working directory and console program running parameters

In vc6.0:

Enter the working directory of the EXE program in "project setting à debug à working directory.

Enter the main running parameter in "project setting à debug à program argument.

In vc2005:

Enter the working directory of the EXE program in "Project Properties à configure properties à debug à working directory.

Fill in the main running parameter in "project property configuration property debugging command parameters.

 

The default working directory is projectdir, that is, the directory where *. DSW/*. vcproj is located.

When the (CTRL + F5) application is started through the compiler, you can set the directory where the dependent lib and dll library files are located as the working directory. During application execution, files are created and saved in the working directory.

The working directory is the path obtained by getcurrentdirectory () in the current directory and changed by setcurrentdirectory.

The running directory is the path of the EXE, which can be obtained through getmodulefilename.

 

3. Additional header file inclusion

In vc6.0:

By default, the include path of vc6.0 is: Tools à options à directories à include files.

For the header file of a specific project, add the additional header file directory in "project setting à C/C ++ (Category: Preprocessor) à additional include directories". For the relative directory, refer *. DSP file.

You do not need to add double quotation marks to the directory path. The path separator is '/' or '/'. You do not need to consider escaping the backslash.CommaSeparated.

Corresponding "/I" inclusion commands will appear in "project setting à C/C ++ à project options.

In vc2005:

By default, vc2005 includes the include path: tool, option, project, solution, VC ++ directory, and file inclusion.

For the header file inclusion of a specific project, add an additional include directory in "Project Properties", "configuration properties", "C/C ++", and "Additional include directory". For details, refer *. vcproj file.

You do not need to add double quotation marks to the directory path. The path separator is '/' or '/'. You do not need to consider escaping the backslash.SemicolonSeparated.

The corresponding "Project Properties" configuration properties "," C/C ++ "command line will display"/I.

Two include methods for # include

# Include <STD *. h> specify the header file in the inclusion path for the compiler: that is, "Tools à optionà directories à include files" in vc6.0 (corresponding to "Tools à optionà project and solution à VC ++ directory à include files" in vc2005 ") directory. By default

(1) $ (vcinstalldir) include (/Microsoft Visual Studio/vc98/include)

(2) $ (vcinstalldir) atlmfc/include (/Microsoft Visual Studio/vc98/ATL/include,/Microsoft Visual Studio/vc98/mfc/include)

(3) $ (vcinstalldir) platformsdk/include (vc2005 ).

You can also add the include path here.

For the inclusion of files under the "Tools à optionà directories à include files" ("Tools à optionà project and solution à VC ++ directory à include files") directory, generally, angle brackets can be used. The system first locates the angle brackets under the inclusion path set by the compiler, And then under the additional inclusion directory.

# Include "myheader. H "in" Tools à optionà directories à include files "(" Tools à optionà project and solution à VC ++ directory à include files ") manually added header files under the inclusion pathOrAppend the header file containing the directory.

For the standard library function header files provided by the compiler ("Tools à optionà directories à include files" ("Tools à optionà project and solution à VC ++ directory à include files ")), it is generally declared to contain angle brackets. Of course, it is not wrong to include double quotation marks.

For "Tools à optionà directories à include files" ("Tools à optionà project and solution à VC ++ directory à include files ") the manually added include path and the header file under the include directory can be included with Angle brackets, but the double quotation marks are generally used.

In principle, for header files in the include directory visible to a project or file, any of the above two include methods will not cause errors, mainly because they are in different order when searching the directory. Typically, braces are used to include standard library function header files, and double quotation marks are used to include custom header files. In addition to standard sdks (such as DirectX), we recommend that you include additional header files for specific projects, try not to change the compiler's "Tools à optionà directories à include files" (corresponding to the "tool à optionà project and solution à VC ++ directory à include files" in vc2005 ") for compiler-level global configuration. The following link library contains the same processing method.

External dependencies shows the header files used by your project. They are not in your project, and are not in the default include path of VC. See: external dependencies of vc6.0.

 

4. Additional Link Library inclusion

In vc6.0:

Default lib inclusion path of vc6.0: Tools à optionà directories à library files

For header files of a specific project, you can add additional link libraries in the following two steps:

1. Add the additional library directory in "project setting à Link (Category: input) à additional library path". For the relative directory, refer to the *. DSP file.

You do not need to add double quotation marks to the directory path. The path separator is '/' or '/'. You do not need to consider escaping the backslash.CommaSeparated.

The corresponding information will be synchronized in "project setting à link à project options"./Libpath"Library contains commands.

2. add the library file name yourlib in "project setting à Link (Category: General) à object/library modules. lib (you can also use # pragma comment (Lib, "yourlib. lib ") explicitly import the dependent static library.SpaceSeparated.

The corresponding library name will be synchronized in "project setting à link à project options.

In vc2005:

Default lib inclusion path of vc2005: Tool & Option & Solution & VC ++ directory & library file

You can add an additional library directory to the library file of a specific project in either of the following ways:

1.

(1) enter the path of the additional library directory in "project properties configuration properties"> "linker"> "general". For more information about the directory, see *. vcproj.

You do not need to add double quotation marks to the directory path. The path separator is '/' or '/'. You do not need to consider escaping the backslash.SemicolonSeparated.

The corresponding commands will be synchronized to the "/libpath" library in "project properties configuration properties", "linker", "command line.

(2) Add the library file name yourlib in "project properties configuration properties"> "linker"> "add dependency. lib (you can also use # pragma comment (Lib, "yourlib. lib ") explicitly import the dependent static library.SpaceSeparated.

The corresponding library name will be synchronized at "project property configuration property", "linker", and "command line.

2.

Add the library file name yourlib. Lib in "Project Properties à configuration properties à linker à command line" (if necessary, add the relative directory to ensure the visibility of yourlib ).

 

5. Create File directory settings

In vc6.0:

Enter * in "output files" of "project setting à General à output directories *. EXE or *. LIB /*. dll Directory, the file output path will be synchronized at "project setting à Link (or library) à output file name. For the relative directory, see *. DSP file.

Enter the intermediate file generation directory in "intermediate files" of "project setting à General à output directories. For the relative directory, see *. DSP file.

In vc2005:

Fill in the output directory in "Project Properties à regular à output directory", and fill in the intermediate directory in "Project Properties à regular à intermediate directory". For the relative directory, refer to the *. vcproj file.

Enter the path of the output file in "Project Properties à linker (or administrator) à regular à output file.

Output directory (outdir) is generally $ (solutiondir) $ (configurationname)

The output file (outputfile) is usually $ (outdir)/export (projectname0000.exe (*. Lib, *. dll)

Description:

$ (Solutiondir) is the folder where the *. sln file is located, with '/' At the end '/';

$ (Projectdir) is the folder where *. vcproj files are located, with '/' At the end '/';

$ (Configurationname) is the debug and release folders in the folder where *. sln *. vcproj files are located. For more information, see <deployments> configuration items in the *. vcproj file.

Click "edit" in the drop-down menu of "Project Properties à configure properties à debug à command" to expand "macro (m)>". You can see many built-in Macros in the project.

The general configuration is:

Output directory(Outdir): $ (projectdir) $ (platformname)/$ (configurationname)

Intermediate directory(Intdir): $ (outdir)/intermediate

Output file: $ (Outdir)/$ (projectname). Lib (DLL, exe)

 

6. Relative Directories

The relative directory is relative to a specific file. For example, if you configure an include directory and an additional library directory in the VC project properties, it is relative *. DSP ,*. for the vcproj file; In *. C ,*. in the CPP file, use the # include command, which is relative to this *. C ,*. CPP file.

The current directory is visible. Generally, the file name (folder) is referenced directly. You can add "./" to subfolders "./".

...: Parent directory

../Include: The include directory under the parent directory

.../...: Grandfather directory

.../../Include: The include directory under the grandfather directory

 

VII. Dependency project Compilation

A solution (DSW and SLN) can create many auxiliary sub-projects (DSP and vcproj). How can we set the secondary project to be compiled first when compiling the main project?

Generally, the outdir of the auxiliary Sub-item is configured to be the same as the main project, so that the generated lib or DLL is directly visible to the main project exe.

In vc6.0:

Select "project à dependencies" to select the project to be associated.

In vc2005:

In Solution Explorer, right-click the project name and select the "Reference" or "project dependency" menu. You can select project dependencies and set the dependency sequence.

 

8. Additional DLL debugging

In vc6.0:

If the DLL to be debugged is dynamically loaded (loadlibrary), add the DLL file in "project setting à debug (Category: Additional DLLs.

 

9. Export makefile

In vc6.0, select "project à export makefile" to export the makefile *. Mak.

Makefile output is no longer supported after vc6.

For details, refer to "VC make File Syntax", "how to use makefile exported by vs6 ide", and "How to Write makefile under vs2005".

 

10. code editing and reading navigation

Visual Studio supports code organization, editing, analysis, and reading.

"Edit à find in files" in vc6.0 and vc2005 supports keyword searches for specified projects, projects, or files.

"Tools à source browser" in vc6.0 ", provides navigation support for "definitions and references", "file outline", "base classes and members", "Derived classes and members", "Call Graph", and "callers graph "..

Right-click vc2005 and choose "search all references" from the shortcut menu. Right-click the shortcut menu and choose "Call Browser" from the shortcut menu to view the function call diagram and called diagram. "Class View Settings" supports displaying "base type", "derived type", "inherited member", and other functions.

In addition, when reading the code, we can use bookmark to set the anchor, so that we can implement the bookmark-based custom index navigation.

The following describes the commonly used programming auxiliary plug-in software and the source code hierarchical structure analysis tool software.

1. Visual assist X is a good Microsoft Visual Studio auxiliary plug-in that supports C/C ++, C #, ASP, and visual
The basic, Java, HTML, and other languages can automatically identify various keywords, system functions, member variables, automatically prompt input, automatically correct case errors, and automatically mark errors, this helps improve the automation and development efficiency of the development process.

2. In Windows, source insight is a program editor and code navigation browser for project development. It also displays reference trees, class inheritancediagrams, and call trees. Source
Navigator can effectively solve file locating and redirection problems.

3. rational Rose is a powerful visual tool for analyzing and designing object-oriented software systems using UML (Unified Modeling Language). It can analyze project requirements, plan structures, and generate framework code, it also supports reverse engineering code transfer from the existing system to generate the rose model.

Reverse Engineer is the function of generating a model from the code of the existing system. Using Rational Rose to analyze existing code, you can understand the code structure and data structure, and generate a class hierarchy diagram, data model diagram, and component diagram.

 

11. Common vc6 shortcut keys

 

Alt + F7: Project Settings

 

CTRL + J/K: Find the previous/next pre-compilation Condition

CTRL + Shift + J/K: Find the previous/next pre-compilation condition and select this one

 

CTRL + tab: switch between the currently opened document and the last opened document.

Alt + O: interactive display of header files and CPP files

 

F12: goto Definition

Shift + F12: goto reference

 

CTRL + home: Document Header

CTRL + Shift + home: select from current position to Document Header

CTRL + end: End of the document

CTRL + Shift + end: select from the current position to the end of the document

Alt + F8: Automatic format rescheduling

CTRL + F4: Close the current document

 

CTRL + z/ALT + backspace: undo

CTRL + Shift + z/Ctrl + Y: redo

 

CTRL + B/ALT + F9: Edit breakpoint

CTRL + Shift + F9: Remove all breakpoints

 

CTRL + D: locate the toolbar to find the input Column

Alt + F3/Ctrl + F: Search for the current document

CTRL + F3: Find the next

CTRL + Shift + F3: Find the previous one

CTRL + H: replace

CTRL +]: matching brackets

 

CTRL + scroll: Scroll up

CTRL + scroll: Scroll down

CTRL + move: Move to the previous word

CTRL + →: Move to the next word

CTRL + Shift + cursor: select the current position to the previous word

CTRL + Shift + →: select the current position to the next word

 

CTRL + backspace: Delete the first half of the current word (separated by the cursor)

CTRL + DEL: Delete the last half of the current word (separated by the cursor)

CTRL + L: Cut the current row

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.