ReactOS  0.4.15-dev-2956-g61e7ea5
CNetConnectionManager Class Reference

#include <connectmanager.h>

Inheritance diagram for CNetConnectionManager:
Collaboration diagram for CNetConnectionManager:

Public Member Functions

 CNetConnectionManager ()
 
HRESULT Initialize ()
 
HRESULT EnumerateINetConnections ()
 
virtual HRESULT WINAPI EnumConnections (NETCONMGR_ENUM_FLAGS Flags, IEnumNetConnection **ppEnum)
 
virtual HRESULT WINAPI Next (ULONG celt, INetConnection **rgelt, ULONG *pceltFetched)
 
virtual HRESULT WINAPI Skip (ULONG celt)
 
virtual HRESULT WINAPI Reset ()
 
virtual HRESULT WINAPI Clone (IEnumNetConnection **ppenum)
 
- Public Member Functions inherited from ATL::CComObjectRootEx< CComMultiThreadModelNoCS >
 ~CComObjectRootEx ()
 
ULONG InternalAddRef ()
 
ULONG InternalRelease ()
 
void Lock ()
 
void Unlock ()
 
HRESULT _AtlInitialConstruct ()
 
- Public Member Functions inherited from ATL::CComObjectRootBase
 CComObjectRootBase ()
 
 ~CComObjectRootBase ()
 
void SetVoid (void *)
 
HRESULT _AtlFinalConstruct ()
 
HRESULT FinalConstruct ()
 
void InternalFinalConstructAddRef ()
 
void InternalFinalConstructRelease ()
 
void FinalRelease ()
 

Private Attributes

PINetConnectionItem m_pHead
 
PINetConnectionItem m_pCurrent
 

Additional Inherited Members

- Static Public Member Functions inherited from ATL::CComObjectRootBase
static void WINAPI ObjectMain (bool)
 
static const struct _ATL_CATMAP_ENTRYGetCategoryMap ()
 
static HRESULT WINAPI InternalQueryInterface (void *pThis, const _ATL_INTMAP_ENTRY *pEntries, REFIID iid, void **ppvObject)
 
- Public Attributes inherited from ATL::CComObjectRootBase
LONG m_dwRef
 

Detailed Description

Definition at line 9 of file connectmanager.h.

Constructor & Destructor Documentation

◆ CNetConnectionManager()

CNetConnectionManager::CNetConnectionManager ( )

Definition at line 377 of file connectmanager.cpp.

377  :
378  m_pHead(NULL),
380 {
381 }
PINetConnectionItem m_pCurrent
PINetConnectionItem m_pHead
#define NULL
Definition: types.h:112

Member Function Documentation

◆ Clone()

HRESULT WINAPI CNetConnectionManager::Clone ( IEnumNetConnection **  ppenum)
virtual

Definition at line 454 of file connectmanager.cpp.

455 {
456  return E_NOTIMPL;
457 }
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ EnumConnections()

HRESULT WINAPI CNetConnectionManager::EnumConnections ( NETCONMGR_ENUM_FLAGS  Flags,
IEnumNetConnection **  ppEnum 
)
virtual

Definition at line 385 of file connectmanager.cpp.

388 {
389  TRACE("EnumConnections\n");
390 
391  if (!ppEnum)
392  return E_POINTER;
393 
394  if (Flags != NCME_DEFAULT)
395  return E_FAIL;
396 
397  *ppEnum = static_cast<IEnumNetConnection*>(this);
398  AddRef();
399  return S_OK;
400 }
#define E_FAIL
Definition: ddrawi.h:102
#define TRACE(s)
Definition: solgame.cpp:4
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define S_OK
Definition: intsafe.h:52
static ULONG WINAPI AddRef(IStream *iface)
Definition: clist.c:90
#define E_POINTER
Definition: winerror.h:2365

◆ EnumerateINetConnections()

HRESULT CNetConnectionManager::EnumerateINetConnections ( )

Definition at line 514 of file connectmanager.cpp.

