2 Copyright 1991-2017 Amebis
4 This file is part of atlex.
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.
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.
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/>.
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
);
32 /// \defgroup ATLWLANAPI WLAN API
33 /// Integrates ATL classes with Microsoft WLAN API
38 /// Retrieves a string that describes a specified reason code and stores it in a ATL::CAtlStringW string.
40 /// \sa [WlanReasonCodeToString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706768.aspx)
43 /// Since Wlanapi.dll is not always present, the \c pfnWlanReasonCodeToString pointer to \c WlanReasonCodeToString
44 /// function must be loaded dynamically.
46 inline DWORD
WlanReasonCodeToString(_In_ DWORD dwReasonCode
, _Out_
ATL::CAtlStringW
&sValue
, __reserved PVOID pReserved
)
50 if (!::pfnWlanReasonCodeToString
)
51 return ERROR_CALL_NOT_IMPLEMENTED
;
54 // Increment size and allocate buffer.
55 LPWSTR szBuffer
= sValue
.GetBuffer(dwSize
+= 1024);
56 if (!szBuffer
) return ERROR_OUTOFMEMORY
;
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.
66 } else if (dwLength
< dwSize
) {
67 // Buffer was long enough to get entire string, and has some extra space left.
73 sValue
.ReleaseBuffer(0);