Jump to content

windows.h

From Wikipedia, the free encyclopedia

<windows.h> is a source code header file that Microsoft provides for the development of programs that access the Windows API (WinAPI) via C language. It declares the WinAPI functions, associated data types and common macros.

Access to WinAPI can be enabled for a C or C++ program by including it into a source file:

#include <windows.h>

Also, the executable must be linked to each static library that either contains the function code or more commonly defines runtime, dynamic linking to a system dynamic link library (DLL). Generally, for functions in a DLL named like Abc.dll, the program must be linked to a library named like Abc.lib. For MinGW, the library name is like libAbc.dll.a.

<windows.h> is a large header file and is often consumed as a precompiled header[1]; however, when imported as a header unit (import <windows.h>;), it is prone to bugs and macro collisions (as <windows.h> defines function-like macros like min() and max() which clash with the standard library).

Included header files

[edit]

Including <windows.h> results in including various other header files that are included directly or indirectly by <windows.h>. Many of these header files cannot be included on their own due to dependencies between the various header files.

Notable included header files:

Standard C

[edit]
NameDescription
<ctype.h>character classification
<stdarg.h>variable-argument function support
<string.h>string and buffer manipulation

Basic

[edit]
NameDescription
<basetsd.h>various types[2]
<guiddef.h>the GUID[3]
<imm.h>Input Method Editor (IME)
<winbase.h>kernel32.dll: kernel services; advapi32.dll: kernel services (e.g. CreateProcessAsUser() function), access control (e.g. AdjustTokenGroups() function).
<wincon.h>console services
<windef.h>various macros and types
<winerror.h>error codes[4]
<wingdi.h>Graphics Device Interface (GDI)[5]
<winnetwk.h>Windows Networking (WNet)[6]
<winnls.h>Native Language Support (NLS)
<winnt.h>various macros and types (for Windows NT)[7]
<winreg.h>Windows registry[8]
<winsvc.h>Windows services and the Service Control Manager (SCM)
<winuser.h>Calls on user32.dll for user services, inline resource macro (e.g. MAKEINTRESOURCE macro[9]), inline dialog macro(e.g. DialogBox function[10]).[11]
<winver.h>version information[12]

Extra

[edit]
NameDescription
<cderr.h>CommDlgExtendedError function error codes
<commldg.h>Common Dialog Boxes
<dde.h>DDE (Dynamic Data Exchange)
<ddeml.h>DDE Management Library
<dlgs.h>various constants for Common Dialog Boxes
<lzexpand.h>LZ (Lempel-Ziv) compression/decompression
<mmsystem.h>Windows Multimedia
<nb30.h>NetBIOS
<rpc.h>RPC (Remote procedure call)
<shellapi.h>Windows Shell API
<wincrypt.h>Cryptographic API
<winperf.h>Performance monitoring
<winresrc.h>used in resources
<winsock.h>Winsock (Windows Sockets), version 1.1
<winspool.h>Print Spooler
<winbgim.h>Standard graphics library

OLE and COM

[edit]
NameDescription
<ole2.h>OLE (Object Linking and Embedding)
<objbase.h>COM (Component Object Model)
<oleauto.h>OLE Automation
<oletlid.h>various GUID definitions

Macros

[edit]

Several macros affect the definitions made by <windows.h> and the files it includes.

  • UNICODE; when defined, this causes the generic text datatype TCHAR to be a synonym of WCHAR instead of CHAR,[2] and all type-generic API functions and messages that work with text will be defined to the -W versions instead of the -A versions. It is similar to the windows C runtime's _UNICODE macro.
  • RC_INVOKED defined when the resource compiler (RC.EXE) is in use instead of a C compiler.
  • WINVER used to enable features only available in newer operating systems. Define it to 0x0501 for Windows XP, and 0x0600 for Windows Vista.
  • WIN32_LEAN_AND_MEAN used to reduce the size of the header files and speed up compilation. Excludes things like cryptography, DDE, RPC, the Windows Shell and Winsock.

Other languages

[edit]

Microsoft has plans to update the Windows API for modern C++ usage with their win32metadata project.[13] Currently, there is C++/WinRT and "Windows Implementation Library" (WIL) for doing this in modern C++. Microsoft has also created bindings for other languages, including C# and Rust for calling the Win32 API.[14]

See also

[edit]

References

[edit]
  1. ↑ NI (21 February 2023). "Precompiled Headers". ni.com. NI (Emerson).
  2. 1 2 "Windows Data Types". learn.microsoft.com. 7 November 2024.
  3. ↑ "guiddef.h header". learn.microsoft.com. 23 January 2023.
  4. ↑ "winerror.h header". learn.microsoft.com. 23 January 2023.
  5. ↑ "wingdi.h header". learn.microsoft.com. 23 January 2023.
  6. ↑ "winnetwk.h header". learn.microsoft.com. 23 January 2023.
  7. ↑ "winnt.h header". learn.microsoft.com. 23 January 2023.
  8. ↑ "winreg.h header". learn.microsoft.com. 23 January 2023.
  9. ↑ "MAKEINTRESOURCEA macro (winuser.h)". learn.microsoft.com. 19 November 2024.
  10. ↑ "DialogBoxA macro (winuser.h)". learn.microsoft.com. 22 February 2024.
  11. ↑ "winuser.h header". learn.microsoft.com. 23 January 2023.
  12. ↑ "winver.h header". learn.microsoft.com. 23 January 2023.
  13. ↑ "Making Win32 APIs More Accessible to More Languages". blogs.windows.com. 21 January 2021.
  14. ↑ "win32metadata". Retrieved 4 September 2025.