515 {
516  DWORD dwSize, dwResult, dwIndex, dwAdapterIndex, dwShowIcon, dwNotifyDisconnect;
517  MIB_IFTABLE *pIfTable;
518  MIB_IFROW IfEntry;
519  IP_ADAPTER_INFO * pAdapterInfo;
520  HDEVINFO hInfo;
521  SP_DEVINFO_DATA DevInfo;
522  HKEY hSubKey;
523  WCHAR szNetCfg[50];
524  WCHAR szAdapterNetCfg[50];
525  WCHAR szDetail[200] = L"SYSTEM\\CurrentControlSet\\Control\\Class\\";
526  WCHAR szName[130] = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
527  PINetConnectionItem pCurrent = NULL;
528 
529  /* get the IfTable */
530  dwSize = 0;
532  return E_FAIL;
533 
534  pIfTable = static_cast<PMIB_IFTABLE>(CoTaskMemAlloc(dwSize));
535  if (!pIfTable)
536  return E_OUTOFMEMORY;
537 
538  dwResult = GetIfTable(pIfTable, &dwSize, TRUE);
539  if (dwResult != NO_ERROR)
540  {
541  CoTaskMemFree(pIfTable);
542  return HRESULT_FROM_WIN32(dwResult);
543  }
544 
545  dwSize = 0;
546  dwResult = GetAdaptersInfo(NULL, &dwSize);
547  if (dwResult!= ERROR_BUFFER_OVERFLOW)
548  {
549  CoTaskMemFree(pIfTable);
550  return HRESULT_FROM_WIN32(dwResult);
551  }
552 
553  pAdapterInfo = static_cast<PIP_ADAPTER_INFO>(CoTaskMemAlloc(dwSize));
554  if (!pAdapterInfo)
555  {
556  CoTaskMemFree(pIfTable);
557  return E_OUTOFMEMORY;
558  }
559 
560  dwResult = GetAdaptersInfo(pAdapterInfo, &dwSize);
561  if (dwResult != NO_ERROR)
562  {
563  CoTaskMemFree(pIfTable);
564  CoTaskMemFree(pAdapterInfo);
565  return HRESULT_FROM_WIN32(dwResult);
566  }
567 
568  hInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT );
569  if (!hInfo)
570  {
571  CoTaskMemFree(pIfTable);
572  CoTaskMemFree(pAdapterInfo);
573  return E_FAIL;
574  }
575 
576  dwIndex = 0;
577  do
578  {
579  ZeroMemory(&DevInfo, sizeof(SP_DEVINFO_DATA));
580  DevInfo.cbSize = sizeof(DevInfo);
581 
582  /* get device info */
583  if (!SetupDiEnumDeviceInfo(hInfo, dwIndex++, &DevInfo))
584  break;
585 
586  /* get device software registry path */
587  if (!SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_DRIVER, NULL, (LPBYTE)&szDetail[39], sizeof(szDetail)/sizeof(WCHAR) - 40, &dwSize))
588  break;
589 
590  /* open device registry key */
591  if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szDetail, 0, KEY_READ, &hSubKey) != ERROR_SUCCESS)
592  break;
593 
594  /* query NetCfgInstanceId for current device */
595  dwSize = sizeof(szNetCfg);
596  if (RegQueryValueExW(hSubKey, L"NetCfgInstanceId", NULL, NULL, (LPBYTE)szNetCfg, &dwSize) != ERROR_SUCCESS)
597  {
598  RegCloseKey(hSubKey);
599  break;
600  }
601  RegCloseKey(hSubKey);
602 
603  /* get the current adapter index from NetCfgInstanceId */
604  if (!GetAdapterIndexFromNetCfgInstanceId(pAdapterInfo, szNetCfg, &dwAdapterIndex))
605  continue;
606 
607  /* get detailed adapter info */
608  ZeroMemory(&IfEntry, sizeof(IfEntry));
609  IfEntry.dwIndex = dwAdapterIndex;
610  if (GetIfEntry(&IfEntry) != NO_ERROR)
611  break;
612 
613  /* allocate new INetConnectionItem */
614  PINetConnectionItem pNew = static_cast<PINetConnectionItem>(CoTaskMemAlloc(sizeof(INetConnectionItem)));
615  if (!pNew)
616  break;
617 
618  ZeroMemory(pNew, sizeof(INetConnectionItem));
619  pNew->dwAdapterIndex = dwAdapterIndex;
620  /* store NetCfgInstanceId */
621  CLSIDFromString(szNetCfg, &pNew->Props.guidId);
622  NormalizeOperStatus(&IfEntry, &pNew->Props);
623 
624  switch (IfEntry.dwType)
625  {
627  pNew->Props.MediaType = NCM_LAN;
628  break;
629  case IF_TYPE_IEEE80211:
631  break;
632  default:
633  break;
634  }
635  /* open network connections details */
636  wcscpy(&szName[80], szNetCfg);
637  wcscpy(&szName[118], L"\\Connection");
638 
640  {
641  /* retrieve name of connection */
642  dwSize = sizeof(szAdapterNetCfg);
643  if (RegQueryValueExW(hSubKey, L"Name", NULL, NULL, (LPBYTE)szAdapterNetCfg, &dwSize) == ERROR_SUCCESS)
644  {
645  pNew->Props.pszwName = static_cast<PWSTR>(CoTaskMemAlloc((wcslen(szAdapterNetCfg)+1) * sizeof(WCHAR)));
646  if (pNew->Props.pszwName)
647  wcscpy(pNew->Props.pszwName, szAdapterNetCfg);
648  }
649  dwSize = sizeof(dwShowIcon);
650  if (RegQueryValueExW(hSubKey, L"ShowIcon", NULL, NULL, (LPBYTE)&dwShowIcon, &dwSize) == ERROR_SUCCESS)
651  {
652  if (dwShowIcon)
654  }
655  dwSize = sizeof(dwNotifyDisconnect);
656  if (RegQueryValueExW(hSubKey, L"IpCheckingEnabled", NULL, NULL, (LPBYTE)&dwNotifyDisconnect, &dwSize) == ERROR_SUCCESS)
657  {
658  if (dwNotifyDisconnect)
660  }
661  RegCloseKey(hSubKey);
662  }
663 
664  /* Get the adapter device description */
665  dwSize = 0;
667  if (dwSize != 0)
668  {
669  pNew->Props.pszwDeviceName = static_cast<PWSTR>(CoTaskMemAlloc(dwSize));
670  if (pNew->Props.pszwDeviceName)
672  }
673 
674  if (pCurrent)
675  pCurrent->Next = pNew;
676  else
677  m_pHead = pNew;
678 
679  pCurrent = pNew;
680  } while (TRUE);
681 
682  CoTaskMemFree(pIfTable);
683  CoTaskMemFree(pAdapterInfo);
685 
687  return (m_pHead != NULL ? S_OK : S_FALSE);
688 }
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1783
BOOL GetAdapterIndexFromNetCfgInstanceId(PIP_ADAPTER_INFO pAdapterInfo, LPWSTR szNetCfg, PDWORD pIndex)
LPWSTR pszwDeviceName
Definition: netcon.h:85
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD dwType
Definition: ifmib.h:39
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Property, PDWORD PropertyRegDataType, PBYTE PropertyBuffer, DWORD PropertyBufferSize, PDWORD RequiredSize)
Definition: devinst.c:3220
#define ZeroMemory
Definition: winbase.h:1664
PINetConnectionItem m_pCurrent
#define NO_ERROR
Definition: dderror.h:5
#define E_FAIL
Definition: ddrawi.h:102
PINetConnectionItem m_pHead
DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define S_FALSE
Definition: winerror.h:2357
#define NCCF_NOTIFY_DISCONNECTED
Definition: precomp.h:76
#define IF_TYPE_IEEE80211
Definition: ipifcons.h:91
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2889
Definition: netcon.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID NormalizeOperStatus(MIB_IFROW *IfEntry, NETCON_PROPERTIES *Props)
NETCON_PROPERTIES Props
Definition: connectmanager.h:6
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define SetupDiGetClassDevs
Definition: setupapi.h:2588
#define SPDRP_DEVICEDESC
Definition: setupapi.h:502
struct tagINetConnectionItem * Next
Definition: connectmanager.h:4
#define S_OK
Definition: intsafe.h:52
#define IF_TYPE_ETHERNET_CSMACD
Definition: ipifcons.h:26
NETCON_MEDIATYPE MediaType
Definition: netcon.h:87
DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
static const WCHAR szName[]
Definition: msipriv.h:1194
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2338
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
DWORD dwIndex
Definition: ifmib.h:38
BYTE * PBYTE
Definition: pedump.c:66
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define DIGCF_PRESENT
Definition: setupapi.h:171
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define SPDRP_DRIVER
Definition: setupapi.h:511
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by Initialize().

