https://git.reactos.org/?p=reactos.git;a=commitdiff;h=769b102e5f7c5e5777b384a1885ab6da2a45b378

commit 769b102e5f7c5e5777b384a1885ab6da2a45b378
Author:     Giannis Adamopoulos <[email protected]>
AuthorDate: Mon Nov 12 16:46:45 2018 +0200
Commit:     Giannis Adamopoulos <[email protected]>
CommitDate: Sun Nov 18 14:01:54 2018 +0200

    [NETSHELL] Use smart pointers and IID_PPV_ARG
---
 dll/shellext/netshell/enumlist.cpp          |  41 +++----
 dll/shellext/netshell/lanconnectui.cpp      |  89 ++++++---------
 dll/shellext/netshell/lanconnectui.h        |   6 +-
 dll/shellext/netshell/lanstatusui.cpp       | 164 +++++++++++++---------------
 dll/shellext/netshell/lanstatusui.h         |   2 +-
 dll/shellext/netshell/shfldr_netconnect.cpp |  73 +++----------
 dll/shellext/netshell/shfldr_netconnect.h   |   6 +-
 7 files changed, 149 insertions(+), 232 deletions(-)

diff --git a/dll/shellext/netshell/enumlist.cpp 
b/dll/shellext/netshell/enumlist.cpp
index c4e5de37a7..218817539e 100644
--- a/dll/shellext/netshell/enumlist.cpp
+++ b/dll/shellext/netshell/enumlist.cpp
@@ -124,45 +124,36 @@ HRESULT
 CEnumIDList::Initialize()
 {
     HRESULT hr;
-    INetConnectionManager *pNetConMan;
-    IEnumNetConnection *pEnumCon;
-    INetConnection *INetCon;
+    CComPtr<INetConnectionManager> pNetConMan;
+    CComPtr<IEnumNetConnection> pEnumCon;
     ULONG Count;
     PITEMID_CHILD pidl;
 
     /* get an instance to of IConnectionManager */
-    hr = CNetConnectionManager_CreateInstance(IID_INetConnectionManager, 
(LPVOID*)&pNetConMan);
-    if (FAILED(hr))
+    hr = 
CNetConnectionManager_CreateInstance(IID_PPV_ARG(INetConnectionManager, 
&pNetConMan));
+    if (FAILED_UNEXPECTEDLY(hr))
         return S_OK;
 
     hr = pNetConMan->EnumConnections(NCME_DEFAULT, &pEnumCon);
-    if (FAILED(hr))
-    {
-        pNetConMan->Release();
+    if (FAILED_UNEXPECTEDLY(hr))
         return S_OK;
-    }
 
-    do
+    while (TRUE)
     {
+        CComPtr<INetConnection> INetCon;
+
         hr = pEnumCon->Next(1, &INetCon, &Count);
-        if (hr == S_OK)
-        {
-            pidl = ILCreateNetConnectItem(INetCon);
-            if (pidl)
-            {
-                AddToEnumList(pidl);
-            }
-        }
-        else
-        {
+        if (hr != S_OK)
             break;
-        }
-    } while (TRUE);
 
-    pEnumCon->Release();
-    pNetConMan->Release();
+        pidl = ILCreateNetConnectItem(INetCon);
+        if (pidl)
+        {
+            AddToEnumList(pidl);
+        }
+    }
 
-    return S_OK;    
+    return S_OK;
 }
 
 HRESULT
diff --git a/dll/shellext/netshell/lanconnectui.cpp 
b/dll/shellext/netshell/lanconnectui.cpp
index 60e25f0363..6c1c0f281e 100644
--- a/dll/shellext/netshell/lanconnectui.cpp
+++ b/dll/shellext/netshell/lanconnectui.cpp
@@ -8,9 +8,6 @@
 #include "precomp.h"
 
 CNetConnectionPropertyUi::CNetConnectionPropertyUi() :
-    m_pCon(NULL),
-    m_NCfgLock(NULL),
-    m_pNCfg(NULL),
     m_pProperties(NULL)
 {
 }
@@ -18,18 +15,10 @@ CNetConnectionPropertyUi::CNetConnectionPropertyUi() :
 CNetConnectionPropertyUi::~CNetConnectionPropertyUi()
 {
     if (m_pNCfg)
-    {
         m_pNCfg->Uninitialize();
-        m_pNCfg->Release();
-    }
-    if (m_NCfgLock)
-    {
-        m_NCfgLock->Release();
-    }
+
     if (m_pProperties)
-    {
         NcFreeNetconProperties(m_pProperties);
-    }
 }
 
 VOID
@@ -51,32 +40,31 @@ CNetConnectionPropertyUi::GetINetCfgComponent(INetCfg 
*pNCfg, INetCfgComponent *
 {
     LPWSTR pName;
     HRESULT hr;
-    INetCfgComponent * pNCg;
     ULONG Fetched;
-    IEnumNetCfgComponent * pEnumCfg;
+    CComPtr<IEnumNetCfgComponent> pEnumCfg;
 
     hr = pNCfg->EnumComponents(&GUID_DEVCLASS_NET, &pEnumCfg);
-    if (FAILED(hr))
-    {
+    if (FAILED_UNEXPECTEDLY(hr))
         return FALSE;
-    }
 
-    while (pEnumCfg->Next(1, &pNCg, &Fetched) == S_OK)
+    while (TRUE)
     {
+        CComPtr<INetCfgComponent> pNCg;
+        hr = pEnumCfg->Next(1, &pNCg, &Fetched);
+        if (hr != S_OK)
+            break;
+
         hr = pNCg->GetDisplayName(&pName);
         if (SUCCEEDED(hr))
         {
             if (!_wcsicmp(pName, m_pProperties->pszwDeviceName))
             {
-                *pOut = pNCg;
-                pEnumCfg->Release();
+                *pOut = pNCg.Detach();
                 return TRUE;
             }
             CoTaskMemFree(pName);
         }
-        pNCg->Release();
     }
-    pEnumCfg->Release();
     return FALSE;
 }
 
@@ -84,9 +72,7 @@ VOID
 CNetConnectionPropertyUi::EnumComponents(HWND hDlgCtrl, INetCfg *pNCfg, const 
GUID *CompGuid, UINT Type)
 {
     HRESULT hr;
-    IEnumNetCfgComponent * pENetCfg;
-    INetCfgComponent  *pNCfgComp, *pAdapterCfgComp;
-    INetCfgComponentBindings * pCompBind;
+    CComPtr<IEnumNetCfgComponent> pENetCfg;
     ULONG Num;
     DWORD dwCharacteristics;
     LPOLESTR pDisplayName, pHelpText;
@@ -94,25 +80,29 @@ CNetConnectionPropertyUi::EnumComponents(HWND hDlgCtrl, 
INetCfg *pNCfg, const GU
     BOOL bChecked;
 
     hr = pNCfg->EnumComponents(CompGuid, &pENetCfg);
-    if (FAILED(hr))
-    {
-        pNCfg->Release();
+    if (FAILED_UNEXPECTEDLY(hr))
         return;
-    }
-    while (pENetCfg->Next(1, &pNCfgComp, &Num) == S_OK)
+
+    while (TRUE)
     {
+        CComPtr<INetCfgComponent> pNCfgComp;
+        CComPtr<INetCfgComponentBindings> pCompBind;
+        CComPtr<INetCfgComponent> pAdapterCfgComp;
+
+        hr = pENetCfg->Next(1, &pNCfgComp, &Num);
+        if (hr != S_OK)
+            break;
+
         hr = pNCfgComp->GetCharacteristics(&dwCharacteristics);
         if (SUCCEEDED(hr) && (dwCharacteristics & NCF_HIDDEN))
-        {
-            pNCfgComp->Release();
             continue;
-        }
+
         pDisplayName = NULL;
         pHelpText = NULL;
         hr = pNCfgComp->GetDisplayName(&pDisplayName);
         hr = pNCfgComp->GetHelpText(&pHelpText);
         bChecked = TRUE; //ReactOS hack
-        hr = pNCfgComp->QueryInterface(IID_INetCfgComponentBindings, 
(LPVOID*)&pCompBind);
+        hr = pNCfgComp->QueryInterface(IID_PPV_ARG(INetCfgComponentBindings, 
&pCompBind));
         if (SUCCEEDED(hr))
         {
             if (GetINetCfgComponent(pNCfg, &pAdapterCfgComp))
@@ -122,8 +112,6 @@ CNetConnectionPropertyUi::EnumComponents(HWND hDlgCtrl, 
INetCfg *pNCfg, const GU
                     bChecked = TRUE;
                 else
                     bChecked = FALSE;
-                pAdapterCfgComp->Release();
-                pCompBind->Release();
             }
         }
 
@@ -134,21 +122,20 @@ CNetConnectionPropertyUi::EnumComponents(HWND hDlgCtrl, 
INetCfg *pNCfg, const GU
         pItem->dwCharacteristics = dwCharacteristics;
         pItem->szHelp = pHelpText;
         pItem->Type = (NET_TYPE)Type;
-        pItem->pNCfgComp = pNCfgComp;
+        pItem->pNCfgComp = pNCfgComp.Detach();
         pItem->NumPropDialogOpen = 0;
 
         AddItemToListView(hDlgCtrl, pItem, pDisplayName, bChecked);
         CoTaskMemFree(pDisplayName);
     }
-    pENetCfg->Release();
 }
 
 VOID
 CNetConnectionPropertyUi::InitializeLANPropertiesUIDlg(HWND hwndDlg)
 {
     HRESULT hr;
-    INetCfg *pNCfg;
-    INetCfgLock *pNCfgLock;
+    CComPtr<INetCfg> pNCfg;
+    CComPtr<INetCfgLock> pNCfgLock;
     HWND hDlgCtrl = GetDlgItem(hwndDlg, IDC_COMPONENTSLIST);
     LVCOLUMNW lc;
     RECT rc;
@@ -182,11 +169,11 @@ 
CNetConnectionPropertyUi::InitializeLANPropertiesUIDlg(HWND hwndDlg)
     dwStyle = dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES;
     SendMessage(hDlgCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
 
-    hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, 
IID_INetCfg, (LPVOID*)&pNCfg);
+    hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, 
IID_PPV_ARG(INetCfg, &pNCfg));
     if (FAILED(hr))
         return;
 
-    hr = pNCfg->QueryInterface(IID_INetCfgLock, (LPVOID*)&pNCfgLock);
+    hr = pNCfg->QueryInterface(IID_PPV_ARG(INetCfgLock, &pNCfgLock));
     hr = pNCfgLock->AcquireWriteLock(100, L"", &pDisplayName);
     if (hr == S_FALSE)
     {
@@ -194,18 +181,16 @@ 
CNetConnectionPropertyUi::InitializeLANPropertiesUIDlg(HWND hwndDlg)
         return;
     }
 
-    m_NCfgLock = pNCfgLock;
     hr = pNCfg->Initialize(NULL);
-    if (FAILED(hr))
-    {
-        pNCfg->Release();
+    if (FAILED_UNEXPECTEDLY(hr))
         return;
-    }
+
+    m_pNCfg = pNCfg;
+    m_NCfgLock = pNCfgLock;
 
     EnumComponents(hDlgCtrl, pNCfg, &GUID_DEVCLASS_NETCLIENT, NET_TYPE_CLIENT);
     EnumComponents(hDlgCtrl, pNCfg, &GUID_DEVCLASS_NETSERVICE, 
NET_TYPE_SERVICE);
     EnumComponents(hDlgCtrl, pNCfg, &GUID_DEVCLASS_NETTRANS, 
NET_TYPE_PROTOCOL);
-    m_pNCfg = pNCfg;
 
     ZeroMemory(&li, sizeof(li));
     li.mask = LVIF_STATE;
@@ -459,7 +444,7 @@ CNetConnectionPropertyUi::AddPages(
         return E_FAIL;
 
     hr = m_pCon->GetProperties(&m_pProperties);
-    if (FAILED(hr))
+    if (FAILED_UNEXPECTEDLY(hr))
         return hr;
 
     hProp = InitializePropertySheetPage(MAKEINTRESOURCEW(IDD_NETPROPERTIES), 
LANPropertiesUIDlg, reinterpret_cast<LPARAM>(this), NULL);
@@ -499,15 +484,10 @@ HRESULT
 WINAPI
 CNetConnectionPropertyUi::SetConnection(INetConnection* pCon)
 {
-    if (m_pCon)
-        m_pCon->Release();
-
     if (!pCon)
         return E_POINTER;
 
     m_pCon = pCon;
-
-    pCon->AddRef();
     return S_OK;
 }
 
@@ -520,7 +500,6 @@ CNetConnectionPropertyUi::Connect(
     if (!m_pCon)
         return E_POINTER; //FIXME
 
-
     if (dwFlags & NCUC_NO_UI)
         return m_pCon->Connect();
 
diff --git a/dll/shellext/netshell/lanconnectui.h 
b/dll/shellext/netshell/lanconnectui.h
index 02c8a8051b..6e8b927187 100644
--- a/dll/shellext/netshell/lanconnectui.h
+++ b/dll/shellext/netshell/lanconnectui.h
@@ -50,9 +50,9 @@ class CNetConnectionPropertyUi:
         BOOL GetDeviceInstanceID(OUT LPOLESTR *DeviceInstanceID); 
         static INT_PTR CALLBACK LANPropertiesUIDlg(HWND hwndDlg, UINT uMsg, 
WPARAM wParam, LPARAM lParam);
 
-        INetConnection * m_pCon;
-        INetCfgLock *m_NCfgLock;
-        INetCfg * m_pNCfg;
+        CComPtr<INetConnection> m_pCon;
+        CComPtr<INetCfgLock> m_NCfgLock;
+        CComPtr<INetCfg> m_pNCfg;
         NETCON_PROPERTIES * m_pProperties;
 
     public:
diff --git a/dll/shellext/netshell/lanstatusui.cpp 
b/dll/shellext/netshell/lanstatusui.cpp
index 2aa7cc0237..7a9be00ad7 100644
--- a/dll/shellext/netshell/lanstatusui.cpp
+++ b/dll/shellext/netshell/lanstatusui.cpp
@@ -903,9 +903,9 @@ CLanStatus::InitializeNetTaskbarNotifications()
 {
     NOTIFYICONDATAW nid;
     HWND hwndDlg;
-    INetConnectionManager *pNetConMan;
-    IEnumNetConnection *pEnumCon;
-    INetConnection *pNetCon;
+    CComPtr<INetConnectionManager> pNetConMan;
+    CComPtr<IEnumNetConnection> pEnumCon;
+    CComPtr<INetConnection> pNetCon;
     NETCON_PROPERTIES* pProps;
     HRESULT hr;
     ULONG Count;
@@ -942,108 +942,100 @@ CLanStatus::InitializeNetTaskbarNotifications()
        return S_OK;
     }
     /* get an instance to of IConnectionManager */
-
-    //hr = CoCreateInstance(&CLSID_ConnectionManager, NULL, 
CLSCTX_INPROC_SERVER, &IID_INetConnectionManager, (LPVOID*)&pNetConMan);
-
-    hr = CNetConnectionManager_CreateInstance(IID_INetConnectionManager, 
(LPVOID*)&pNetConMan);
-    if (FAILED(hr))
-    {
-        ERR("CNetConnectionManager_CreateInstance failed\n");
+    hr = 
CNetConnectionManager_CreateInstance(IID_PPV_ARG(INetConnectionManager, 
&pNetConMan));
+    if (FAILED_UNEXPECTEDLY(hr))
         return hr;
-    }
 
     hr = pNetConMan->EnumConnections(NCME_DEFAULT, &pEnumCon);
-    if (FAILED(hr))
-    {
-        ERR("EnumConnections failed\n");
-        pNetConMan->Release();
+    if (FAILED_UNEXPECTEDLY(hr))
         return hr;
-    }
 
     Index = 1;
-    do
+    while (TRUE)
     {
         hr = pEnumCon->Next(1, &pNetCon, &Count);
-        if (hr == S_OK)
+        if (hr != S_OK)
+            break;
+
+        TRACE("new connection\n");
+        pItem = 
static_cast<NOTIFICATION_ITEM*>(CoTaskMemAlloc(sizeof(NOTIFICATION_ITEM)));
+        if (!pItem)
+            break;
+
+        pContext = 
static_cast<LANSTATUSUI_CONTEXT*>(CoTaskMemAlloc(sizeof(LANSTATUSUI_CONTEXT)));
+        if (!pContext)
         {
-            TRACE("new connection\n");
-            pItem = 
static_cast<NOTIFICATION_ITEM*>(CoTaskMemAlloc(sizeof(NOTIFICATION_ITEM)));
-            if (!pItem)
-                break;
+            CoTaskMemFree(pItem);
+            break;
+        }
 
-            pContext = 
static_cast<LANSTATUSUI_CONTEXT*>(CoTaskMemAlloc(sizeof(LANSTATUSUI_CONTEXT)));
-            if (!pContext)
-            {
-                CoTaskMemFree(pItem);
-                break;
-            }
+        ZeroMemory(pContext, sizeof(LANSTATUSUI_CONTEXT));
+        pContext->uID = Index;
+        pContext->pNet = pNetCon;
+        pItem->uID = Index;
+        pItem->pNext = NULL;
+        pItem->pNet = pNetCon;
+        pNetCon->AddRef();
+        hwndDlg = CreateDialogParamW(netshell_hInstance, 
MAKEINTRESOURCEW(IDD_STATUS), NULL, LANStatusDlg, (LPARAM)pContext);
+        if (!hwndDlg)
+        {
+            ERR("CreateDialogParamW failed\n");
+            continue;
+        }
 
-            ZeroMemory(pContext, sizeof(LANSTATUSUI_CONTEXT));
-            pContext->uID = Index;
-            pContext->pNet = pNetCon;
-            pItem->uID = Index;
-            pItem->pNext = NULL;
-            pItem->pNet = pNetCon;
-            hwndDlg = CreateDialogParamW(netshell_hInstance, 
MAKEINTRESOURCEW(IDD_STATUS), NULL, LANStatusDlg, (LPARAM)pContext);
-            if (hwndDlg)
-            {
-                ZeroMemory(&nid, sizeof(nid));
-                nid.cbSize = sizeof(nid);
-                nid.uID = Index++;
-                nid.uFlags = NIF_MESSAGE;
-                nid.uVersion = NOTIFYICON_VERSION;
-                nid.uCallbackMessage = WM_SHOWSTATUSDLG;
-                nid.hWnd = hwndDlg;
-
-                hr = pNetCon->GetProperties(&pProps);
-                if (SUCCEEDED(hr))
-                {
-                    CopyMemory(&pItem->guidItem, &pProps->guidId, 
sizeof(GUID));
-                    if (!(pProps->dwCharacter & NCCF_SHOW_ICON))
-                    {
-                        nid.dwState = NIS_HIDDEN;
-                        nid.dwStateMask = NIS_HIDDEN;
-                        nid.uFlags |= NIF_STATE;
-                    }
-                    if (pProps->Status == NCS_MEDIA_DISCONNECTED || 
pProps->Status == NCS_DISCONNECTED || pProps->Status == NCS_HARDWARE_DISABLED)
-                        nid.hIcon = LoadIcon(netshell_hInstance, 
MAKEINTRESOURCE(IDI_NET_OFF));
-                    else if (pProps->Status == NCS_CONNECTED)
-                        nid.hIcon = LoadIcon(netshell_hInstance, 
MAKEINTRESOURCE(IDI_NET_IDLE));
+        ZeroMemory(&nid, sizeof(nid));
+        nid.cbSize = sizeof(nid);
+        nid.uID = Index++;
+        nid.uFlags = NIF_MESSAGE;
+        nid.uVersion = NOTIFYICON_VERSION;
+        nid.uCallbackMessage = WM_SHOWSTATUSDLG;
+        nid.hWnd = hwndDlg;
 
-                    if (nid.hIcon)
-                        nid.uFlags |= NIF_ICON;
+        hr = pNetCon->GetProperties(&pProps);
+        if (SUCCEEDED(hr))
+        {
+            CopyMemory(&pItem->guidItem, &pProps->guidId, sizeof(GUID));
+            if (!(pProps->dwCharacter & NCCF_SHOW_ICON))
+            {
+                nid.dwState = NIS_HIDDEN;
+                nid.dwStateMask = NIS_HIDDEN;
+                nid.uFlags |= NIF_STATE;
+            }
+            if (pProps->Status == NCS_MEDIA_DISCONNECTED || pProps->Status == 
NCS_DISCONNECTED || pProps->Status == NCS_HARDWARE_DISABLED)
+                nid.hIcon = LoadIcon(netshell_hInstance, 
MAKEINTRESOURCE(IDI_NET_OFF));
+            else if (pProps->Status == NCS_CONNECTED)
+                nid.hIcon = LoadIcon(netshell_hInstance, 
MAKEINTRESOURCE(IDI_NET_IDLE));
 
-                    wcscpy(nid.szTip, pProps->pszwName);
-                    nid.uFlags |= NIF_TIP;
-                }
-                pContext->hwndStatusDlg = hwndDlg;
-                pItem->hwndDlg = hwndDlg;
+            if (nid.hIcon)
+                nid.uFlags |= NIF_ICON;
 
-                if (Shell_NotifyIconW(NIM_ADD, &nid))
-                {
-                    if (pLast)
-                        pLast->pNext = pItem;
-                    else
-                        m_pHead = pItem;
+            wcscpy(nid.szTip, pProps->pszwName);
+            nid.uFlags |= NIF_TIP;
+        }
+        pContext->hwndStatusDlg = hwndDlg;
+        pItem->hwndDlg = hwndDlg;
 
-                    pLast = pItem;
-                    Index++;
-                }
-                else
-                {
-                    ERR("Shell_NotifyIconW failed\n");
-                    CoTaskMemFree(pItem);
-                }
+        if (Shell_NotifyIconW(NIM_ADD, &nid))
+        {
+            if (pLast)
+                pLast->pNext = pItem;
+            else
+                m_pHead = pItem;
 
-                if (nid.uFlags & NIF_ICON)
-                    DestroyIcon(nid.hIcon);
-            } else
-                ERR("CreateDialogParamW failed\n");
+            pLast = pItem;
+            Index++;
         }
-    } while (hr == S_OK);
+        else
+        {
+            ERR("Shell_NotifyIconW failed\n");
+            CoTaskMemFree(pItem);
+        }
+
+        if (nid.uFlags & NIF_ICON)
+            DestroyIcon(nid.hIcon);
+    }
 
     m_lpNetMan = pNetConMan;
-    pEnumCon->Release();
     return S_OK;
 }
 
diff --git a/dll/shellext/netshell/lanstatusui.h 
b/dll/shellext/netshell/lanstatusui.h
index 62f047b0cb..339db30d17 100644
--- a/dll/shellext/netshell/lanstatusui.h
+++ b/dll/shellext/netshell/lanstatusui.h
@@ -47,7 +47,7 @@ class CLanStatus:
         HRESULT InitializeNetTaskbarNotifications();
         HRESULT ShowStatusDialogByCLSID(const GUID *pguidCmdGroup);
 
-        INetConnectionManager *m_lpNetMan;
+        CComPtr<INetConnectionManager> m_lpNetMan;
         NOTIFICATION_ITEM *m_pHead;
 
     public:
diff --git a/dll/shellext/netshell/shfldr_netconnect.cpp 
b/dll/shellext/netshell/shfldr_netconnect.cpp
index 82d0cfa02c..39c5c44ed8 100644
--- a/dll/shellext/netshell/shfldr_netconnect.cpp
+++ b/dll/shellext/netshell/shfldr_netconnect.cpp
@@ -57,18 +57,13 @@ CNetworkConnections::CNetworkConnections() :
     m_pidlRoot(_ILCreateNetConnect())
 {
     HRESULT hr;
-    hr = CoCreateInstance(CLSID_ConnectionTray, NULL, CLSCTX_INPROC_SERVER, 
IID_IOleCommandTarget, reinterpret_cast<PVOID*>(&m_lpOleCmd));
-    if (FAILED(hr))
-    {
-        ERR("CoCreateInstance failed with %lx\n", hr);
+    hr = CoCreateInstance(CLSID_ConnectionTray, NULL, CLSCTX_INPROC_SERVER, 
IID_PPV_ARG(IOleCommandTarget, &m_lpOleCmd));
+    if (FAILED_UNEXPECTEDLY(hr))
         m_lpOleCmd = NULL;
-    }
 }
 
 CNetworkConnections::~CNetworkConnections()
 {
-    if (m_lpOleCmd)
-        m_lpOleCmd->Release();
     SHFree(m_pidlRoot);
 }
 
@@ -132,7 +127,6 @@ HRESULT WINAPI CNetworkConnections::CompareIDs(
 HRESULT WINAPI CNetworkConnections::CreateViewObject(
                HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
 {
-    CSFV cvf;
     HRESULT hr = E_NOINTERFACE;
 
     if (!ppvOut)
@@ -142,17 +136,13 @@ HRESULT WINAPI CNetworkConnections::CreateViewObject(
 
     if (IsEqualIID(riid, IID_IShellView))
     {
-        ZeroMemory(&cvf, sizeof(cvf));
-        cvf.cbSize = sizeof(cvf);
-        cvf.pshf = static_cast<IShellFolder*>(this);
-
-        IShellView* pShellView;
+        CSFV cvf = {sizeof(cvf), this};
+        CComPtr<IShellView> pShellView;
         hr = SHCreateShellFolderViewEx(&cvf, &pShellView);
-        if (SUCCEEDED(hr))
-        {
-            hr = pShellView->QueryInterface(riid, ppvOut);
-            pShellView->Release();
-        }
+        if (FAILED_UNEXPECTEDLY(hr))
+            return hr;
+
+        return pShellView->QueryInterface(riid, ppvOut);
     }
 
     return hr;
@@ -488,24 +478,18 @@ HRESULT WINAPI CNetworkConnections::MapColumnToSCID(UINT 
column, SHCOLUMNID *psc
 */
 
 CNetConUiObject::CNetConUiObject()
-    : m_pidl(NULL),
-      m_pUnknown(NULL),
-      m_lpOleCmd(NULL)
+    : m_pidl(NULL)
 {
 }
 
 CNetConUiObject::~CNetConUiObject()
 {
-    if (m_lpOleCmd)
-        m_lpOleCmd->Release();
 }
 
 HRESULT WINAPI CNetConUiObject::Initialize(PCUITEMID_CHILD pidl, 
IOleCommandTarget *lpOleCmd)
 {
     m_pidl = pidl;
     m_lpOleCmd = lpOleCmd;
-    if (m_lpOleCmd)
-        m_lpOleCmd->AddRef();
     return S_OK;
 }
 
@@ -657,7 +641,7 @@ ShowNetConnectionProperties(
     CLSID ClassID;
     PROPSHEETHEADERW pinfo;
     HPROPSHEETPAGE hppages[MAX_PROPERTY_SHEET_PAGE];
-    INetConnectionPropertyUi * pNCP;
+    CComPtr<INetConnectionPropertyUi> pNCP;
     NETCON_PROPERTIES * pProperties;
 
     if (pNetConnect->GetProperties(&pProperties) != S_OK)
@@ -695,7 +679,6 @@ ShowNetConnectionProperties(
                 hr = E_FAIL;
         }
     }
-    pNCP->Release();
     NcFreeNetconProperties(pProperties);
     return hr;
 }
@@ -737,14 +720,13 @@ HRESULT WINAPI 
CNetConUiObject::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
         case IDS_NET_RENAME:
         {
             HRESULT hr;
-            IShellView *psv;
-            hr = IUnknown_QueryService(m_pUnknown, SID_IFolderView, 
IID_IShellView, (PVOID*)&psv);
+            CComPtr<IShellView> psv;
+            hr = IUnknown_QueryService(m_pUnknown, SID_IFolderView, 
IID_PPV_ARG(IShellView, &psv));
             if (SUCCEEDED(hr))
             {
                 SVSIF selFlags = SVSI_DESELECTOTHERS | SVSI_EDIT | 
SVSI_ENSUREVISIBLE | SVSI_FOCUSED | SVSI_SELECT;
                 psv->SelectItem(m_pidl, selFlags);
             }
-            psv->Release();
 
             return S_OK;
         }
@@ -793,45 +775,18 @@ HRESULT WINAPI CNetConUiObject::HandleMenuMsg2(
 
 HRESULT WINAPI CNetConUiObject::GetSite(REFIID riid, PVOID *ppvSite)
 {
-    HRESULT hr;
-    IUnknown *pUnknown;
-
     if (!m_pUnknown)
     {
         *ppvSite = NULL;
         return E_FAIL;
     }
 
-    hr = m_pUnknown->QueryInterface(riid, reinterpret_cast<PVOID*>(&pUnknown));
-    if (SUCCEEDED(hr))
-    {
-        pUnknown->AddRef();
-        *ppvSite = pUnknown;
-        return S_OK;
-    }
-
-    *ppvSite = NULL;
-    return hr;
+    return m_pUnknown->QueryInterface(riid, ppvSite);
 }
 
 HRESULT WINAPI CNetConUiObject::SetSite(IUnknown *pUnkSite)
 {
-    if (!pUnkSite)
-    {
-        if (m_pUnknown)
-        {
-            m_pUnknown->Release();
-            m_pUnknown = NULL;
-        }
-    }
-    else
-    {
-        pUnkSite->AddRef();
-        if (m_pUnknown)
-            m_pUnknown->Release();
-        m_pUnknown = pUnkSite;
-    }
-
+    m_pUnknown = pUnkSite;
     return S_OK;
 }
 
diff --git a/dll/shellext/netshell/shfldr_netconnect.h 
b/dll/shellext/netshell/shfldr_netconnect.h
index 2c541ad3bd..9326fdad14 100644
--- a/dll/shellext/netshell/shfldr_netconnect.h
+++ b/dll/shellext/netshell/shfldr_netconnect.h
@@ -64,7 +64,7 @@ class CNetworkConnections:
 
         /* both paths are parsible from the desktop */
         PIDLIST_ABSOLUTE m_pidlRoot;
-        IOleCommandTarget *m_lpOleCmd;
+        CComPtr<IOleCommandTarget> m_lpOleCmd;
 
     public:
 
@@ -94,8 +94,8 @@ class CNetConUiObject:
 {
     private:
         PCUITEMID_CHILD m_pidl;
-        IUnknown *m_pUnknown;
-        IOleCommandTarget *m_lpOleCmd;
+        CComPtr<IUnknown> m_pUnknown;
+        CComPtr<IOleCommandTarget> m_lpOleCmd;
 
     public:
         CNetConUiObject();

Reply via email to