Table of Contents
Start with the compilation process of the program" > Start with the compilation process of the program
Write our Test.c file" > Write our Test.c file
Home Operation and Maintenance Windows Operation and Maintenance Win32 SDK Basics (2) Detailed explanation of the cl.exe and link.exe compilation and linking procedures (picture)

Win32 SDK Basics (2) Detailed explanation of the cl.exe and link.exe compilation and linking procedures (picture)

Jun 06, 2017 am 09:36 AM

Start with the compilation process of the program

## We introduced windows in the previous article Knowledge of the classification of programs under the system, compilers, connectors, commonly used header files, library files, etc. This article will talk about the compilation process of the program.

I believe everyone knows that the compilation process of source code is divided into two steps: First, the compilation process, the main job is to translate our source code into intermediate files, which is in windows is the function of cl.exe, it will use our .c file or The .cpp file is translated into an intermediate .obj file; the second is the connection process. The main job is to connect various intermediate files and library files to generate an executable file. This is the role of link.exe in windows, it will .objFiles and library files are linked into exe programs.

This article mainly teaches you to get rid of the IDE of VS and use the command line to use cl.exe and link.exe compile and link the program.

Write our Test.c file

## First We create a new

test.txt file and rename it to text.c. In this file we fill in the following code:

#include "windows.h"
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,  
                     _In_opt_ HINSTANCE hPrevInstance,  
                     _In_ LPWSTR    lpCmdLine,  
                     _In_ int       nCmdShow)   
{
  MessageBox(NULL,"Hello Win32","sdk",MB_ABORTRETRYIGNORE|MB_ICONERROR);
  return 0;
}
Copy after login
    #include "windows.h"

Imports all the necessary header files we need under the

windows system. Then we introduced the main function of the windows window programwWinMain. Here is a brief explanation of the role of each formal parameter in Winmain: hInstance is the instance handle of the current program, which is the memory where the current program is located. The position; hPrevInstanceThe handle of the previous instance of the current program, which has been abandoned; lpCmdLine is the command line parameter, that is, we use the command line When executing the program, you can attach some strings as parameters; nCmdShow is the window display mode, maximize or minimize. We called MessageBox in the main function to define a modal dialog box. If the compilation is successful, a dialog box will pop up after we execute the program.

Now that the

Test.c file has been written, the next thing we have to do is compile and link the files separately.

CompileTest.c

We will open

windows The cmd command line tool, then switch to our current working directory and compile the Test.c file using the following command: Cl.exe /c test.c

After compilation is completed, the test.obj intermediate file will be generated in the working directory:

If your command line prompt cannot find the cl.exe command and other information, I believe you should understand that this is because the environment variable does not exist To import the directory where cl.exe is located, we can first add the environment variable or use the full path to import. If you generate the test.obj file, it means that the compilation process is completed and we can start the connection process.

4. Link generationtest.exe

Next we execute the following command to generate the executable file:

Link.exe test.obj user32.lib

User32.libWe mentioned this library in the previous article. It contains the desired user interface and message-related API. The MessageBox we need to call is defined in this library. , if nothing goes wrong, the executable file test.exe should be generated in your working directory:


## Double-click this exe, and the dialog box we defined pops up:


OK

, the test is over. We completely broke away from VSwith interfaceIDE and generated a custom dialog box. Isn’t it amazing? There should be Xiao Yueyue's mean expression here. . .

The above is the detailed content of Win32 SDK Basics (2) Detailed explanation of the cl.exe and link.exe compilation and linking procedures (picture). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Windows 11 22H2 brings mica/acrylic design to more Win32 desktop apps Windows 11 22H2 brings mica/acrylic design to more Win32 desktop apps Apr 14, 2023 pm 04:58 PM

Windows 11 22H2 brings mica/acrylic design to more Win32 desktop apps

Microsoft is developing new blur effects for Windows 11 Microsoft is developing new blur effects for Windows 11 May 13, 2023 am 09:04 AM

Microsoft is developing new blur effects for Windows 11

Trojan/win32.casdet Rfn in Windows 11 Trojan/win32.casdet Rfn in Windows 11 Apr 14, 2023 pm 02:49 PM

Trojan/win32.casdet Rfn in Windows 11

What is the difference between win32 and win64 What is the difference between win32 and win64 May 29, 2023 pm 05:22 PM

What is the difference between win32 and win64

Microsoft begins testing new OneNote design for Windows 11 Microsoft begins testing new OneNote design for Windows 11 Apr 19, 2023 pm 08:01 PM

Microsoft begins testing new OneNote design for Windows 11

what is sdk what is sdk Jan 06, 2023 pm 03:26 PM

what is sdk

Installation and use of WeChat mini program PHP SDK Installation and use of WeChat mini program PHP SDK Mar 27, 2024 am 09:33 AM

Installation and use of WeChat mini program PHP SDK

Master the essential skills for secondary development of Java Hikvision SDK Master the essential skills for secondary development of Java Hikvision SDK Sep 06, 2023 am 08:10 AM

Master the essential skills for secondary development of Java Hikvision SDK

See all articles