1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Using Boost.WinAPI</title> 5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../index.html" title="Chapter 1. Boost.WinAPI"> 8<link rel="up" href="../index.html" title="Chapter 1. Boost.WinAPI"> 9<link rel="prev" href="config.html" title="Configuration"> 10</head> 11<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 12<table cellpadding="2" width="100%"><tr> 13<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td> 14<td align="center"><a href="../../../../../index.html">Home</a></td> 15<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td> 16<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 17<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 18<td align="center"><a href="../../../../../more/index.htm">More</a></td> 19</tr></table> 20<hr> 21<div class="spirit-nav"> 22<a accesskey="p" href="config.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a> 23</div> 24<div class="section"> 25<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 26<a name="winapi.usage"></a><a class="link" href="usage.html" title="Using Boost.WinAPI">Using Boost.WinAPI</a> 27</h2></div></div></div> 28<p> 29 In order to use Boost.WinAPI you have to include one or several headers from 30 the <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">winapi</span></code> directory. Each header there defines 31 a portion of Windows API, the name of the header should be self-explanatory. 32 Each Boost.WinAPI header may declare a number of symbols like functions and 33 types in the global namespace, mimicking the Windows SDK, and the corresponding 34 set of symbols in the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">winapi</span></code> 35 namespace. User's code is supposed to use the symbols from the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">winapi</span></code> 36 namespace only. 37 </p> 38<p> 39 Most of the functions in the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">winapi</span></code> 40 have the same name and meaning as the corresponding Windows API functions. 41 Types and constants have a trailing underscore ('_') in their name to avoid 42 clashes with macros that are defined in Windows SDK. 43 </p> 44<div class="note"><table border="0" summary="Note"> 45<tr> 46<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td> 47<th align="left">Note</th> 48</tr> 49<tr><td align="left" valign="top"><p> 50 Boost.WinAPI does not define function-name macros that expand to the <code class="computeroutput"><span class="keyword">char</span></code> or <code class="computeroutput"><span class="keyword">wchar_t</span></code> 51 based functions depending on the <code class="computeroutput"><span class="identifier">UNICODE</span></code> 52 macro. Boost.WinAPI also does not support <code class="computeroutput"><span class="identifier">_TCHAR</span></code> 53 and related string types. Users have to explicitly use the <code class="computeroutput"><span class="special">*</span><span class="identifier">A</span></code> or 54 <code class="computeroutput"><span class="special">*</span><span class="identifier">W</span></code> 55 functions with appropriate argument types. Note however that <code class="computeroutput"><span class="special">*</span><span class="identifier">A</span></code> functions 56 may not be available if <code class="computeroutput"><span class="identifier">BOOST_NO_ANSI_APIS</span></code> 57 is defined. 58 </p></td></tr> 59</table></div> 60<p> 61 For example, here is how one would create and destroy a semaphore with Boost.WinAPI: 62 </p> 63<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">limits</span><span class="special">></span> 64<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">winapi</span><span class="special">/</span><span class="identifier">handles</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 65<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">winapi</span><span class="special">/</span><span class="identifier">semaphore</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 66 67<span class="identifier">boost</span><span class="special">::</span><span class="identifier">winapi</span><span class="special">::</span><span class="identifier">HANDLE_</span> <span class="identifier">h</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">winapi</span><span class="special">::</span><span class="identifier">CreateSemaphoreExW</span><span class="special">(</span> 68 <span class="identifier">NULL</span><span class="special">,</span> <span class="comment">// security attributes</span> 69 <span class="number">0l</span><span class="special">,</span> <span class="comment">// initial count</span> 70 <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">winapi</span><span class="special">::</span><span class="identifier">LONG_</span> <span class="special">>::</span><span class="identifier">max</span><span class="special">(),</span> <span class="comment">// max count</span> 71 <span class="identifier">L</span><span class="string">"Local\\MySemaphore"</span><span class="special">,</span> <span class="comment">// semaphore name</span> 72 <span class="number">0l</span><span class="special">,</span> <span class="comment">// flags</span> 73 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">winapi</span><span class="special">::</span><span class="identifier">SEMAPHORE_ALL_ACCESS_</span> <span class="comment">// access mode</span> 74<span class="special">);</span> 75 76<span class="keyword">if</span> <span class="special">(</span><span class="identifier">h</span><span class="special">)</span> 77 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">winapi</span><span class="special">::</span><span class="identifier">CloseHandle</span><span class="special">(</span><span class="identifier">h</span><span class="special">);</span> 78</pre> 79<p> 80 Refer to <a href="https://msdn.microsoft.com/library" target="_top">MSDN</a> for documentation 81 on the particular functions, types and constants. 82 </p> 83</div> 84<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 85<td align="left"></td> 86<td align="right"><div class="copyright-footer">Copyright © 2016-2018 Andrey Semashev<p> 87 Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost 88 Software License, Version 1.0</a>. 89 </p> 90</div></td> 91</tr></table> 92<hr> 93<div class="spirit-nav"> 94<a accesskey="p" href="config.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a> 95</div> 96</body> 97</html> 98