winapi/doc/winapi.qbk
2018-03-18 01:42:55 +03:00

90 lines
8.0 KiB
Plaintext

[/
Copyright (c) 2016-2018 Andrey Semashev
Distributed under the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt
or copy at http://boost.org/LICENSE_1_0.txt)
]
[library Boost.WinAPI
[quickbook 1.6]
[id winapi]
[copyright 2016-2018 Andrey Semashev]
[dirname winapi]
[license Distributed under the [@http://boost.org/LICENSE_1_0.txt Boost Software License, Version 1.0].]
]
[section:intro Introduction]
The Boost.WinAPI library is an abstraction layer for Windows API intended to be used internally by other Boost libraries. Boost.WinAPI is not a public library for users of Boost.
The main advantages of using Boost.WinAPI instead of Windows API directly are:
* Avoid including `<windows.h>` or other Windows SDK headers in public headers of your library. Windows SDK headers are known to be dependent on a large number of configuration macros that have to be defined by the user. If your library depends on a particular API, you may not be able to rely on it being enabled by the user. On the other hand, your library cannot enforce particular Windows SDK configuration because (a) Windows SDK headers may be included before your library headers with a different set of config macros and (b) because your desired configuration may be incompatible with that of the user's code.
* Avoid dealing with lots of macros defined by Windows SDK headers.
* More fine grained control of the API you include in your headers.
* Allow to select the target Windows version for Boost. This version can be different from the version user's code targets.
* Better compatibility with different implementations of Windows SDK, like MinGW and MinGW-w64.
The implementation of Boost.WinAPI consists of a number of declarations of functions, types and constants mimicking the real declarations in Windows SDK. In some cases simple inline function wrappers are provided. As a result the runtime performance impact of Boost.WinAPI should be zero. Boost.WinAPI only depends on Boost.Config and Boost.Predef and is compatible with C++03 compilers.
[endsect]
[section:config Configuration]
Boost.WinAPI recognizes the following configuration macros:
[table Configuration macros
[[Macro name] [Effect]]
[[`BOOST_USE_WINAPI_VERSION`] [If defined, designates the target Windows API version. The version should be given as hexadecimal integer, same as the `_WIN32_WINNT` macro values. Some of the versions are given [@https://msdn.microsoft.com/en-us/library/aa383745(v=vs.100).aspx#macros_for_conditional_declarations here]. If the macro is not defined, the version is deduced from `_WIN32_WINNT` and `WINVER` macros, if they are defined, or the default version is chosen. The default version is currently Windows Vista/Server 2008 on compilers that support this version of SDK and Windows XP on others. The default may change in future releases.]]
[[`BOOST_USE_NTDDI_VERSION`] [If defined, designates the target Windows API version down to a particular Service Pack. This macro offers a more fine grained way to define the target Windows version than `BOOST_USE_WINAPI_VERSION`. The version should be given as hexadecimal integer, same as the `NTDDI_VERSION` macro values. Some of the versions are given [@https://msdn.microsoft.com/en-us/library/aa383745(v=vs.100).aspx#macros_for_conditional_declarations here]. If the macro is not defined, the version is deduced from `NTDDI_VERSION` and `BOOST_USE_WINAPI_VERSION` macros, in the latter case defaulting to the latest revision of the indicated Windows version. If `BOOST_USE_NTDDI_VERSION` is defined, `BOOST_USE_WINAPI_VERSION` is also expected to be defined to a corresponding value.]]
[[`BOOST_USE_WINAPI_FAMILY`] [If defined, designates the Windows API family to use. The family can be set to one of the values of the `WINAPI_FAMILY`.]]
[[`BOOST_USE_WINDOWS_H`] [This macro is part of Boost.Config. If defined, Boost.WinAPI will include `<windows.h>` and any other headers from Windows SDK as needed. Otherwise Boost.WinAPI will provide its own declarations of the SDK components as needed without including SDK headers.]]
[[`BOOST_NO_ANSI_APIS`] [This macro is defined by Boost.Config on platforms that do not support narrow-character versions of some APIs. Boost.WinAPI will not declare narrow-character APIs when this macro is defined.]]
]
User's code can include `<boost/winapi/config.hpp>` to define a number of macros that can be useful. Including this header is recommended in any code that involves Windows API usage.
[table Defined configuration macros
[[Macro name] [Effect]]
[[`BOOST_USE_WINAPI_VERSION`,[br]`BOOST_USE_NTDDI_VERSION`]
[If not defined by user, these macros are defined by the header to the target Windows API version.]]
[[`BOOST_WINAPI_VERSION_NT4`,[br]`BOOST_WINAPI_VERSION_WIN2K`,[br]`BOOST_WINAPI_VERSION_WINXP`,[br]`BOOST_WINAPI_VERSION_WS03`,[br]`BOOST_WINAPI_VERSION_WIN6`,[br]`BOOST_WINAPI_VERSION_VISTA`,[br]`BOOST_WINAPI_VERSION_WS08`,[br]`BOOST_WINAPI_VERSION_LONGHORN`,[br]`BOOST_WINAPI_VERSION_WIN7`,[br]`BOOST_WINAPI_VERSION_WIN8`,[br]`BOOST_WINAPI_VERSION_WINBLUE`,[br]`BOOST_WINAPI_VERSION_WINTHRESHOLD`,[br]`BOOST_WINAPI_VERSION_WIN10`]
[These macros expand to the constants designating the particular Windows versions and can be used together with `BOOST_USE_WINAPI_VERSION` in preprocessor version checks.]]
[[`BOOST_WINAPI_IS_MINGW`] [Defined if Windows SDK is provided by [@http://mingw.org/ MinGW].]]
[[`BOOST_WINAPI_IS_MINGW_W64`] [Defined if Windows SDK is provided by [@http://mingw-w64.org MinGW-w64]. Note that is does not mean that the code is compiled for 64-bit Windows.]]
[[`BOOST_WINAPI_IS_CYGWIN`] [Defined if Windows SDK is provided by MinGW variant from [@https://cygwin.com/ Cygwin].]]
]
[endsect]
[section:usage Using Boost.WinAPI]
In order to use Boost.WinAPI you have to include one or several headers from the `boost/winapi` directory. Each header there defines a portion of Windows API, the name of the header should be self-explanatory. Each Boost.WinAPI header may declare a number of symbols like functions and types in the global namespace, mimicking the Windows SDK, and the corresponding set of symbols in the `boost::winapi` namespace. User's code is supposed to use the symbols from the `boost::winapi` namespace only.
Most of the functions in the `boost::winapi` have the same name and meaning as the corresponding Windows API functions. Types and constants have a trailing underscore ('_') in their name to avoid clashes with macros that are defined in Windows SDK.
[note Boost.WinAPI does not define function-name macros that expand to the `char` or `wchar_t` based functions depending on the `UNICODE` macro. Boost.WinAPI also does not support `_TCHAR` and related string types. Users have to explicitly use the `*A` or `*W` functions with appropriate argument types. Note however that `*A` functions may not be available if `BOOST_NO_ANSI_APIS` is defined.]
For example, here is how one would create and destroy a semaphore with Boost.WinAPI:
#include <limits>
#include <boost/winapi/handles.hpp>
#include <boost/winapi/semaphore.hpp>
boost::winapi::HANDLE_ h = boost::winapi::CreateSemaphoreExW(
NULL, // security attributes
0l, // initial count
std::numeric_limits< boost::winapi::LONG_ >::max(), // max count
L"Local\\MySemaphore", // semaphore name
0l, // flags
boost::winapi::SEMAPHORE_ALL_ACCESS_ // access mode
);
if (h)
boost::winapi::CloseHandle(h);
Refer to [@https://msdn.microsoft.com/library MSDN] for documentation on the particular functions, types and constants.
[endsect]