From e94fa3fa267aeaa14399300716caa0b301a475ca Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 14 Jun 2019 15:34:25 +0200 Subject: [PATCH] Switch to WinStd library Signed-off-by: Simon Rozman --- .gitmodules | 3 + WLANSetEAPUserData.sln | 22 +++ WLANSetEAPUserData/WLANSetEAPUserData.cpp | 22 ++- WLANSetEAPUserData/WLANSetEAPUserData.h | 161 ------------------ WLANSetEAPUserData/WLANSetEAPUserData.props | 1 + WLANSetEAPUserData/WLANSetEAPUserData.vcxproj | 6 +- .../WLANSetEAPUserData.vcxproj.filters | 3 - lib/WinStd | 1 + 8 files changed, 42 insertions(+), 177 deletions(-) create mode 100644 .gitmodules delete mode 100644 WLANSetEAPUserData/WLANSetEAPUserData.h create mode 160000 lib/WinStd diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..18e30a9 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/WinStd"] + path = lib/WinStd + url = https://github.com/Amebis/WinStd.git diff --git a/WLANSetEAPUserData.sln b/WLANSetEAPUserData.sln index c7b258a..e0782ae 100644 --- a/WLANSetEAPUserData.sln +++ b/WLANSetEAPUserData.sln @@ -10,6 +10,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{943F6F19-535F-4DD8-A5BA-5033B4E2EFF5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinStd", "lib\WinStd\build\WinStd-16.0.vcxproj", "{47399D91-7EB9-41DE-B521-514BA5DB0C43}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -32,8 +36,26 @@ Global {EC3084A5-CA18-498B-A962-5321AE37789B}.Release|Win32.Build.0 = Release|Win32 {EC3084A5-CA18-498B-A962-5321AE37789B}.Release|x64.ActiveCfg = Release|x64 {EC3084A5-CA18-498B-A962-5321AE37789B}.Release|x64.Build.0 = Release|x64 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|ARM64.Build.0 = Debug|ARM64 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|Win32.ActiveCfg = Debug|Win32 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|Win32.Build.0 = Debug|Win32 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|x64.ActiveCfg = Debug|x64 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|x64.Build.0 = Debug|x64 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|ARM64.ActiveCfg = Release|ARM64 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|ARM64.Build.0 = Release|ARM64 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|Win32.ActiveCfg = Release|Win32 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|Win32.Build.0 = Release|Win32 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|x64.ActiveCfg = Release|x64 + {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {47399D91-7EB9-41DE-B521-514BA5DB0C43} = {943F6F19-535F-4DD8-A5BA-5033B4E2EFF5} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1B6BEEAC-F963-4C30-A460-9EE887768FC3} + EndGlobalSection EndGlobal diff --git a/WLANSetEAPUserData/WLANSetEAPUserData.cpp b/WLANSetEAPUserData/WLANSetEAPUserData.cpp index 6d2894e..e804a50 100644 --- a/WLANSetEAPUserData/WLANSetEAPUserData.cpp +++ b/WLANSetEAPUserData/WLANSetEAPUserData.cpp @@ -17,7 +17,9 @@ along with WLANSetEAPUserData. If not, see . */ -#include "WLANSetEAPUserData.h" +#include +#include +#include #include #include #include @@ -33,6 +35,7 @@ #pragma comment(lib, "Wlanapi.lib") using namespace std; +using namespace winstd; /// @@ -105,22 +108,17 @@ int CALLBACK WinMain( // Open WLAN handle. DWORD dwNegotiatedVersion; - unique_ptr wlan; - { - HANDLE hWlan; - DWORD dwResult = WlanOpenHandle(WLAN_API_MAKE_VERSION(2, 0), NULL, &dwNegotiatedVersion, &hWlan); - if (dwResult != ERROR_SUCCESS) { - //_ftprintf(stderr, _T("WlanOpenHandle() failed (error %u).\n"), dwResult); - return 400; - } - wlan.reset(hWlan); + wlan_handle wlan; + if (!wlan.open(WLAN_API_MAKE_VERSION(2, 0), &dwNegotiatedVersion)) { + //_ftprintf(stderr, _T("WlanOpenHandle() failed (error %u).\n"), GetLastError()); + return 400; } // Get a list of WLAN interfaces. unique_ptr > interfaces; { WLAN_INTERFACE_INFO_LIST *pInterfaceList; - DWORD dwResult = WlanEnumInterfaces(wlan.get(), NULL, &pInterfaceList); + DWORD dwResult = WlanEnumInterfaces(wlan, NULL, &pInterfaceList); if (dwResult != ERROR_SUCCESS) { //_ftprintf(stderr, _T("WlanEnumInterfaces() failed (error %u).\n"), dwResult); return 401; @@ -138,7 +136,7 @@ int CALLBACK WinMain( // Set user data. DWORD dwResult = WlanSetProfileEapXmlUserData( - wlan.get(), + wlan, &(interfaces->InterfaceInfo[i].InterfaceGuid), pwcArglist[1], wcstoul(pwcArglist[2], NULL, 10), diff --git a/WLANSetEAPUserData/WLANSetEAPUserData.h b/WLANSetEAPUserData/WLANSetEAPUserData.h deleted file mode 100644 index 1f3457d..0000000 --- a/WLANSetEAPUserData/WLANSetEAPUserData.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - Copyright 2016-2019 Simon Rozman - - This file is part of WLANSetEAPUserData. - - WLANSetEAPUserData is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - WLANSetEAPUserData is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with WLANSetEAPUserData. If not, see . -*/ - -#pragma once - -#include - - -/// -/// Deleter for unique_ptr using LocalFree -/// -template -struct LocalFree_delete -{ - /// - /// Frees memory - /// - /// \sa [LocalFree function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366730.aspx) - /// - inline void operator()(_Ty *_Ptr) const - { - LocalFree(_Ptr); - } -}; - - -/// -/// Deleter for unique_ptr to array of unknown size using LocalFree -/// -template -struct LocalFree_delete<_Ty[]> -{ - /// - /// Frees memory - /// - inline void operator()(_Frees_ptr_opt_ _Ty *_Ptr) const noexcept - { - LocalFree(_Ptr); - } - - /// - /// Frees memory - /// - /// \sa [LocalFree function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366730.aspx) - /// - template - inline void operator()(_Other *) const - { - LocalFree(_Ptr); - } -}; - - -#include - -/// -/// Context scope automatic COM (un)initialization -/// -class com_initializer -{ -public: - /// - /// Initializes the COM library on the current thread and identifies the concurrency model as single-thread apartment (STA). - /// - /// \sa [CoInitialize function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms678543.aspx) - /// - inline com_initializer(_In_opt_ LPVOID pvReserved) noexcept - { - m_result = CoInitialize(pvReserved); - } - - - /// - /// Initializes the COM library for use by the calling thread, sets the thread's concurrency model, and creates a new apartment for the thread if one is required. - /// - /// \sa [CoInitializeEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms695279.aspx) - /// - inline com_initializer(_In_opt_ LPVOID pvReserved, _In_ DWORD dwCoInit) noexcept - { - m_result = CoInitializeEx(pvReserved, dwCoInit); - } - - - /// - /// Uninitializes COM. - /// - /// \sa [CoUninitialize function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms688715.aspx) - /// - virtual ~com_initializer() - { - if (SUCCEEDED(m_result)) - CoUninitialize(); - } - - - /// - /// Return result of `CoInitialize()` call. - /// - /// \sa [CoInitialize function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms678543.aspx) - /// - inline HRESULT status() const noexcept - { - return m_result; - } - -protected: - HRESULT m_result; ///< Result of CoInitialize call -}; - - -#include - -/// -/// Deleter for unique_ptr using WlanCloseHandle -/// -struct WlanCloseHandle_delete -{ - /// - /// Closes the WLAN handle - /// - /// \sa [WlanCloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706610.aspx) - /// - inline void operator()(void *_Ptr) const noexcept - { - WlanCloseHandle(_Ptr, NULL); - } -}; - - -/// -/// Deleter for unique_ptr using WlanFreeMemory -/// -template -struct WlanFreeMemory_delete -{ - /// - /// Frees memory - /// - /// \sa [WlanFreeMemory function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706722.aspx) - /// - void operator()(_Ty *_Ptr) const noexcept - { - WlanFreeMemory(_Ptr); - } -}; diff --git a/WLANSetEAPUserData/WLANSetEAPUserData.props b/WLANSetEAPUserData/WLANSetEAPUserData.props index abf4446..7c51f27 100644 --- a/WLANSetEAPUserData/WLANSetEAPUserData.props +++ b/WLANSetEAPUserData/WLANSetEAPUserData.props @@ -4,6 +4,7 @@ ..\output\$(Platform).$(Configuration)\ + ..\lib\WinStd\include;$(IncludePath) diff --git a/WLANSetEAPUserData/WLANSetEAPUserData.vcxproj b/WLANSetEAPUserData/WLANSetEAPUserData.vcxproj index 80b0a19..d0e7324 100644 --- a/WLANSetEAPUserData/WLANSetEAPUserData.vcxproj +++ b/WLANSetEAPUserData/WLANSetEAPUserData.vcxproj @@ -141,11 +141,15 @@ - + + + {47399d91-7eb9-41de-b521-514ba5db0c43} + + diff --git a/WLANSetEAPUserData/WLANSetEAPUserData.vcxproj.filters b/WLANSetEAPUserData/WLANSetEAPUserData.vcxproj.filters index 081ed2c..a13169d 100644 --- a/WLANSetEAPUserData/WLANSetEAPUserData.vcxproj.filters +++ b/WLANSetEAPUserData/WLANSetEAPUserData.vcxproj.filters @@ -20,9 +20,6 @@ - - Header Files - Header Files diff --git a/lib/WinStd b/lib/WinStd new file mode 160000 index 0000000..5498fb0 --- /dev/null +++ b/lib/WinStd @@ -0,0 +1 @@ +Subproject commit 5498fb0c159962802faaae7d474dd6f1d8daaffe