Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sts=2 sw=2 et cin: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#pragma once
8
9
// Moz headers (alphabetical)
10
11
// System headers (alphabetical)
12
#include <windows.h> // HINSTANCE, HANDLE
13
#include <wlanapi.h> // Wlan* functions
14
15
class WinWLANLibrary {
16
public:
17
static WinWLANLibrary* Load();
18
~WinWLANLibrary();
19
20
HANDLE GetWLANHandle() const;
21
decltype(::WlanEnumInterfaces)* GetWlanEnumInterfacesPtr() const;
22
decltype(::WlanGetNetworkBssList)* GetWlanGetNetworkBssListPtr() const;
23
decltype(::WlanFreeMemory)* GetWlanFreeMemoryPtr() const;
24
decltype(::WlanCloseHandle)* GetWlanCloseHandlePtr() const;
25
decltype(::WlanOpenHandle)* GetWlanOpenHandlePtr() const;
26
decltype(::WlanRegisterNotification)* GetWlanRegisterNotificationPtr() const;
27
decltype(::WlanScan)* GetWlanScanPtr() const;
28
29
private:
30
WinWLANLibrary();
31
bool Initialize();
32
33
HMODULE mWlanLibrary;
34
HANDLE mWlanHandle;
35
decltype(::WlanEnumInterfaces)* mWlanEnumInterfacesPtr;
36
decltype(::WlanGetNetworkBssList)* mWlanGetNetworkBssListPtr;
37
decltype(::WlanFreeMemory)* mWlanFreeMemoryPtr;
38
decltype(::WlanCloseHandle)* mWlanCloseHandlePtr;
39
decltype(::WlanOpenHandle)* mWlanOpenHandlePtr;
40
decltype(::WlanRegisterNotification)* mWlanRegisterNotificationPtr;
41
decltype(::WlanScan)* mWlanScanPtr;
42
};
43
44
class ScopedWLANObject {
45
public:
46
ScopedWLANObject(WinWLANLibrary* library, void* object)
47
: mLibrary(library), mObject(object) {}
48
49
~ScopedWLANObject() { (*(mLibrary->GetWlanFreeMemoryPtr()))(mObject); }
50
51
private:
52
WinWLANLibrary* mLibrary;
53
void* mObject;
54
};