# Windows API

Windows API 是应用程序编程接口，面向 [Microsoft Windows](https://www.edgepedia.org/zh/microsoft-windows) 的桌面和服务器应用程序通过它向操作系统请求服务，涵盖窗口管理、图形、存储、设备、网络、安全和系统管理。它以前被称为 Win32 API；据 Microsoft 称，“Windows API”这一术语更好地传达了它可追溯至 16 位 Windows，如今也运行在 64 位 Windows 上。<sup>[1](https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-api-list)</sup> 针对它编写的应用程序可以在所有受支持的 Windows 版本上运行，同时利用每个版本独有的功能。<sup>[1](https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-api-list)</sup>

| 关键事实 | 详情 |
|---|---|
| 曾用名与现名 | 原名 Win32 API；更名为 Windows API，以反映其 16 位根源和 64 位支持<sup>[1](https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-api-list)</sup> |
| 首个 32 位版本 | Win32 随 Windows NT 首次亮相；Windows NT 和 Win32 API 的首次公开发布是在 1993 年<sup>[2](https://gunkies.org/wiki/Windows_NT_3.1)</sup> |
| 接口形式 | 以 C 语言绑定规定；以共享库（DLL）形式实现，使用与 Pascal 程序相关的调用约定，因此许多函数可从其他语言调用<sup>[3](https://www.spinellis.gr/pubs/jrnl/1997-CSI-WinApi/html/win.pdf)</sup> |
| 64 位数据模型 | LLP64：只有指针扩展到 64 位；整数和 long 仍为 32 位<sup>[4](https://learn.microsoft.com/en-us/windows/win32/winprog64/abstract-data-models)</sup> |
| 后继接口面 | Windows 运行时（WinRT），一种面向对象的 API 接口面，命名空间以 `Windows.*` 开头，随 Windows 8 引入<sup>[5](https://learn.microsoft.com/en-us/windows/apps/develop/interop/)</sup> |
| 重新实现 | Wine 在类 Unix 系统上实现 Windows API，使 Windows 应用程序可以在那里运行<sup>[6](https://citeseerx.ist.psu.edu/document?doi=b48deefde8f9f440582f0a96d59be48c3f43c128&repid=rep1&type=pdf)</sup> |

## 历史

最早的 16 位 Windows 版本的 API 被称为 Win16。Win32 是 32 位 Windows 版本的 API，随 [Windows NT](https://www.edgepedia.org/zh/windows-nt) 引入。<sup>[7](https://catalogimages.wiley.com/images/db/pdf/9780470041802.excerpt.pdf)</sup> Microsoft 于 1992 年 7 月在旧金山举行的 Win32 专业开发者大会上展示了 Windows NT，与会者收到了 Win32 API 初步软件开发工具包，其中包含 Windows NT 的早期版本。<sup>[8](https://learn.microsoft.com/en-us/shows/history/history-of-microsoft-1992)</sup> 1993 年，Windows NT 3.1 发布，这是该操作系统和 Win32 API 的首次公开发布。<sup>[2](https://gunkies.org/wiki/Windows_NT_3.1)</sup>

32 位和 64 位两代共享同一代码库：使用 Windows API 的 32 位和 64 位程序可以从同一份源代码构建，LLP64 数据模型通过将大小变化限制在指针上来支持这一点。<sup>[4](https://learn.microsoft.com/en-us/windows/win32/winprog64/abstract-data-models)</sup>

## 结构与实现

该接口通过 C 头文件规定，并实现为一组动态链接库（DLL）。软件工程研究者迪奥米迪斯·斯皮内利斯（Diomidis Spinellis）当时发表关于 API 架构的分析，他在 1997 年对 Win32 SDK 的分析中统计了 129 个根头文件、总计 232 个头文件、3,433 个函数、1,462 个接口方法、858 条消息和 1,077 个结构，另有 33,174 个宏和常量定义以及 4,858 个类型定义。<sup>[3](https://www.spinellis.gr/pubs/jrnl/1997-CSI-WinApi/html/win.pdf)</sup> SDK 附带的一个文件 WIN32API.CSV 列出了 9,067 个 API 元素，这一数字不包括头文件中约 29,000 个常量定义和约 4,800 个类型定义。<sup>[3](https://www.spinellis.gr/pubs/jrnl/1997-CSI-WinApi/html/win.pdf)</sup>

**分层。** 调用在到达内核之前要经过若干层。有文档记载的 `CreateFile` 函数由 kernel32.dll 提供，它调用 Ntdll.dll 中的 `NtCreateFile`，请求内核执行该操作。<sup>[9](https://xn--lcss68aj21b.xn--w8je.xn--tckwe/books/windowsnativeapiprogramming.pdf)</sup> Ntdll.dll 中的入口点将 Nt 和 Zw 例程的调用转换为陷入内核模式的系统调用；Ntoskrnl.exe 不暴露任何可从用户模式到达的入口点，Ntdll.dll 的入口点同样对内核模式驱动程序不可用。<sup>[10](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/libraries-and-headers)</sup> 应用程序在用户模式下运行，每个进程拥有私有的虚拟地址空间，而核心操作系统组件在内核模式下运行，共享单一地址空间。<sup>[11](https://learn.microsoft.com/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode)</sup>

**API 集。** 现代 Windows 将 API 所属的契约与实现它的 DLL 分离。API 集名称以 `api-` 或 `ext-` 开头，标识的是一个契约而非文件；在运行时，加载器通过 API 集架构解析该契约，并将引用路由到承载它的 DLL。这使得模块可以跨 Windows 的不同发布版本和产品版本进行重构，而应用程序仍能继续链接和运行。<sup>[12](https://learn.microsoft.com/windows/win32/apiindex/windows-apisets)</sup> API 集还让应用程序可以在运行时使用 `IsApiSetImplemented` 函数检测当前设备上是否存在某项能力，这一点很重要，因为在 HoloLens 和 Xbox 等非 PC 设备上只有一部分 Win32 API 可用。<sup>[12](https://learn.microsoft.com/windows/win32/apiindex/windows-apisets)</sup>

## 范围

参考文档按技术领域组织。Windows API 索引涵盖用户界面、Windows 环境（Shell）、用户输入与消息传递、数据访问与存储、诊断、图形与多媒体、设备、系统服务、安全与身份、应用程序安装与维护、系统管理、网络与互联网，以及已弃用或旧版 API。<sup>[1](https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-api-list)</sup>

用户界面部分创建和使用窗口来显示输出并提示输入；大多数应用程序至少创建一个窗口。<sup>[1](https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-api-list)</sup> 每个基于 Windows 的应用程序都必须以 `WinMain` 作为入口点函数，它使用 `RegisterClass` 注册窗口类，并使用 `CreateWindowEx` 创建主窗口；返回的窗口句柄具有 HWND 数据类型，在后续调用中用于标识该窗口。<sup>[13](https://learn.microsoft.com/en-us/windows/win32/winmsg/about-windows)</sup> 图形和游戏 API 包括 Direct2D、Direct3D 11 和 12、DXGI、经典的 Windows GDI 以及 GDI+。<sup>[14](https://learn.microsoft.com/en-us/windows/win32/api/)</sup>

## 批评

斯皮内利斯的一篇同行评审批评文章认为，该 API 的架构、接口和功能使其难以掌握和有效使用，并对在其下开发的应用程序的安全性、健壮性和可移植性产生负面影响，文中列举了复杂性、非正交性、类型系统、命名空间污染、命名约定不一致和可移植性等问题。<sup>[3](https://www.spinellis.gr/pubs/jrnl/1997-CSI-WinApi/html/win.pdf)</sup><sup> • </sup><sup>[15](https://www.sciencedirect.com/science/article/abs/pii/S0920548998000129)</sup> 同一分析指出，该 API 对 DLL 的依赖对应用程序及其链接的库不提供版本和接口控制，因为在给定时间系统上只能加载一个版本的 DLL。<sup>[3](https://www.spinellis.gr/pubs/jrnl/1997-CSI-WinApi/html/win.pdf)</sup> [Wine](https://www.edgepedia.org/zh/wine-software) 项目的开发者指南指出，Windows API 不遵循任何标准；它本身就是事实标准，这使独立重新实现变得复杂。<sup>[6](https://citeseerx.ist.psu.edu/document?doi=b48deefde8f9f440582f0a96d59be48c3f43c128&repid=rep1&type=pdf)</sup>

## 兼容性与重新实现

由于应用程序依赖于精确的 API 行为，Microsoft 维护了一个兼容性基础设施，将应用程序从 Windows 代码重定向到实现兼容性修复的替代代码。该修复通过修改导入地址表中受影响 Windows 函数的地址来起作用，导入地址表是 API 调用到达外部二进制文件所经过的间接层。兼容性修复作为用户模式代码在应用程序进程内运行，因此无法解决设备驱动程序问题等内核模式问题。<sup>[16](https://learn.microsoft.com/windows/deployment/planning/understanding-and-using-compatibility-fixes)</sup> Microsoft 的应用程序兼容性团队还使用静态和运行时分析工具，在新版本发布前检测可能破坏第三方应用程序的 API 变更。<sup>[17](https://blogs.windows.com/windowsexperience/2019/01/15/application-compatibility-in-the-windows-ecosystem/)</sup>

在 Windows 之外，Wine 是 Windows API 的一种实现，可作为库使用，在类 Unix 系统上运行 Windows 应用程序；它不是虚拟机，也不模拟 CPU。<sup>[6](https://citeseerx.ist.psu.edu/document?doi=b48deefde8f9f440582f0a96d59be48c3f43c128&repid=rep1&type=pdf)</sup>

## 后继 API 接口面与现状

Microsoft 曾多次尝试在 Windows API 之上添加新的 API 层。随 [Windows 8](https://www.edgepedia.org/zh/windows-8) 引入的 Windows 运行时（WinRT）是一个现代面向对象接口面，其命名空间以 `Windows.*` 开头，涵盖通知、媒体捕获、[蓝牙](https://www.edgepedia.org/zh/bluetooth)、地理位置等领域；大多数 WinRT API 可从 .NET 直接访问，不过有些在桌面应用中需要窗口句柄。<sup>[5](https://learn.microsoft.com/en-us/windows/apps/develop/interop/)</sup> 桌面应用程序即使在使用现代框架时仍经常调用 Win32 函数；例如，自定义窗口的标题栏或位置使用 `SetWindowPos`，读取系统内存使用 `GlobalMemoryStatusEx`。<sup>[5](https://learn.microsoft.com/en-us/windows/apps/develop/interop/)</sup>

较旧的接口面一直延续下来。Microsoft 的 Azure 首席技术官马克·鲁西诺维奇（Mark Russinovich）在 2026 年表示，Win32 具有持久生命力，因为它是 Windows 内部的基础层，众多技术和生态系统都建立在其上，堪称“一种基石”，而试图重启 Windows API 接口面的尝试，例如 WinRT，“并没有像许多人预期的那样发展”。<sup>[18](https://www.tomshardware.com/software/windows/microsoft-cto-confesses-that-30-year-old-code-from-the-mid-90s-still-forms-the-bedrock-of-windows-11-ancient-win32-api-still-the-backbone-but-cto-says-its-more-relevant-than-ever-in-2026)</sup> 新的 Win32 API 仍在不断添加；2026 年 8 月的 Windows SDK 预览版本新增了多项内容，其中包括一个 Direct3D 12 `ID3D12DeviceStatistics` 接口和一个 AV1 编码器运行模式编解码器 API。<sup>[19](https://learn.microsoft.com/en-us/windows/apps/whats-new/whats-new-for-developers?view=winui-2.4)</sup>

## References

1. [Windows API index, Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-api-list)
2. [Windows NT 3.1, Computer History Wiki](https://gunkies.org/wiki/Windows_NT_3.1)
3. [Diomidis Spinellis (1997). A Critique of the Windows Application Programming Interface](https://www.spinellis.gr/pubs/jrnl/1997-CSI-WinApi/html/win.pdf)
4. [Abstract Data Models, Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/winprog64/abstract-data-models)
5. [Choose your interop approach for Windows apps, Microsoft Learn](https://learn.microsoft.com/en-us/windows/apps/develop/interop/)
6. [Wine Developer's Guide](https://citeseerx.ist.psu.edu/document?doi=b48deefde8f9f440582f0a96d59be48c3f43c128&repid=rep1&type=pdf)
7. [Overview of Windows (excerpt defining Win16 and Win32), Wiley](https://catalogimages.wiley.com/images/db/pdf/9780470041802.excerpt.pdf)
8. [The History of Microsoft – 1992, Microsoft Learn](https://learn.microsoft.com/en-us/shows/history/history-of-microsoft-1992)
9. [Windows Native API Programming (introduction)](https://xn--lcss68aj21b.xn--w8je.xn--tckwe/books/windowsnativeapiprogramming.pdf)
10. [Libraries and Headers, Windows drivers, Microsoft Learn](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/libraries-and-headers)
11. [User Mode and Kernel Mode, Microsoft Learn](https://learn.microsoft.com/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode)
12. [Windows API sets, Microsoft Learn](https://learn.microsoft.com/windows/win32/apiindex/windows-apisets)
13. [About Windows, Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/winmsg/about-windows)
14. [Programming reference for the Win32 API, Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/api/)
15. [A critique of the Windows Application Programming Interface, ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0920548998000129)
16. [Understanding and Using Compatibility Fixes, Microsoft Learn](https://learn.microsoft.com/windows/deployment/planning/understanding-and-using-compatibility-fixes)
17. [Application compatibility in the Windows ecosystem, Windows Experience Blog](https://blogs.windows.com/windowsexperience/2019/01/15/application-compatibility-in-the-windows-ecosystem/)
18. [Microsoft CTO on Win32 as the bedrock of Windows 11, Tom's Hardware](https://www.tomshardware.com/software/windows/microsoft-cto-confesses-that-30-year-old-code-from-the-mid-90s-still-forms-the-bedrock-of-windows-11-ancient-win32-api-still-the-backbone-but-cto-says-its-more-relevant-than-ever-in-2026)
19. [What's new: SDK, WinUI, tools, Microsoft Learn](https://learn.microsoft.com/en-us/windows/apps/whats-new/whats-new-for-developers?view=winui-2.4)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Frameworks, libraries, and APIs › Mobile and platform frameworks

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/windows-api

English original: https://www.edgepedia.org/windows-api
