Take you to play with Visual Studio

Take you to play with Visual Studio

Take you to create a new project

The meaning of each file in the project directory

Solutions and Engineering

Before that, let's understand a concept: solutions and engineering.
Solution: the overall working environment of a large-scale project;
Project: a sub-project under a solution;

In VS, a Solution can have one or more Projects. When we create a project, if no Solution is specified, VS will help us create a Solution with the same name as the project. At this time, there is only one Project in a Solution. There is also a TestProject folder under the TestProject folder in the file directory structure of our TestProject (as shown in Figure 4). The first is the directory of the entire Solution, and the second is the Project directory.

Solution related files:

TestProject.sln:
A configuration file for the entire solution, organizing multiple projects and related elements into a solution. Double-click it with the mouse to open the entire project with VS.

TestProject.sdf:
Browse related database files, it supports browse and navigation features. Such as jumping to the declaration of methods, variables, finding all references to all objects, class views, etc.

TestProject.suo:
(solution user opertion) solution user opertion, records all options that will be associated with the solution, so that every time it is opened, it contains the custom settings you have made.

TestProject.opensdf:
A temporary file when opening a solution. This file will only exist when your solution is open in VS. The file will be deleted as soon as the project is closed.

Engineering related documents

TestProject.vcxproj:
Record project (Project) related property configuration.

TestProject.vcxproj.filters:
file filter, the organization and arrangement of each file in the "Project Structure" in Figure 3 above are defined in this file. If for some special reason (such as a sudden system or VS crash) the organization of the file is messed up when you open the project, 100% is the reason for this file.

TestProject.vcxproj.user:
some configuration related to users.

Among the above files, some of the more important files that must not be deleted are:

TestProject.sln、TestProject.vcxprojTestProject.vcxproj.filters

Don't ask me how I know what these files do, look at the official documentation:

VS2010 definition: https://msdn.microsoft.com/en-us/library/3awe4781.aspx .

VS2015 definition: https://msdn.microsoft.com/en-us/library/vstudio/hx0cxhaw(v=vs.110).aspx

Take you to understand various types of projects in VC++

Understand a few concepts ###

WITH

COM (Component Object Model) component object model is a component software standard developed by microsoft, which is the same as CORBA on unix. Any component developed in accordance with the COM standard is called a COM component. The goal is to achieve software reuse in binary mode. On the Windows platform, the implementation of COM has two types: DLL (in-process component) and EXE (out-of-process component).

BE

OLE (Object Linking and Embedding) Object Linking and Embedding is Microsoft's compound document technology that facilitates communication between applications. In the later OLE2, COM was imported, and the support for COM was provided. Reusable software components COM can be developed by using this technology. OLE is a technology proposed by software earlier.

ATL

ATL (Active Template Library) Active Template Library is a set of C++ template library, commonly used to develop COM programs and ActiveX programs. To understand ATL technology can be understood from the following two aspects:

  1. It can be said that ATL encapsulates COM, makes it a library like MFC, and has a wizard to automate and visualize COM application development as much as possible, which determines that ATL only provides support for COM development.
  2. Because ATL adopts a specific basic implementation technology, it gets rid of a lot of redundant code, and the code of COM application developed by ATL is concise and efficient.
    Before ATL came into being, there were two main ways to develop COM components: one was to use COM SDK (COM Software Development Kit) to directly develop COM components, and the other was to implement COM components provided by MFC. And now ATL has become Microsoft's main development tool to support COM application development.

MFC

MFC (Microsoft Foundation Classes) Microsoft Foundation Classes is a basic class library provided by Microsoft for Windows program development. MFC encapsulates the Windows API in the form of C++ classes and includes an application framework to reduce the workload of application developers. The included classes include a large number of Windows handle wrapper classes and wrapper classes for many Windows built-in controls and components.

ActiveX

ActiveX is a set of technologies proposed by Microsoft to use COM technology to make software components interact in a network environment. It has nothing to do with specific programming languages. As a technology developed for Internet applications, ActiveX is widely used in all aspects of WEB servers and clients. At the same time, ActiveX technology is also used to easily create common desktop applications, and ActiveX generally has an interface.

ActiveX includes both server-side technology and client-side technology. Its main contents are:

  1. ActiveX Control (ActiveX Control); used to insert COM objects into WEB pages, Microsoft Word and other containers that support ActiveX.
  2. ActiveX Document (ActiveX Document); used to browse compound documents (non-HTML documents) in WEB Browser or other containers that support ActiveX, such as Microsoft Word documents, Microsoft Excel documents or user-defined documents.
  3. ActiveX Scripting (ActiveX Scripting); used to manipulate ActiveX controls and Java programs from the client or server side, pass data, and coordinate operations between them.
  4. ActiveX Server Framework (ActiveX Server Framework); provides a series of functions and encapsulation classes for various aspects of WEB server application design, such as server filters, HTML data flow control, etc.
  5. Built-in Java Virtual Machine (Java Virtual Machine) in Internet Explorer, so that Java Applet can run on Internet Explorer, and can communicate with ActiveX control through script description language.

