Windows Application Development
This post talks about different level of Windows application development, including APIs, Application category, and hardware platform.
Windows API (Win32 API)
Definition. The Windows API, also called Win32 API, is Microsoft’s core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. Applications that leveraged Win32 API directly are called Win32 Applications, or Desktop applications, which can can access the full set of Windows APIs and either runs in a window or in the system console.
Features and power. Almost all Windows programs interact with the Windows API. It specifies the interface between an application and the Windows system by exposing a large part of the underlying structure of the Windows systems to programmers. Windows API gives the developer much flexibility and power over their applications, but also creates great responsibility in how applications handle various low-level, sometimes tedious, operations that are associated with a graphical user interface.
Implementation. Although the Windows API mainly focused on the programming language C
, there have also been many wrapper classes and extensions for object-oriented languages, which makes the Windows API more object-oriented.
Developer tools. Developer support is available in the form of a software development kit, Microsoft Windows SDK, providing documentation and tools needed to build software based on the Windows API and associated Windows interfaces.
Versions
There are different versions of Windows API such as Win16, Win32, Win32s, Win64, and WinCE. They firstly targeted to different 16-bit, 32-bit, 64-bit versions of Windows. But finally, Microsoft made Win32
into a catch-all term for both past and future API versions.
Basic Functions
Function | Description | Files |
---|---|---|
Base Services | file systems, devices, processes, threads, and error handling | kernel.exe, kernel32.dll, KernelBase.dll and etc |
Advanced Services | - Windows registry - shutdown/restart the system - manage user accounts |
advapi32.dll, advapires32.dll |
Graphics Device Interface | output graphics content to monitors, printers, and other output devices | gdi.exe, gdi32.dll |
User Interface | - create and manage screen windows and most basic controls e.g. buttons - receive mouse and keyboard input |
user32.dll |
Common Dialog Box Library | standard dialog boxes to open and save files | comdlg32.dll |
Common Control Library | status bars, progress bars, toolbars and tabs | comctl32.dll |
Windows Shell | access functions provided by the operating system shell | shell32.dll |
Network Services | NetBIOS, Winsock, NetDDE, remote procedure call | netapi32.dll |
Notes .dll
files are dynamic libraries, which can be dynamically linked with other applications to help them achieve specific functions.
Advanced Functions
Apart from the basic functions, there are also some APIs alongside the main Windows API.
Function | Description |
---|---|
Web | some APIs from IE - An embeddable web browser control: shdocvw.dll - An HTTP client library - XML support: msxml*.dll |
Multimedia | - sound: mmsystem.dll - graphics and gaming services: DirectX (collections of APIs) |
Program interaction | interaction between the operating system and an application |
Wrapper libraries | - Microsoft Foundation Class Library (MFC): wrapped Windows API functionality in C++ classes - Active Template Library (ATL): template oriented wrapper for COM - Windows API Code Pack for Microsoft .NET Framework: .NET wrapper library for Windows API |
Windows Runtime (WinRT)
Definition. Windows Runtime (WinRT) is a platform-agnostic component and application architecture first introduced in Windows 8 and Windows Server 2012 in 2012. WinRT is not a runtime in a traditional sense but rather a language-independent application binary interface (ABI) based on COM to allow APIs be consumed from multiple languages, but it does provide certain services usually provided by a full-blown runtime. Built-in APIs provided by Windows which use the WinRT ABI are commonly known as WinRT APIs.
Features. Applications using Windows Runtime run within a sandbox and need explicit user approval to access critical OS features and underlying hardware. Most WinRT APIs expected to take significant time to complete are implemented as asynchronous, reducing the chance when the application is not responding. WinRT aims the development Windows Store apps.
Implementation. WinRT is implemented in the programming language C++. It supports development in C++ (via C++/WinRT, C++/CX or WRL), Rust/WinRT, Python/WinRT, JavaScript-TypeScript, and the managed code languages C# and Visual Basic .NET (VB.NET).
Relationship with Win32 API
WinRT isn’t another abstraction layer; it resides directly on top of the kernel just like the Win32 API. This marks the first major break in the core of Windows since Win32 was introduced in 1993 with Windows NT. WinRT represents a new application execution environment with semantics that are very different than Win32.
However, WinRT is intended to be the successor to the flat, C-based Win32 API, the Win32 API has not been removed and older applications using the traditional application execution environment will continue to work as expected. e.g. Microsoft Office, Adobe Products, and Visual Studio. Therefore, WinRT APIs and the Win32 APIs can be used side by side.
As for the applications, Win32 applications that are written in pure C++ and used to call Win32 APIs can also use WinRT APIs through C++/WinRT. Desktop Bridge also enables Win32 process to call WinRT components.
Services
Metadata. The metadata describes the code written for the WinRT platform. It defines a programming model that makes it possible to write object-oriented code that can be shared across programming languages, and enables services like reflection. It is saved in .winmd
files.
Type system. It supports constructs with corresponding constructs in the .NET framework: classes, methods, properties, delegates, and events.
Programming Interface. The Windows Runtime is based on Component Object Model (COM) APIs, and it’s designed to be accessed through language projections
. A projection hides the COM details, and provides a more natural programming experience for a given language. Supporting language projections include
- C++/WinRT, C++/CX (Legacy), WRL (Windows Runtime C++ Template Library, Legacy)
- .NET (C#, Visual Basic)
- JavaScript
Device Platforms
- PC
- HoloLens
- Xbox
- Surface Hub
- IoT devices
Categories of Windows Applications
There are different types of Windows Applications.
Native Desktop Client Application (Win32 Application)
Native desktop applications use C-based/C++
to develop and calls Win32 APIs directly. Using Win32 API with C++ could achieve the highest levels of performance and efficiency
with by taking more control of the target platform un-managed code
than on a managed runtime environment like WinRT and .NET. However, Win32 applications can still use C++/WinRT
or C++/CX
to call WinRT APIs.
Strengths of Win32 applications:
- Hardware-level optimizations, including tight control over resource allocation, object lifetimes, data layout, alignment, byte packing, and more
- Access to performance-oriented instruction sets like SSE and AVX through intrinsic functions
- Efficient, type-safe generic programming by using templates
- Efficient and safe containers and algorithms
- DirectX, in particular Direct3D and DirectCompute
To develop Win32 app with C/C++, Windows SDK is required, which includes the headers and libraries necessary to compile and link applications, command-line tools for building Windows applications, including the Visual C++ compiler and linker.
Universal Windows Platform Application (UWP Application)
UWP is an application model built on top of the Windows Runtime. UWP apps use WinRT APIs to provide powerful UI and advanced asynchronous features that are ideal for internet-connected devices. UWP apps run on any Windows 10 or Windows 11 device.
UWP applications can be native
or managed
. Native UWP
apps use C++/WinRT
, or C++/CX
(legacy) or WRL
(legacy) to develop. Managed UWP
apps use .NET and managed language like C#
to develop.
Strength of UWP application
- More secure against malware and viruses compared to Win32 apps because they are completely sandboxed which means they can’t interact with other apps on the operating system in ways that Win32 apps can
- More power efficient because they are suspended when they are not in focus. This means that when we switch to a different app, the Store apps in the background stop using any processor time which can prolong the battery life on the laptop or tablet.
e.g. UWP Application Sample
noticed that when you run the program in VS, the UWP program will be installed in your computer, you can find it in your start menu.
WPF (Windows Presentation Foundation)
The established .NET-based
platform for graphically-rich managed
Windows apps with a XAML UI model
. These apps can target .NET Core 3 or the full .NET Framework. The WPF development platform supports a broad set of application development features, including an application model, resources, controls, graphics, layout, data binding, documents, and security.
- An alternative of Windows Forms
- Used XMAL to build the UI, used other .NET language to build the logic
- can run in any version of windows with the appropriate .NET framework installed
- based on DirectX, better when you scale, but need a lot of time to design
- eg. The modern style App in Win10 but not from the Windows Store
Windows Forms
A .NET-based
platform that is designed for managed
line-of-business apps with a lightweight UI model
. These apps can target .NET Core 3 or the full .NET Framework. It provides rich, interactive user interfaces.
- The oldest desktop platform for Windows using .NET
- can run in any version of windows with the appropriate .NET framework installed
- good in performance
- eg. The old win7 style App
Library development
Dll
Dynamic link libraries will be loaded into memory and used by client application in runtime. A Dll project usually generate 2 files. A lib
file and a dll
file, where the lib
is import library which only contains symbols to allow the linker to link to a Dll, and the dll
file really hold the exported functions.
When creating a client application need to use Dll file in Visual Studio. Following steps need to be performed
- Use
.h
to pass compile - Use
.lib
to pass link. Step 1 and 2 could pass the build - Use
.dll
when executing the builtexe
application
Reference
- Wikipedia, Windows API
- Wikipedia, WinRT
- Quora, What is WinRT(Windows Runtime)?
- Microsoft Docs, Windows app developer documentation
- Microsoft Docs, Build desktop apps for Windows PCs
- Microsoft Docs, Choose your app platform
- WinRT: An Object Orientated Replacement for Win32
- Overview of Windows Programming in C++
- StackOverFlow: Dll and Lib files
- Microsoft Docs, Creating and Using Dll