[SDK] Added atlex for future use
[reactos.git] / reactos / sdk / include / reactos / atlex / atlwlan.h
1 /*
2 Copyright 1991-2017 Amebis
3
4 This file is part of atlex.
5
6 Setup is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Setup is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Setup. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #pragma once
21
22 #include <atlstr.h>
23 #include <wlanapi.h>
24
25
26 // Must not statically link to Wlanapi.dll as it is not available on Windows
27 // without a WLAN interface.
28 extern DWORD (WINAPI *pfnWlanReasonCodeToString)(__in DWORD dwReasonCode, __in DWORD dwBufferSize, __in_ecount(dwBufferSize) PWCHAR pStringBuffer, __reserved PVOID pReserved);
29
30
31 ///
32 /// \defgroup ATLWLANAPI WLAN API
33 /// Integrates ATL classes with Microsoft WLAN API
34 ///
35 /// @{
36
37 ///
38 /// Retrieves a string that describes a specified reason code and stores it in a ATL::CAtlStringW string.
39 ///
40 /// \sa [WlanReasonCodeToString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706768.aspx)
41 ///
42 /// \note
43 /// Since Wlanapi.dll is not always present, the \c pfnWlanReasonCodeToString pointer to \c WlanReasonCodeToString
44 /// function must be loaded dynamically.
45 ///
46 inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Out_ ATL::CAtlStringW &sValue, __reserved PVOID pReserved)
47 {
48 DWORD dwSize = 0;
49
50 if (!::pfnWlanReasonCodeToString)
51 return ERROR_CALL_NOT_IMPLEMENTED;
52
53 for (;;) {
54 // Increment size and allocate buffer.
55 LPWSTR szBuffer = sValue.GetBuffer(dwSize += 1024);
56 if (!szBuffer) return ERROR_OUTOFMEMORY;
57
58 // Try!
59 DWORD dwResult = ::pfnWlanReasonCodeToString(dwReasonCode, dwSize, szBuffer, pReserved);
60 if (dwResult == NO_ERROR) {
61 DWORD dwLength = (DWORD)wcsnlen(szBuffer, dwSize);
62 sValue.ReleaseBuffer(dwLength++);
63 if (dwLength == dwSize) {
64 // Buffer was long exactly enough.
65 return NO_ERROR;
66 } else if (dwLength < dwSize) {
67 // Buffer was long enough to get entire string, and has some extra space left.
68 sValue.FreeExtra();
69 return NO_ERROR;
70 }
71 } else {
72 // Return error code.
73 sValue.ReleaseBuffer(0);
74 return dwResult;
75 }
76 }
77 }
78
79 /// @}