Additional support for working with WLAN added
This commit is contained in:
@@ -34,6 +34,23 @@ extern DWORD (WINAPI *pfnWlanReasonCodeToString)(__in DWORD dwReasonCode, __in D
|
||||
///
|
||||
/// @{
|
||||
|
||||
namespace winstd {
|
||||
///
|
||||
/// Deleter for unique_ptr using WlanFreeMemory
|
||||
///
|
||||
template <class _Ty> struct WlanFreeMemory_delete;
|
||||
|
||||
///
|
||||
/// Deleter for unique_ptr to array of unknown size using WlanFreeMemory
|
||||
///
|
||||
template <class _Ty> struct WlanFreeMemory_delete<_Ty[]>;
|
||||
|
||||
///
|
||||
/// WLAN handle wrapper
|
||||
///
|
||||
class WINSTD_API wlan_handle;
|
||||
}
|
||||
|
||||
///
|
||||
/// Retrieves a string that describes a specified reason code and stores it in a std::wstring string.
|
||||
///
|
||||
@@ -50,6 +67,140 @@ template<class _Elem, class _Traits, class _Ax> inline DWORD WlanReasonCodeToStr
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace winstd
|
||||
{
|
||||
template <class _Ty> struct WlanFreeMemory_delete
|
||||
{
|
||||
typedef WlanFreeMemory_delete<_Ty> _Myt; ///< This type
|
||||
|
||||
///
|
||||
/// Default construct
|
||||
///
|
||||
WlanFreeMemory_delete() {}
|
||||
|
||||
///
|
||||
/// Construct from another WlanFreeMemory_delete
|
||||
///
|
||||
template <class _Ty2> WlanFreeMemory_delete(const WlanFreeMemory_delete<_Ty2>&) {}
|
||||
|
||||
///
|
||||
/// Delete a pointer
|
||||
///
|
||||
void operator()(_Ty *_Ptr) const
|
||||
{
|
||||
WlanFreeMemory(_Ptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class _Ty> struct WlanFreeMemory_delete<_Ty[]>
|
||||
{
|
||||
typedef WlanFreeMemory_delete<_Ty> _Myt; ///< This type
|
||||
|
||||
///
|
||||
/// Default construct
|
||||
///
|
||||
WlanFreeMemory_delete() {}
|
||||
|
||||
///
|
||||
/// Delete a pointer
|
||||
///
|
||||
void operator()(_Ty *_Ptr) const
|
||||
{
|
||||
WlanFreeMemory(_Ptr);
|
||||
}
|
||||
|
||||
///
|
||||
/// Delete a pointer of another type
|
||||
///
|
||||
template<class _Other>
|
||||
void operator()(_Other *) const
|
||||
{
|
||||
WlanFreeMemory(_Ptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class WINSTD_API wlan_handle : public handle<HANDLE>
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Initializes a new class instance with the object handle set to NULL.
|
||||
///
|
||||
inline wlan_handle() : handle<HANDLE>() {}
|
||||
|
||||
///
|
||||
/// Initializes a new class instance with an already available object handle.
|
||||
///
|
||||
/// \param[in] h Initial object handle value
|
||||
///
|
||||
inline wlan_handle(_In_opt_ handle_type h) : handle<HANDLE>(h) {}
|
||||
|
||||
///
|
||||
/// Move constructor
|
||||
///
|
||||
/// \param[inout] h A rvalue reference of another object
|
||||
///
|
||||
inline wlan_handle(_Inout_ wlan_handle &&h) : handle<HANDLE>(std::move(h)) {}
|
||||
|
||||
///
|
||||
/// Closes a connection to the server.
|
||||
///
|
||||
/// \sa [WlanCloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706610(v=vs.85).aspx)
|
||||
///
|
||||
virtual ~wlan_handle();
|
||||
|
||||
///
|
||||
/// Move assignment
|
||||
///
|
||||
/// \param[inout] h A rvalue reference of another object
|
||||
///
|
||||
wlan_handle& operator=(_Inout_ wlan_handle &&h)
|
||||
{
|
||||
if (this != std::addressof(h))
|
||||
*(handle<handle_type>*)this = std::move(h);
|
||||
return *this;
|
||||
}
|
||||
|
||||
///
|
||||
/// Opens a connection to the server.
|
||||
///
|
||||
/// \sa [WlanOpenHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706759.aspx)
|
||||
///
|
||||
/// \return
|
||||
/// - \c true when succeeds;
|
||||
/// - \c false when fails. Use `GetLastError()` for failure reason.
|
||||
///
|
||||
inline bool open(_In_ DWORD dwClientVersion, _Out_ PDWORD pdwNegotiatedVersion)
|
||||
{
|
||||
handle_type h;
|
||||
DWORD dwResult = WlanOpenHandle(dwClientVersion, 0, pdwNegotiatedVersion, &h);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
attach(h);
|
||||
return true;
|
||||
} else {
|
||||
SetLastError(dwResult);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
// This class is noncopyable.
|
||||
wlan_handle(_In_ const wlan_handle &h);
|
||||
wlan_handle& operator=(_In_ const wlan_handle &h);
|
||||
|
||||
protected:
|
||||
///
|
||||
/// Closes a connection to the server.
|
||||
///
|
||||
/// \sa [WlanCloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706610(v=vs.85).aspx)
|
||||
///
|
||||
virtual void free_internal();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
template<class _Elem, class _Traits, class _Ax>
|
||||
inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue, __reserved PVOID pReserved)
|
||||
{
|
||||
|
Reference in New Issue
Block a user