From 604568dbaffbc3a52b389b4c01e10a6c1c03bcbd Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sun, 19 Apr 2015 21:07:35 +0000 Subject: [PATCH] [NETSHELL] - Keep a CLanStatus instance around in CNetworkConnections (as before r65758) and properly manage its lifetime. Fixes Status context menu item for network connections. CORE-9564 svn path=/trunk/; revision=67311 --- reactos/dll/shellext/netshell/lanstatusui.cpp | 6 +---- .../shellext/netshell/shfldr_netconnect.cpp | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/reactos/dll/shellext/netshell/lanstatusui.cpp b/reactos/dll/shellext/netshell/lanstatusui.cpp index 88ddb6ff2eb..a556334e6ae 100644 --- a/reactos/dll/shellext/netshell/lanstatusui.cpp +++ b/reactos/dll/shellext/netshell/lanstatusui.cpp @@ -34,7 +34,7 @@ typedef struct UINT Status; } LANSTATUSUI_CONTEXT; -class CLanStatus : +class CLanStatus final : public IOleCommandTarget { public: @@ -1149,16 +1149,12 @@ ULONG WINAPI CLanStatus::Release() { -#if 0 // WTF?! ULONG refCount = InterlockedDecrement(&m_ref); if (!refCount) delete this; return refCount; -#else - return 1; -#endif } HRESULT diff --git a/reactos/dll/shellext/netshell/shfldr_netconnect.cpp b/reactos/dll/shellext/netshell/shfldr_netconnect.cpp index 0c9841c02bf..12db3711db0 100644 --- a/reactos/dll/shellext/netshell/shfldr_netconnect.cpp +++ b/reactos/dll/shellext/netshell/shfldr_netconnect.cpp @@ -111,6 +111,8 @@ class CNetConUiObject final : virtual HRESULT STDMETHODCALLTYPE Extract(LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize); private: + ~CNetConUiObject(); + LONG m_ref; PCUITEMID_CHILD m_pidl; IUnknown *m_pUnknown; @@ -139,13 +141,21 @@ HRESULT ShowNetConnectionStatus(IOleCommandTarget * lpOleCmd, INetConnection * p CNetworkConnections::CNetworkConnections() : m_ref(0), - m_pidlRoot(_ILCreateNetConnect()), - m_lpOleCmd(NULL) + m_pidlRoot(_ILCreateNetConnect()) { + HRESULT hr; + hr = CoCreateInstance(CLSID_LanConnectStatusUI, NULL, CLSCTX_INPROC_SERVER, IID_IOleCommandTarget, reinterpret_cast(&m_lpOleCmd)); + if (FAILED(hr)) + { + ERR("CoCreateInstance failed with %lx\n", hr); + m_lpOleCmd = NULL; + } } CNetworkConnections::~CNetworkConnections() { + if (m_lpOleCmd) + m_lpOleCmd->Release(); SHFree(m_pidlRoot); } @@ -670,6 +680,14 @@ CNetConUiObject::CNetConUiObject(PCUITEMID_CHILD pidl, IOleCommandTarget *lpOleC m_pUnknown(NULL), m_lpOleCmd(lpOleCmd) { + if (m_lpOleCmd) + m_lpOleCmd->AddRef(); +} + +CNetConUiObject::~CNetConUiObject() +{ + if (m_lpOleCmd) + m_lpOleCmd->Release(); } /************************************************************************ @@ -856,7 +874,7 @@ ShowNetConnectionStatus( if (pNetConnect->GetProperties(&pProperties) != S_OK) return E_FAIL; - hr = lpOleCmd->Exec(&pProperties->guidId, 2, OLECMDEXECOPT_DODEFAULT, NULL, NULL); + hr = lpOleCmd->Exec(&pProperties->guidId, OLECMDID_NEW, OLECMDEXECOPT_DODEFAULT, NULL, NULL); NcFreeNetconProperties(pProperties); return hr; -- 2.17.1