mirror of
https://github.com/microsoft/WSL.git
synced 2025-12-10 00:44:55 -06:00
cleanup: switch from Microsoft::WRL::ComPtr to wil::com_ptr (#13767)
* cleanup: switch from Microsoft::WRL::ComPtr to wil::com_ptr * reformat --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
This commit is contained in:
parent
d9c69a50ab
commit
66904342a5
@ -540,16 +540,13 @@ wsl::windows::common::SvcComm::SvcComm()
|
||||
};
|
||||
|
||||
wsl::shared::retry::RetryWithTimeout<void>(
|
||||
[this]() {
|
||||
THROW_IF_FAILED(CoCreateInstance(__uuidof(LxssUserSession), nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&m_userSession)));
|
||||
},
|
||||
[this]() { m_userSession = wil::CoCreateInstance<LxssUserSession, ILxssUserSession>(CLSCTX_LOCAL_SERVER); },
|
||||
std::chrono::seconds(1),
|
||||
std::chrono::minutes(1),
|
||||
retry_pred);
|
||||
|
||||
// Query client security interface.
|
||||
wil::com_ptr_nothrow<IClientSecurity> clientSecurity;
|
||||
THROW_IF_FAILED(m_userSession->QueryInterface(IID_PPV_ARGS(&clientSecurity)));
|
||||
auto clientSecurity = m_userSession.query<IClientSecurity>();
|
||||
|
||||
// Get the current proxy blanket settings.
|
||||
DWORD authnSvc, authzSvc, authnLvl, capabilities;
|
||||
|
||||
@ -77,7 +77,7 @@ namespace Windows { namespace Internal {
|
||||
// Tell COM how to mask fatal exceptions.
|
||||
if (ownProcess)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<IGlobalOptions> pIGLB;
|
||||
wil::com_ptr<IGlobalOptions> pIGLB;
|
||||
RETURN_IF_FAILED(CoCreateInstance(CLSID_GlobalOptions, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pIGLB)));
|
||||
RETURN_IF_FAILED(pIGLB->Set(COMGLB_EXCEPTION_HANDLING, TExceptionPolicy));
|
||||
}
|
||||
@ -294,7 +294,7 @@ namespace Windows { namespace Internal {
|
||||
bool m_addedModuleReference = false;
|
||||
|
||||
// COM callback object to support unloading shared-process services
|
||||
Microsoft::WRL::ComPtr<IContextCallback> m_icc;
|
||||
wil::com_ptr<IContextCallback> m_icc;
|
||||
|
||||
// COM Server descriptor
|
||||
ServerDescriptor m_serverDescriptor{};
|
||||
|
||||
@ -335,7 +335,7 @@ const std::wstring LxssNetworkingFirewall::s_FriendlyNamePrefix(L"WSLRULE_177744
|
||||
|
||||
LxssNetworkingFirewall::LxssNetworkingFirewall()
|
||||
{
|
||||
THROW_IF_FAILED(::CoCreateInstance(__uuidof(NetFwPolicy2), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_firewall)));
|
||||
m_firewall = wil::CoCreateInstance<NetFwPolicy2, INetFwPolicy2>(CLSCTX_INPROC_SERVER);
|
||||
}
|
||||
|
||||
void LxssNetworkingFirewall::CopyPartialArray(SAFEARRAY* Destination, SAFEARRAY* Source, ULONG DestinationIndexStart, ULONG SourceIndexStart, ULONG ElementsToCopy)
|
||||
@ -388,8 +388,7 @@ void LxssNetworkingFirewall::CopyPartialArray(SAFEARRAY* Destination, SAFEARRAY*
|
||||
|
||||
std::wstring LxssNetworkingFirewall::AddPortRule(const IP_ADDRESS_PREFIX& Address) const
|
||||
{
|
||||
Microsoft::WRL::ComPtr<INetFwRule> newRule;
|
||||
THROW_IF_FAILED(::CoCreateInstance(__uuidof(NetFwRule), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&newRule)));
|
||||
auto newRule = wil::CoCreateInstance<NetFwRule, INetFwRule>(CLSCTX_INPROC_SERVER);
|
||||
|
||||
// Open a port via the firewall by creating a rule that specifies the local
|
||||
// address and the local port to allow. Currently this rule only applies to
|
||||
@ -412,9 +411,9 @@ std::wstring LxssNetworkingFirewall::AddPortRule(const IP_ADDRESS_PREFIX& Addres
|
||||
THROW_IF_FAILED(newRule->put_Description(s_DefaultRuleDescription.get()));
|
||||
THROW_IF_FAILED(newRule->put_Enabled(VARIANT_TRUE));
|
||||
// Add the rule to the existing set.
|
||||
Microsoft::WRL::ComPtr<INetFwRules> rules;
|
||||
wil::com_ptr<INetFwRules> rules;
|
||||
THROW_IF_FAILED(m_firewall->get_Rules(&rules));
|
||||
THROW_IF_FAILED(rules->Add(newRule.Get()));
|
||||
THROW_IF_FAILED(rules->Add(newRule.get()));
|
||||
// Return the unique rule name to the caller.
|
||||
return generatedName;
|
||||
}
|
||||
@ -423,12 +422,11 @@ void LxssNetworkingFirewall::CleanupRemnants()
|
||||
{
|
||||
auto firewall = std::make_shared<LxssNetworkingFirewall>();
|
||||
THROW_HR_IF(E_OUTOFMEMORY, !firewall);
|
||||
Microsoft::WRL::ComPtr<INetFwRules> rules;
|
||||
wil::com_ptr<INetFwRules> rules;
|
||||
THROW_IF_FAILED(firewall->m_firewall->get_Rules(&rules));
|
||||
Microsoft::WRL::ComPtr<IUnknown> enumInterface;
|
||||
THROW_IF_FAILED(rules->get__NewEnum(enumInterface.GetAddressOf()));
|
||||
Microsoft::WRL::ComPtr<IEnumVARIANT> rulesEnum;
|
||||
THROW_IF_FAILED(enumInterface.As(&rulesEnum));
|
||||
wil::com_ptr<IUnknown> enumInterface;
|
||||
THROW_IF_FAILED(rules->get__NewEnum(enumInterface.addressof()));
|
||||
auto rulesEnum = enumInterface.query<IEnumVARIANT>();
|
||||
// Find any rules with the unique WSL prefix and destroy them.
|
||||
for (;;)
|
||||
{
|
||||
@ -440,7 +438,7 @@ void LxssNetworkingFirewall::CleanupRemnants()
|
||||
break;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<INetFwRule> nextRule;
|
||||
wil::com_ptr<INetFwRule> nextRule;
|
||||
THROW_IF_FAILED(next.pdispVal->QueryInterface(IID_PPV_ARGS(&nextRule)));
|
||||
wil::unique_bstr nextRuleName;
|
||||
THROW_IF_FAILED(nextRule->get_Name(nextRuleName.addressof()));
|
||||
@ -558,7 +556,7 @@ void LxssNetworkingFirewall::RemoveExcludedAdapter(const std::wstring& AdapterNa
|
||||
|
||||
void LxssNetworkingFirewall::RemovePortRule(const std::wstring& RuleName) const
|
||||
{
|
||||
Microsoft::WRL::ComPtr<INetFwRules> rules;
|
||||
wil::com_ptr<INetFwRules> rules;
|
||||
THROW_IF_FAILED(m_firewall->get_Rules(&rules));
|
||||
THROW_IF_FAILED(rules->Remove(wil::make_bstr_failfast(RuleName.c_str()).get()));
|
||||
}
|
||||
@ -572,8 +570,7 @@ LxssNetworkingFirewallPort::LxssNetworkingFirewallPort(const std::shared_ptr<Lxs
|
||||
return;
|
||||
}
|
||||
|
||||
LxssNetworkingFirewallPort::LxssNetworkingFirewallPort(
|
||||
const std::shared_ptr<LxssNetworkingFirewall>& Firewall, const Microsoft::WRL::ComPtr<INetFwRule>& Existing) :
|
||||
LxssNetworkingFirewallPort::LxssNetworkingFirewallPort(const std::shared_ptr<LxssNetworkingFirewall>& Firewall, const wil::com_ptr<INetFwRule>& Existing) :
|
||||
m_firewall(Firewall)
|
||||
{
|
||||
wil::unique_bstr ruleName;
|
||||
|
||||
@ -262,7 +262,7 @@ private:
|
||||
/// <summary>
|
||||
/// COM firewall instance.
|
||||
/// </summary>
|
||||
Microsoft::WRL::ComPtr<INetFwPolicy2> m_firewall;
|
||||
wil::com_ptr<INetFwPolicy2> m_firewall;
|
||||
|
||||
/// <summary>
|
||||
/// Lock to protect class members.
|
||||
@ -295,7 +295,7 @@ public:
|
||||
/// <summary>
|
||||
/// Constructor to take ownership of an existing rule.
|
||||
/// </summary>
|
||||
LxssNetworkingFirewallPort(const std::shared_ptr<LxssNetworkingFirewall>& Firewall, const Microsoft::WRL::ComPtr<INetFwRule>& Existing);
|
||||
LxssNetworkingFirewallPort(const std::shared_ptr<LxssNetworkingFirewall>& Firewall, const wil::com_ptr<INetFwRule>& Existing);
|
||||
|
||||
/// <summary>
|
||||
/// Destructor.
|
||||
|
||||
@ -2674,8 +2674,7 @@ try
|
||||
THROW_IF_FAILED(shellLink->SetArguments(commandLine.c_str()));
|
||||
THROW_IF_FAILED(shellLink->SetIconLocation(ShortcutIcon, 0));
|
||||
|
||||
Microsoft::WRL::ComPtr<IPersistFile> storage;
|
||||
THROW_IF_FAILED(shellLink->QueryInterface(IID_IPersistFile, &storage));
|
||||
auto storage = shellLink.query<IPersistFile>();
|
||||
THROW_IF_FAILED(storage->Save(shortcutPath.c_str(), true));
|
||||
|
||||
registration.Write(Property::ShortcutPath, shortcutPath.c_str());
|
||||
|
||||
@ -351,7 +351,7 @@ private:
|
||||
wsl::shared::SocketChannel m_miniInitChannel;
|
||||
wil::unique_socket m_notifyChannel;
|
||||
SE_SID m_userSid;
|
||||
Microsoft::WRL::ComPtr<DeviceHostProxy> m_deviceHostSupport;
|
||||
wil::com_ptr<DeviceHostProxy> m_deviceHostSupport;
|
||||
std::shared_ptr<LxssRunningInstance> m_systemDistro;
|
||||
_Guarded_by_(m_lock) std::bitset<MAX_VHD_COUNT> m_lunBitmap;
|
||||
_Guarded_by_(m_lock) std::map<AttachedDisk, DiskState> m_attachedDisks;
|
||||
|
||||
@ -327,7 +327,7 @@ class PolicyTest
|
||||
const auto stop = std::chrono::steady_clock::now() + std::chrono::seconds{30};
|
||||
for (;;)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<ILxssUserSession> session;
|
||||
wil::com_ptr<ILxssUserSession> session;
|
||||
result = CoCreateInstance(CLSID_LxssUserSession, nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&session));
|
||||
if (result == expectedResult || std::chrono::steady_clock::now() > stop)
|
||||
{
|
||||
|
||||
@ -2448,8 +2448,7 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
|
||||
// Validate that the shortcut is actually in the start menu
|
||||
VERIFY_IS_TRUE(shortcutPath.find(startMenu) != std::string::npos);
|
||||
|
||||
Microsoft::WRL::ComPtr<IPersistFile> storage;
|
||||
VERIFY_SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, &storage));
|
||||
auto storage = shellLink.query<IPersistFile>();
|
||||
|
||||
VERIFY_SUCCEEDED(storage->Load(shortcutPath.c_str(), 0));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user