WinAPI C for beginners

C WinAPI is the core set of Microsoft programming interfaces (APIs) available on Microsoft Windows operating systems . The early version was called the Win32 API.

Introduction

C WinAPI is an application programming interface that is used to create Windows applications. To get started, the novice user must download the Windows SDK, formerly known as the Platform SDK.

c winapi

The SDK (Software Development Kit) contains header files, libraries, samples, documentation, and tools that are used to develop applications. The Windows API is designed for the C and C ++ programming languages. This is the most direct way to create applications in the operating system from the company.

C WinAPI can be divided into several areas:

  • basic services;

  • security;

  • graphics;

  • user interface;

  • multimedia;

  • Windows shell

  • network services.

Basic services provide access to core resources. These include C WinAPI functions, file systems, devices, processes, threads, registry, and error handling. The security area provides interfaces, objects, and other programming elements for authentication, authorization, cryptography, and other security-related tasks. The graphics subsystem provides functionality for outputting graphic content to monitors, printers, and other output devices. The user interface provides functionality for creating windows and controls.

create winapi c
The multimedia component provides tools for working with video, audio and input devices. Shell interface functions allow applications to access the functions provided by the operating system shell. Network services provide access to the network features of Windows.

Components

When creating WinAPI C, you should consider the basic features provided by the Windows API, which can be ordered in seven categories. Let's consider each of them in more detail.

Basic services provide access to the basic system resources available on Windows. Examples: file system, peripherals, processes, registry access, and exception management system. These functions are stored in kernel.exe, krnl286.exe, or krnl386.exe for 16-bit systems and kernel32.dll and advapi32.dll for 32-bit systems.

A graphical interface provides access to resources for display on monitors, printers, and other peripheral equipment. It is stored in the gdi.exe file on 16-bit systems and gdi32.dll on 32-bit systems.

The user interface is responsible for viewing and managing basic elements such as buttons and scrollbars, obtaining keyboard and mouse information, and related functions. These functions are stored in user.exe on 16-bit systems and user32.dll comctl32.dll on 32-bit systems. Since XP, controls have been grouped into comctl32.dll.

General dialogs - display data for opening and saving files, choosing color and font. They are located in the comdlg.dll file on 16-bit systems and comdlg32.dll on 32-bit systems.

Windows Shell is a WinAPI component that allows applications to access the functions provided by the operating system shell.

Network Services provides access to the various network capabilities of the operating system. Its subcomponents include NetBIOS, Winsock, RPC. In older versions - NetDDE.

winapi c for beginners

Versions

Win16, Win32 and Win32s are standard sets of components that allow application software to use the functions of various Windows operating systems.

Win32, the successor to Win16, was introduced in 1993 in 32-bit Windows products, such as Windows NT, 2000, 95. This programming interface is implemented by three software libraries: Kernel32.dll, User32.dll and GDI32.dll2. The same Win32 functions are available in all Windows products, and depending on the product, the use of certain functions may result in a maintenance error.

Win32 features include interoperability between programs, process management, computer networks, files, printers, servers, and communication ports.

c winapi example

Specification

C WinAPI is an abstract specification of the programming interface for the Windows operating system. It consists of declarations of functions, unions, structures, data types, macros, constants, and other programming elements. WinAPI is mainly described by MSDN (Microsoft Developer Network) and is located in the Windows C headers. The official implementation of WinAPI functions is in dynamic libraries (DLLs): for example, kernel32.dll, user32.dll, gdi32.dll or shell32.dll in the system directory. There are third-party implementations of the Windows API: primarily the Wine project and the ReactOS project.

The Windows API is a dynamic object. The number of functions is constantly growing with each new version of the OS and new service packs. There are also important differences between server versions and desktop versions of the operating system. Some features are not officially documented.

c winapi functions

Pelles c

Pelles C is a free program and the best C compiler and integrated development environment (IDE) for the C programming language. It supports 32-bit Windows (x86) and 64-bit Windows (x64). It implements both C99 and C11 standards. Pelles C has a built-in resource editor, bitmap, icon and cursor editor, and hex dump editor. It was developed by the Swedish developer Pelle Orinius. The name of the compiler bears the name of its author. It comes with an SDK, so the programmer can immediately start creating applications without further installation.

Target Architecture Error

To create Windows API programs, you must enable Microsoft extensions. By default, they are turned off, and therefore the compiler generates the following error message, which serves as an example of C WinAPI with a broken structure: fatal error # 1014: #error: "No target architecture". To enable Microsoft extensions, go to the project settings and select the β€œCompiler” tab. On this tab, activate the "Enable Microsoft Extensions" checkbox.

MSDN

MSDN (Microsoft Developer Network) is the central portal for Windows development. This is a huge collection of materials related to the development of applications using Microsoft tools. This is the most comprehensive base along with desktop development documentation and a list of Windows APIs.

winapi application c

Using DLL in WinAPI C

A common control library provides access to advanced operating system features such as status bars, progress bars, toolbars, and tabs. These commands are located in the commctrl.dll library on 16-bit systems and comctl32.dll and are grouped with a user interface.

DLL is a dynamic link library file format used to store several codes and procedures for Windows programs. DLL files were created in such a way that several programs could use their information at the same time, helping to save memory. Allows the user to edit the coding of several applications at once without changing them. DLLs can be converted to static using the MSIL Disassembler or DLL for Lib 3.00.

WinAPI C for beginners

WinAPI as an application programming interface for Windows offers many powerful functions that allow you to create your own programs, from simple file processing to building a graphical interface for programming low-level device drivers.

Before you begin programming in WinAPI, you must configure the environment for code in Windows. Since it is not a Linux distribution, it does not have a built-in compiler for building applications. Consider the following options for compiling code:

  • MinGW / Cygwin is a third-party C WinAPI application that provides a suitable programming environment on the Windows platform. This compiler is ideal for a novice user due to the simplicity and convenience of organizing the environment. When working with this solution, you will need a text editor, since it is not provided by the graphical interface of the application.

  • Third-party IDEs, or integrated development environments, are applications that create a GUI for developers. They come bundled with related tools, such as MinGW, for creating Windows programs.

  • Microsoft Visual Studio (MSVS) is a Microsoft IDE developed with its own compiler, which provides many functions and features when creating your own Windows applications, including a graphical interface, application version information, icons, and other resources. Optimal for malware research.

    using dll in winapi c

A developer kit is available for Windows that provides documentation and tools that allow developers to create software using the API and related technologies.

Source: https://habr.com/ru/post/K11493/


All Articles