1 2 typedef struct tagINetConnectionItem 3 { 4 struct tagINetConnectionItem * Next; 5 DWORD dwAdapterIndex; 6 NETCON_PROPERTIES Props; 7 } INetConnectionItem, *PINetConnectionItem; 8 9 class CNetConnectionManager: 10 public CComCoClass<CNetConnectionManager, &CLSID_ConnectionManager>, 11 public CComObjectRootEx<CComMultiThreadModelNoCS>, 12 public INetConnectionManager, 13 public IEnumNetConnection 14 { 15 public: 16 CNetConnectionManager(); 17 HRESULT Initialize(); 18 HRESULT EnumerateINetConnections(); 19 20 // INetConnectionManager 21 virtual HRESULT WINAPI EnumConnections(NETCONMGR_ENUM_FLAGS Flags, IEnumNetConnection **ppEnum); 22 23 // IEnumNetConnection 24 virtual HRESULT WINAPI Next(ULONG celt, INetConnection **rgelt, ULONG *pceltFetched); 25 virtual HRESULT WINAPI Skip(ULONG celt); 26 virtual HRESULT WINAPI Reset(); 27 virtual HRESULT WINAPI Clone(IEnumNetConnection **ppenum); 28 29 private: 30 PINetConnectionItem m_pHead; 31 PINetConnectionItem m_pCurrent; 32 33 public: 34 DECLARE_NO_REGISTRY() 35 DECLARE_NOT_AGGREGATABLE(CNetConnectionManager) 36 DECLARE_PROTECT_FINAL_CONSTRUCT() 37 38 BEGIN_COM_MAP(CNetConnectionManager) 39 COM_INTERFACE_ENTRY_IID(IID_INetConnectionManager, INetConnectionManager) 40 COM_INTERFACE_ENTRY_IID(IID_IEnumNetConnection, IEnumNetConnection) 41 END_COM_MAP() 42 }; 43 44 class CNetConnection: 45 public CComObjectRootEx<CComMultiThreadModelNoCS>, 46 public INetConnection 47 { 48 private: 49 NETCON_PROPERTIES m_Props; 50 DWORD m_dwAdapterIndex; 51 52 public: 53 ~CNetConnection(); 54 HRESULT WINAPI Initialize(PINetConnectionItem pItem); 55 56 // INetConnection 57 HRESULT WINAPI Connect(); 58 HRESULT WINAPI Disconnect(); 59 HRESULT WINAPI Delete(); 60 HRESULT WINAPI Duplicate(LPCWSTR pszwDuplicateName, INetConnection **ppCon); 61 HRESULT WINAPI GetProperties(NETCON_PROPERTIES **ppProps); 62 HRESULT WINAPI GetUiObjectClassId(CLSID *pclsid); 63 HRESULT WINAPI Rename(LPCWSTR pszwDuplicateName); 64 65 DECLARE_NOT_AGGREGATABLE(CNetConnection) 66 DECLARE_PROTECT_FINAL_CONSTRUCT() 67 68 BEGIN_COM_MAP(CNetConnection) 69 COM_INTERFACE_ENTRY_IID(IID_INetConnection, INetConnection) 70 END_COM_MAP() 71 }; 72 73 BOOL GetAdapterIndexFromNetCfgInstanceId(PIP_ADAPTER_INFO pAdapterInfo, LPWSTR szNetCfg, PDWORD pIndex); 74 HRESULT WINAPI CNetConnectionManager_CreateInstance(REFIID riid, LPVOID * ppv); 75 76