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         virtual HRESULT WINAPI GetClassID(CLSID *lpClassId);
26         virtual HRESULT WINAPI Initialize(PCIDLIST_ABSOLUTE pidl);
27         virtual HRESULT WINAPI GetCurFolder(PIDLIST_ABSOLUTE *pidl);
28 
29         // IShellFolder
30         virtual HRESULT WINAPI ParseDisplayName(HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName, DWORD *pchEaten, PIDLIST_RELATIVE *ppidl, DWORD *pdwAttributes);
31         virtual HRESULT WINAPI EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList);
32         virtual HRESULT WINAPI BindToObject(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut);
33         virtual HRESULT WINAPI BindToStorage(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut);
34         virtual HRESULT WINAPI CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2);
35         virtual HRESULT WINAPI CreateViewObject(HWND hwndOwner, REFIID riid, LPVOID *ppvOut);
36         virtual HRESULT WINAPI GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut);
37         virtual HRESULT WINAPI GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut);
38         virtual HRESULT WINAPI GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET strRet);
39         virtual HRESULT WINAPI SetNameOf(HWND hwndOwner, PCUITEMID_CHILD pidl, LPCOLESTR lpName, DWORD dwFlags, PITEMID_CHILD *pPidlOut);
40 
41         // IShellFolder2
42         virtual HRESULT WINAPI GetDefaultSearchGUID(GUID *pguid);
43         virtual HRESULT WINAPI EnumSearches(IEnumExtraSearch **ppenum);
44         virtual HRESULT WINAPI GetDefaultColumn(DWORD dwRes, ULONG *pSort, ULONG *pDisplay);
45         virtual HRESULT WINAPI GetDefaultColumnState(UINT iColumn, DWORD *pcsFlags);
46         virtual HRESULT WINAPI GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMNID *pscid, VARIANT *pv);
47         virtual HRESULT WINAPI GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *psd);
48         virtual HRESULT WINAPI MapColumnToSCID(UINT column, SHCOLUMNID *pscid);
49 
50         // IShellExtInit
51         virtual HRESULT WINAPI Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID);
52 
53         // IOleCommandTarget
54         virtual HRESULT WINAPI Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut);
55         virtual HRESULT WINAPI QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText);
56 
57         // IShellFolderViewCB
58         virtual HRESULT WINAPI MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam);
59 
60         // IShellExecuteHookW
61         virtual HRESULT WINAPI Execute(LPSHELLEXECUTEINFOW pei);
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         virtual HRESULT WINAPI QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
107         virtual HRESULT WINAPI InvokeCommand(LPCMINVOKECOMMANDINFO lpici);
108         virtual HRESULT WINAPI GetCommandString(UINT_PTR idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax);
109         virtual HRESULT WINAPI HandleMenuMsg( UINT uMsg, WPARAM wParam, LPARAM lParam);
110         virtual HRESULT WINAPI HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult);
111 
112         // IObjectWithSite
113         virtual HRESULT WINAPI SetSite(IUnknown *punk);
114         virtual HRESULT WINAPI GetSite(REFIID iid, void **ppvSite);
115 
116         // IQueryInfo
117         virtual HRESULT WINAPI GetInfoFlags(DWORD *pdwFlags);
118         virtual HRESULT WINAPI GetInfoTip(DWORD dwFlags, WCHAR **ppwszTip);
119 
120         // IExtractIconW
121         virtual HRESULT STDMETHODCALLTYPE GetIconLocation(UINT uFlags, LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags);
122         virtual HRESULT STDMETHODCALLTYPE Extract(LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize);
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