From 0e38debecbfa0d1dcb68f133433ea21273bd9fe8 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 11 Mar 2016 12:29:42 +0100 Subject: [PATCH] Wlanapi.dll is accessed dynamically now (since not present on Windows Server by default) --- include/atlex/atlwlan.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/include/atlex/atlwlan.h b/include/atlex/atlwlan.h index 26b198a..0e2eba0 100644 --- a/include/atlex/atlwlan.h +++ b/include/atlex/atlwlan.h @@ -22,6 +22,12 @@ #include #include + +// Must not statically link to Wlanapi.dll as it is not available on Windows +// without a WLAN interface. +extern DWORD (WINAPI *pfnWlanReasonCodeToString)(__in DWORD dwReasonCode, __in DWORD dwBufferSize, __in_ecount(dwBufferSize) PWCHAR pStringBuffer, __reserved PVOID pReserved); + + /// /// \defgroup ATLWLANAPI WLAN API /// Integrates ATL classes with Microsoft WLAN API @@ -33,17 +39,24 @@ /// /// \sa [WlanReasonCodeToString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706768.aspx) /// +/// \note +/// Since Wlanapi.dll is not always present, the \c pfnWlanReasonCodeToString pointer to \c WlanReasonCodeToString +/// function must be loaded dynamically. +/// inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Out_ ATL::CAtlStringW &sValue, __reserved PVOID pReserved) { DWORD dwSize = 0; + if (!::pfnWlanReasonCodeToString) + return ERROR_CALL_NOT_IMPLEMENTED; + for (;;) { // Increment size and allocate buffer. LPWSTR szBuffer = sValue.GetBuffer(dwSize += 1024); if (!szBuffer) return ERROR_OUTOFMEMORY; // Try! - DWORD dwResult = ::WlanReasonCodeToString(dwReasonCode, dwSize, szBuffer, pReserved); + DWORD dwResult = ::pfnWlanReasonCodeToString(dwReasonCode, dwSize, szBuffer, pReserved); if (dwResult == NO_ERROR) { DWORD dwLength = (DWORD)wcsnlen(szBuffer, dwSize); sValue.ReleaseBuffer(dwLength++);