Windows core programming process (1)

Source: Internet
Author: User
Starting from today, the process is generally defined as an instance of a program running by one person. It consists of two parts: 1. one is the kernel object used by the operating system to manage processes, and the kernel object is also used by the system to store statistics about processes. 2. The other is the address space, which contains the code and data of all executable modules or DLL modules. It also contains the space allocated by the dynamic memory. Such as thread stack and heap allocation space. To allow a process to complete an operation, it must have its own thread to execute the Code contained in the address space of the process. Each thread has its own set of CPU registers and its own stack. How do multiple threads run? The operating system schedules a certain CPU for each thread and provides a time slice (called a volume name) for the line program in a loop) windows supports two types of applications. One is an application based on a graphical user interface (GUI), and the other is an application based on a console user interface (Cui. In VC settings, the linked program displays the title of the executable graphical program according to/subsystem: condole or/subsystem: Windows. When you run an application, the OS loader displays the title of the executable graphical program, capture the value of this subsystem. If this value specifies a Cui application, the loader automatically creates a text Console window for the application. Otherwise, when the application starts to run, the OS no longer cares about the type of user interface that the application has. The entry point function int winapi winmain (hinstance hinstexe, hinstance, pstr pszcmdline, int ncmdshow) called when the four applications provided by Windows Start and run; // The second parameter indicates the previous instance handle, it is used in 16-bit windows int winapi wwinmain (hinstance hinstexe, hinstance, pwstr nsz1_line, int ncmdshow); L int _ cdecl main (INT argc, char * agrv [], char * envp []); int _ cdecl wmain (INT argc, wchar_t * argv [], wchar_t * envp []); note: the OS does not call the entry point function we wrote, it calls the C/C ++ runtime startup function. This function initializes the C/C ++ Runtime Library so that you can call functions such as malloc and free. It also ensures that all well-known global objects and static C ++ objects can be correctly created before code execution.

Application entry point

The startup function of the application type entry point embedding executable files requires the ASCI character and string GUI application winmain winmaincrtstartup requires the Unicode Character and string GUI application wwinmain wwinmaincrtstartup requires the ASCI character and string the Cui application main maincrtstartup requires Unicode characters and strings. The Cui application wmain wmaincrtstartup all the C/C ++ startup functions at runtime have the same functions, it only processes the ANSI string or Unicode string, and the entry function that they call after initializing the C Runtime Library.

The source code of the C Runtime Library has the following main functions in the crt0.c file: 1. Retrieve the complete command line pointer to the new process. 2. Retrieve the pointer to the environment variable of the new process. 3. initialize global variables in the C/C ++ runtime. If stdlib is included. h file, the code will be able to access these variables (those four functions such as winmain) 4. initialize the memory stack used by the memory unit allocation function (malloc and calloc) and other low-level Input/Output Routines in the C runtime. 5. Call constructors for all global and static C ++ class objects. After completing the above functions, C/C ++ starts the function and calls the entry point function of the application. When the function is returned, start the function and call the exit function in the C runtime. The exit function is responsible for the following operations: 1. call any function registered by calling the _ onexit function 2. call the Destructor for all global and static C ++ class objects. 3. Call the exitprocess function of OS... To be continued .............

 

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.