Switch to WinStd library
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
f35a0f4bf4
commit
e94fa3fa26
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "lib/WinStd"]
|
||||
path = lib/WinStd
|
||||
url = https://github.com/Amebis/WinStd.git
|
@ -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
|
||||
|
@ -17,7 +17,9 @@
|
||||
along with WLANSetEAPUserData. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "WLANSetEAPUserData.h"
|
||||
#include <WinStd\Com.h>
|
||||
#include <WinStd\Common.h>
|
||||
#include <WinStd\WLAN.h>
|
||||
#include <comip.h>
|
||||
#include <comutil.h>
|
||||
#include <msxml6.h>
|
||||
@ -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<void, WlanCloseHandle_delete> 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<WLAN_INTERFACE_INFO_LIST, WlanFreeMemory_delete<WLAN_INTERFACE_INFO_LIST> > 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),
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
///
|
||||
/// Deleter for unique_ptr using LocalFree
|
||||
///
|
||||
template <class _Ty>
|
||||
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 <class _Ty>
|
||||
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<class _Other>
|
||||
inline void operator()(_Other *) const
|
||||
{
|
||||
LocalFree(_Ptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#include <ObjBase.h>
|
||||
|
||||
///
|
||||
/// 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 <wlanapi.h>
|
||||
|
||||
///
|
||||
/// 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 <class _Ty>
|
||||
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);
|
||||
}
|
||||
};
|
@ -4,6 +4,7 @@
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<OutDir>..\output\$(Platform).$(Configuration)\</OutDir>
|
||||
<IncludePath>..\lib\WinStd\include;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<Link>
|
||||
|
@ -141,11 +141,15 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="WLANSetEAPUserData.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="WLANSetEAPUserData.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\lib\WinStd\build\WinStd-16.0.vcxproj">
|
||||
<Project>{47399d91-7eb9-41de-b521-514ba5db0c43}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
@ -20,9 +20,6 @@
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="WLANSetEAPUserData.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
1
lib/WinStd
Submodule
1
lib/WinStd
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 5498fb0c159962802faaae7d474dd6f1d8daaffe
|
Loading…
x
Reference in New Issue
Block a user