◆ Initialize()

HRESULT CNetConnectionManager::Initialize ( )

Definition at line 690 of file connectmanager.cpp.

691 {
693  if (FAILED_UNEXPECTEDLY(hr))
694  {
695  /* If something went wrong during the enumeration print an error don't enumerate anything */
696  m_pCurrent = m_pHead = NULL;
697  return S_FALSE;
698  }
699  return S_OK;
700 }
HRESULT EnumerateINetConnections()
HRESULT hr
Definition: shlfolder.c:183
PINetConnectionItem m_pCurrent
PINetConnectionItem m_pHead
#define S_FALSE
Definition: winerror.h:2357
LONG HRESULT
Definition: typedefs.h:79
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:82
#define S_OK
Definition: intsafe.h:52
#define NULL
Definition: types.h:112

◆ Next()

HRESULT WINAPI CNetConnectionManager::Next ( ULONG  celt,
INetConnection **  rgelt,
ULONG pceltFetched 
)
virtual

Definition at line 408 of file connectmanager.cpp.

412 {
413  HRESULT hr;
414 
415  if (!pceltFetched || !rgelt)
416  return E_POINTER;
417 
418  if (celt != 1)
419  return E_FAIL;
420 
421  if (!m_pCurrent)
422  return S_FALSE;
423 
426 
427  return hr;
428 }
HRESULT hr
Definition: shlfolder.c:183
PINetConnectionItem m_pCurrent
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
#define S_FALSE
Definition: winerror.h:2357
LONG HRESULT
Definition: typedefs.h:79
struct tagINetConnectionItem * Next
Definition: connectmanager.h:4
HRESULT WINAPI CNetConnection_CreateInstance(PINetConnectionItem pItem, REFIID riid, LPVOID *ppv)
#define E_POINTER
Definition: winerror.h:2365