Take you to develop efficiently

Using Visual Assist X

Visual Assist X Snippets 宏

Visual Assist X Snippets 宏

Take you to manage code efficiently

The current mainstream version control systems are:

  1. CVS: It is a free software for code version control. It is a relatively early tool. Due to its many defects, it is now almost replaced by SVN.
  2. SVN: SVN is short for Subversion, which is a centralized version control system. SVN inherits the basic idea of ​​CVS and contains almost all the functions of CVS. You can think of SVN as an upgraded version of CVS (but in reality they are two pieces of software entirely).
  3. GIT: GIT is a distributed version control system. I believe everyone who has played with open source code knows github, it is a git-based code hosting platform

Files to be ignored by the C++ project upload server

Files to be ignored by the C++ project upload server

h: 头文件
cpp: 源文件
txt: 说明文件,如readme
rc: 资源文件
rc2: 资源文件
ico: 图标,如logo等
sln: 解决方案工程文件
vcxproj: 工程文件
filters: 文件过虑器

Types of files not to upload

Debug、Release等编译结构目录
ipch目录
aps: last resource editor state
exe: build result
idb: build state
ipch: build helper
lastbuildstate: build helper
lib: build result. Can be 3rd party
log: build log
manifest: build helper. Can be written yourself.
obj: build helper
pch: build helper
pdb: build result
res: build helper
sdf: intellisense dbase
suo: solution user options
tlog: build log
user: debug settings. Do preserve if just one dev or custom debug settings

If you use TortoiseSVN for management, you need to manually add the ignore attribute to ignore files that do not need to be uploaded. In your project directory, right-click->TortoiseSVN->Properties->New->Other, select svn:ignore in the Property name in the pop-up dialog box, and fill in the content to be ignored in the Property value (you can use matching characters here) . A global ignore style can be set.

Take you out of the pit father's Runtime Library pit

Multi-threaded  /MT     Release版的多线程静态库     libcmt.lib  
Multi-threaded Debug    /MTd    Debug版的多线程静态库   libcmtd.lib     
Multi-threaded DLL  /MD     Release版的多线程动态库     msvcrt.lib+msvcrtxx.dll     
Multi-threaded DLL Debug    MDd     Debug版的多线程动态库   msvcrtd.lib+msvcrtxxd.dll

Conclusion: /MD and /MDd will be the trend, please give up /ML and /MLd in time, and it is best not to use /MT and /MTd when it is not necessary.

Take you to understand multi-byte encoding and Unicode code

  1. When set to Use Unicode Character Set, there will be precompiled macros: _UNICODE, UNICODE
  2. When set to Use Unicode Character Set, there will be precompiled macros: _UNICODE, UNICODE

The role of incremental linking

Path macros in VS, OutDir, ProjectDir, SolutionDir various paths in vc++

Compile C/C++ programs from the command line

Open VSDIR\VC\bin in the installation directory, you can see a series of executable programs. exe and batch files, these are the tools to be used when VS2010 builds, compiles, and links. Take a look at a few major tools:

cl.exe:编译程序
link.exe:链接程序
lib.exe:加载lib库的程序
nmake.exe:用makefile进行构建、编译的工具

Microsoft CL.exe compiler

Performance Analysis and Optimization##

Using VS's performance analysis tools

Selection of performance analysis tools

Open a "Performance Analysis" session: Debug->Start Diagnotic Tools Without Debugging (or press Alt+F2), VS2013 is in the Analysis menu.

CPU Usage

Detect the performance of the CPU, mainly used to find the code that affects the CPU bottleneck (consuming a lot of CPU resources).

GPU Usage

Detecting the performance of the GPU, commonly used in graphics engine applications (such as DirectX programs), is mainly used to determine whether the CPU or GPU is the bottleneck.

Memory Usage

Detect the memory of the application and find the memory.

Performance Wizard

Performance (Monitoring) Wizard, which comprehensively detects program performance bottlenecks. This is more commonly used, and will be explained one by one below.

Performance (Monitoring) Wizard

CPU Sampling:

Sampling statistics to monitor CPU-intensive applications at a low overhead level. This can greatly save monitoring time for computationally intensive programs.

Instrumentation:

Full statistics, measuring function call counts and elapsed time

.NET memory allocation:

Track managed memory allocations. This seems to be only available for managed code (such as C#), generally C++ code does not seem to work.

Resource contention data (concurrent):

Detect threads waiting for other threads, mostly used for multi-threaded concurrency.

Performance Analysis Report

view type

There are several different views for us to switch between. The bolded part below is the view that I find more convenient and commonly used.

  • Summary: a summary description of the entire report
  • Call Tree: Expand the relationship between functions in a tree-shaped table.
  • Module (module): analyze the time-consuming of different program modules called, such as different DLL and lib modules
  • Caller/Callee (calling and being called): the relationship between calling and being called by numerical value
  • Functions (function statistics): The execution time and execution times of each function are displayed numerically.
  • Marks:
  • Processers:
  • Function Details: Graphically display the relationship and time ratio between the calling function - the current function - the called sub-function.

special term

  • Num of Calls: (function) number of calls
  • Elapsed Inclusive Time: Elapsed Inclusive Time
  • Elapsed Exclusive Time: Elapsed exclusive time
  • Avg Elapsed Inclusive Time: Average elapsed inclusive time
  • Avg Elapsed Exclusive Time: Average elapsed exclusive time
  • Module Name: The name of the module, generally the name of the executable file (.exe), dynamic library (.dll), and static library (.lib).

Calling conventions __cdecl, __stdcall and __fastcall

What is a calling convention

The calling convention of a function, as the name suggests, is a constraint and regulation (specification) on the function call, which describes how the function parameters are passed and who clears the stack. It determines the following: (1) the order in which the function parameters are pushed onto the stack, (2) whether the caller or the callee pops the parameters off the stack, (3) and the method for generating the function's decorated name.

Common calling conventions are __cdecl, __stdcall, fastcall, the most widely used are __cdecl and __stdcall, we will describe in detail below. . There are also some less common ones, such as __pascal, __thiscall, __vectorcall.

Features of __cdecl

__cdecl is the abbreviation of C Declaration, which means the default function calling convention of C and C++. is the default calling convention for C/C++ and MFCX.

  • Arguments are pushed onto the stack from right to left.
  • It is up to the caller to pop the parameter off the stack. Remember: the memory stack for passing parameters is maintained by the caller, and the return value is in EAX. So this convention must be used for variadic functions like printf.
  • When the compiler generates a decorated name for a function of this calling rule at compile time, it adds an underscore prefix before the output function name in the format _function. For example, the modified name of the function int add(int a, int b) is _add.

Characteristics of __stdcall

__stdcall is the abbreviation of Standard Call, which is the standard calling method of C++. Of course, this is the standard defined by Microsoft. __stdcall is usually used in Win32 API (see the definition of WINAPI).

  • Arguments are pushed onto the stack from right to left.
  • It is up to the callee to pop the parameter off the stack. Remember: the function itself clears the stack on exit, the return value is in EAX.
  • The __stdcall calling convention adds an underscore prefix to the output function name, followed by an "@" symbol and the number of bytes of its parameters, in the format _function@number. For example, the modified name of the function int sub(int a, int b) is _sub@8.

__fastcall features

The main feature of the __fastcall call is that it is fast, because it transfers parameters through registers.

  • In fact, __fastcall uses ECX and EDX to transfer the first two DWORD or smaller parameters, the remaining parameters are still pushed from right to left, and the called function clears the memory stack of the passed parameters before returning.
  • The __fastcall calling convention adds an "@" symbol before the output function name, followed by an "@" symbol and the number of bytes of its parameters, the format is @function@number, such as the modified name of double multi(double a, double b) It's @multi@16.
  • __fastcall is very similar to __stdcall, the only difference is that the first two arguments are passed through registers. Note that the two parameters transferred through the register are from left to right, that is, the first parameter goes into ECX, the second goes into EDX, the other parameters are pushed from right to left, and the return still goes through EAX.

__thiscall

__thiscall is the default calling convention for C++ class member functions, but it has no explicit declaration form. Because in C++ classes, member function calls also have a this pointer parameter, so they must be handled specially, the characteristics of thiscall calling convention:

  • Parameter push: Parameters are pushed onto the stack from right to left
  • The this pointer is pushed onto the stack: if the number of parameters is determined, the this pointer is passed to the callee through ecx; if the number of parameters is uncertain, the this pointer is pushed onto the stack after all parameters are pushed onto the stack.
  • Stack recovery: If the number of parameters is indeterminate, the caller clears the stack, otherwise the function clears the stack by itself.

Calling Conventions and (Dynamic) Libraries

Calling Conventions and (Dynamic) Libraries

refer to:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324135968&siteId=291194637