win_wlanLibrary.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #pragma once
  7. // Moz headers (alphabetical)
  8. // System headers (alphabetical)
  9. #include <windows.h> // HINSTANCE, HANDLE
  10. #include <wlanapi.h> // Wlan* functions
  11. class WinWLANLibrary {
  12. public:
  13. static WinWLANLibrary* Load();
  14. ~WinWLANLibrary();
  15. HANDLE GetWLANHandle() const;
  16. decltype(::WlanEnumInterfaces)* GetWlanEnumInterfacesPtr() const;
  17. decltype(::WlanGetNetworkBssList)* GetWlanGetNetworkBssListPtr() const;
  18. decltype(::WlanFreeMemory)* GetWlanFreeMemoryPtr() const;
  19. decltype(::WlanCloseHandle)* GetWlanCloseHandlePtr() const;
  20. decltype(::WlanOpenHandle)* GetWlanOpenHandlePtr() const;
  21. decltype(::WlanRegisterNotification)* GetWlanRegisterNotificationPtr() const;
  22. decltype(::WlanScan)* GetWlanScanPtr() const;
  23. private:
  24. WinWLANLibrary();
  25. bool Initialize();
  26. HMODULE mWlanLibrary;
  27. HANDLE mWlanHandle;
  28. decltype(::WlanEnumInterfaces)* mWlanEnumInterfacesPtr;
  29. decltype(::WlanGetNetworkBssList)* mWlanGetNetworkBssListPtr;
  30. decltype(::WlanFreeMemory)* mWlanFreeMemoryPtr;
  31. decltype(::WlanCloseHandle)* mWlanCloseHandlePtr;
  32. decltype(::WlanOpenHandle)* mWlanOpenHandlePtr;
  33. decltype(::WlanRegisterNotification)* mWlanRegisterNotificationPtr;
  34. decltype(::WlanScan)* mWlanScanPtr;
  35. };
  36. class ScopedWLANObject {
  37. public:
  38. ScopedWLANObject(WinWLANLibrary* library, void* object)
  39. : mLibrary(library)
  40. , mObject(object)
  41. {
  42. }
  43. ~ScopedWLANObject()
  44. {
  45. (*(mLibrary->GetWlanFreeMemoryPtr()))(mObject);
  46. }
  47. private:
  48. WinWLANLibrary *mLibrary;
  49. void *mObject;
  50. };