◆ Reset()

HRESULT WINAPI CNetConnectionManager::Reset ( void  )
virtual

Definition at line 446 of file connectmanager.cpp.

447 {
449  return S_OK;
450 }
PINetConnectionItem m_pCurrent
PINetConnectionItem m_pHead
#define S_OK
Definition: intsafe.h:52

◆ Skip()

HRESULT WINAPI CNetConnectionManager::Skip ( ULONG  celt)
virtual

Definition at line 432 of file connectmanager.cpp.

433 {
434  while (m_pCurrent && celt-- > 0)
436 
437  if (celt)
438  return S_FALSE;
439  else
440  return S_OK;
441 
442 }
PINetConnectionItem m_pCurrent
#define S_FALSE
Definition: winerror.h:2357
struct tagINetConnectionItem * Next
Definition: connectmanager.h:4
#define S_OK
Definition: intsafe.h:52

Member Data Documentation

◆ m_pCurrent

PINetConnectionItem CNetConnectionManager::m_pCurrent
private

Definition at line 31 of file connectmanager.h.

Referenced by EnumerateINetConnections(), Initialize(), Next(), Reset(), and Skip().

◆ m_pHead

PINetConnectionItem CNetConnectionManager::m_pHead
private

Definition at line 30 of file connectmanager.h.

Referenced by EnumerateINetConnections(), Initialize(), and Reset().


The documentation for this class was generated from the following files: