1 
2 
3 typedef struct {
4     int colnameid;
5     int pcsFlags;
6     int fmt;
7     int cxChar;
8 } shvheader;
9 
10 class CNetworkConnections:
11     public CComCoClass<CNetworkConnections, &CLSID_ConnectionFolder>,
12     public CComObjectRootEx<CComMultiThreadModelNoCS>,
13     public IPersistFolder2,
14     public IShellExtInit,
15     public IShellFolder2,
16     public IOleCommandTarget,
17     public IShellFolderViewCB,
18     public IShellExecuteHookW
19 {
20     public:
21         CNetworkConnections();
22         ~CNetworkConnections();
23 
24         // IPersistFolder2
25         STDMETHOD(GetClassID)(CLSID *lpClassId) override;
26         STDMETHOD(Initialize)(PCIDLIST_ABSOLUTE pidl) override;
27         STDMETHOD(GetCurFolder)(PIDLIST_ABSOLUTE *pidl) override;
28 
29         // IShellFolder
30         STDMETHOD(ParseDisplayName)(HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName, DWORD *pchEaten, PIDLIST_RELATIVE *ppidl, DWORD *pdwAttributes) override;
31         STDMETHOD(EnumObjects)(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList) override;
32         STDMETHOD(BindToObject)(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut) override;
33         STDMETHOD(BindToStorage)(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut) override;
34         STDMETHOD(CompareIDs)(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2) override;
35         STDMETHOD(CreateViewObject)(HWND hwndOwner, REFIID riid, LPVOID *ppvOut) override;
36         STDMETHOD(GetAttributesOf)(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut) override;
37         STDMETHOD(GetUIObjectOf)(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut) override;
38         STDMETHOD(GetDisplayNameOf)(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET strRet) override;
39         STDMETHOD(SetNameOf)(HWND hwndOwner, PCUITEMID_CHILD pidl, LPCOLESTR lpName, DWORD dwFlags, PITEMID_CHILD *pPidlOut) override;
40 
41         // IShellFolder2
42         STDMETHOD(GetDefaultSearchGUID)(GUID *pguid) override;
43         STDMETHOD(EnumSearches)(IEnumExtraSearch **ppenum) override;
44         STDMETHOD(GetDefaultColumn)(DWORD dwRes, ULONG *pSort, ULONG *pDisplay) override;
45         STDMETHOD(GetDefaultColumnState)(UINT iColumn, DWORD *pcsFlags) override;
46         STDMETHOD(GetDetailsEx)(PCUITEMID_CHILD pidl, const SHCOLUMNID *pscid, VARIANT *pv) override;
47         STDMETHOD(GetDetailsOf)(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *psd) override;
48         STDMETHOD(MapColumnToSCID)(UINT column, SHCOLUMNID *pscid) override;
49 
50         // IShellExtInit
51         STDMETHOD(Initialize)(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID) override;
52 
53         // IOleCommandTarget
54         STDMETHOD(Exec)(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) override;
55         STDMETHOD(QueryStatus)(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText) override;
56 
57         // IShellFolderViewCB
58         STDMETHOD(MessageSFVCB)(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
59 
60         // IShellExecuteHookW
61         STDMETHOD(Execute)(LPSHELLEXECUTEINFOW pei) override;
62 
63     private:
64 
65         /* both paths are parsible from the desktop */
66         PIDLIST_ABSOLUTE m_pidlRoot;
67         CComPtr<IOleCommandTarget> m_lpOleCmd;
68 
69     public:
70 
71         BEGIN_COM_MAP(CNetworkConnections)
72             COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersistFolder2)
73             COM_INTERFACE_ENTRY_IID(IID_IPersistFolder, IPersistFolder2)
74             COM_INTERFACE_ENTRY_IID(IID_IPersistFolder2, IPersistFolder2)
75             COM_INTERFACE_ENTRY_IID(IID_IShellFolder, IShellFolder2)
76             COM_INTERFACE_ENTRY_IID(IID_IShellFolder2, IShellFolder2)
77             COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, IShellExtInit)
78             COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget)
79             COM_INTERFACE_ENTRY_IID(IID_IShellFolderViewCB, IShellFolderViewCB)
80             COM_INTERFACE_ENTRY_IID(IID_IShellExecuteHookW, IShellExecuteHookW)
81         END_COM_MAP()
82 
83         DECLARE_NO_REGISTRY()
84         DECLARE_NOT_AGGREGATABLE(CNetworkConnections)
85         DECLARE_PROTECT_FINAL_CONSTRUCT()
86 };
87 
88 class CNetConUiObject:
89     public CComObjectRootEx<CComMultiThreadModelNoCS>,
90     public IContextMenu3,
91     public IObjectWithSite,
92     public IQueryInfo,
93     public IExtractIconW
94 {
95     private:
96         PCUITEMID_CHILD m_pidl;
97         CComPtr<IUnknown> m_pUnknown;
98         CComPtr<IOleCommandTarget> m_lpOleCmd;
99 
100     public:
101         CNetConUiObject();
102         ~CNetConUiObject();
103         HRESULT WINAPI Initialize(PCUITEMID_CHILD pidl, IOleCommandTarget *lpOleCmd);
104 
105         // IContextMenu3
106         STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) override;
107         STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici) override;
108         STDMETHOD(GetCommandString)(UINT_PTR idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax) override;
109         STDMETHOD(HandleMenuMsg)( UINT uMsg, WPARAM wParam, LPARAM lParam) override;
110         STDMETHOD(HandleMenuMsg2)(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult) override;
111 
112         // IObjectWithSite
113         STDMETHOD(SetSite)(IUnknown *punk) override;
114         STDMETHOD(GetSite)(REFIID iid, void **ppvSite) override;
115 
116         // IQueryInfo
117         STDMETHOD(GetInfoFlags)(DWORD *pdwFlags) override;
118         STDMETHOD(GetInfoTip)(DWORD dwFlags, WCHAR **ppwszTip) override;
119 
120         // IExtractIconW
121         STDMETHOD(GetIconLocation)(UINT uFlags, LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags) override;
122         STDMETHOD(Extract)(LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize) override;
123 
124         BEGIN_COM_MAP(CNetConUiObject)
125             COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu3)
126             COM_INTERFACE_ENTRY_IID(IID_IContextMenu2, IContextMenu3)
127             COM_INTERFACE_ENTRY_IID(IID_IContextMenu3, IContextMenu3)
128             COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite)
129             COM_INTERFACE_ENTRY_IID(IID_IQueryInfo, IQueryInfo)
130             COM_INTERFACE_ENTRY_IID(IID_IExtractIconW, IExtractIconW)
131         END_COM_MAP()
132 
133         DECLARE_NOT_AGGREGATABLE(CNetConUiObject)
134         DECLARE_PROTECT_FINAL_CONSTRUCT()
135 };
136 
137 HRESULT ShowNetConnectionProperties(INetConnection * pNetConnect, HWND hwnd);
138