ReactOS  0.4.13-dev-651-g5dbc677
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 371 of file connectmanager.cpp.

371  :
372  m_pHead(NULL),
374 {
375 }
PINetConnectionItem m_pCurrent
PINetConnectionItem m_pHead
smooth NULL
Definition: ftsmooth.c:416

Member Function Documentation

◆ Clone()

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

Definition at line 448 of file connectmanager.cpp.

449 {
450  return E_NOTIMPL;
451 }
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ EnumConnections()

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

Definition at line 379 of file connectmanager.cpp.

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

◆ EnumerateINetConnections()

HRESULT CNetConnectionManager::EnumerateINetConnections ( )

Definition at line 508 of file connectmanager.cpp.

509 {
510  DWORD dwSize, dwResult, dwIndex, dwAdapterIndex, dwShowIcon, dwNotifyDisconnect;
511  MIB_IFTABLE *pIfTable;
512  MIB_IFROW IfEntry;
513  IP_ADAPTER_INFO * pAdapterInfo;
514  HDEVINFO hInfo;
515  SP_DEVINFO_DATA DevInfo;
516  HKEY hSubKey;
517  WCHAR szNetCfg[50];
518  WCHAR szAdapterNetCfg[50];
519  WCHAR szDetail[200] = L"SYSTEM\\CurrentControlSet\\Control\\Class\\";
520  WCHAR szName[130] = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
521  PINetConnectionItem pCurrent = NULL;
522 
523  /* get the IfTable */
524  dwSize = 0;
526  return E_FAIL;
527 
528  pIfTable = static_cast<PMIB_IFTABLE>(CoTaskMemAlloc(dwSize));
529  if (!pIfTable)
530  return E_OUTOFMEMORY;
531 
532  dwResult = GetIfTable(pIfTable, &dwSize, TRUE);
533  if (dwResult != NO_ERROR)
534  {
535  CoTaskMemFree(pIfTable);
536  return HRESULT_FROM_WIN32(dwResult);
537  }
538 
539  dwSize = 0;
540  dwResult = GetAdaptersInfo(NULL, &dwSize);
541  if (dwResult!= ERROR_BUFFER_OVERFLOW)
542  {
543  CoTaskMemFree(pIfTable);
544  return HRESULT_FROM_WIN32(dwResult);
545  }
546 
547  pAdapterInfo = static_cast<PIP_ADAPTER_INFO>(CoTaskMemAlloc(dwSize));
548  if (!pAdapterInfo)
549  {
550  CoTaskMemFree(pIfTable);
551  return E_OUTOFMEMORY;
552  }
553 
554  dwResult = GetAdaptersInfo(pAdapterInfo, &dwSize);
555  if (dwResult != NO_ERROR)
556  {
557  CoTaskMemFree(pIfTable);
558  CoTaskMemFree(pAdapterInfo);
559  return HRESULT_FROM_WIN32(dwResult);
560  }
561 
562  hInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT );
563  if (!hInfo)
564  {
565  CoTaskMemFree(pIfTable);
566  CoTaskMemFree(pAdapterInfo);
567  return E_FAIL;
568  }
569 
570  dwIndex = 0;
571  do
572  {
573  ZeroMemory(&DevInfo, sizeof(SP_DEVINFO_DATA));
574  DevInfo.cbSize = sizeof(DevInfo);
575 
576  /* get device info */
577  if (!SetupDiEnumDeviceInfo(hInfo, dwIndex++, &DevInfo))
578  break;
579 
580  /* get device software registry path */
581  if (!SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_DRIVER, NULL, (LPBYTE)&szDetail[39], sizeof(szDetail)/sizeof(WCHAR) - 40, &dwSize))
582  break;
583 
584  /* open device registry key */
585  if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szDetail, 0, KEY_READ, &hSubKey) != ERROR_SUCCESS)
586  break;
587 
588  /* query NetCfgInstanceId for current device */
589  dwSize = sizeof(szNetCfg);
590  if (RegQueryValueExW(hSubKey, L"NetCfgInstanceId", NULL, NULL, (LPBYTE)szNetCfg, &dwSize) != ERROR_SUCCESS)
591  {
592  RegCloseKey(hSubKey);
593  break;
594  }
595  RegCloseKey(hSubKey);
596 
597  /* get the current adapter index from NetCfgInstanceId */
598  if (!GetAdapterIndexFromNetCfgInstanceId(pAdapterInfo, szNetCfg, &dwAdapterIndex))
599  continue;
600 
601  /* get detailed adapter info */
602  ZeroMemory(&IfEntry, sizeof(IfEntry));
603  IfEntry.dwIndex = dwAdapterIndex;
604  if (GetIfEntry(&IfEntry) != NO_ERROR)
605  break;
606 
607  /* allocate new INetConnectionItem */
608  PINetConnectionItem pNew = static_cast<PINetConnectionItem>(CoTaskMemAlloc(sizeof(INetConnectionItem)));
609  if (!pNew)
610  break;
611 
612  ZeroMemory(pNew, sizeof(INetConnectionItem));
613  pNew->dwAdapterIndex = dwAdapterIndex;
614  /* store NetCfgInstanceId */
615  CLSIDFromString(szNetCfg, &pNew->Props.guidId);
616  NormalizeOperStatus(&IfEntry, &pNew->Props);
617 
618  switch (IfEntry.dwType)
619  {
621  pNew->Props.MediaType = NCM_LAN;
622  break;
623  case IF_TYPE_IEEE80211:
625  break;
626  default:
627  break;
628  }
629  /* open network connections details */
630  wcscpy(&szName[80], szNetCfg);
631  wcscpy(&szName[118], L"\\Connection");
632 
634  {
635  /* retrieve name of connection */
636  dwSize = sizeof(szAdapterNetCfg);
637  if (RegQueryValueExW(hSubKey, L"Name", NULL, NULL, (LPBYTE)szAdapterNetCfg, &dwSize) == ERROR_SUCCESS)
638  {
639  pNew->Props.pszwName = static_cast<PWSTR>(CoTaskMemAlloc((wcslen(szAdapterNetCfg)+1) * sizeof(WCHAR)));
640  if (pNew->Props.pszwName)
641  wcscpy(pNew->Props.pszwName, szAdapterNetCfg);
642  }
643  dwSize = sizeof(dwShowIcon);
644  if (RegQueryValueExW(hSubKey, L"ShowIcon", NULL, NULL, (LPBYTE)&dwShowIcon, &dwSize) == ERROR_SUCCESS)
645  {
646  if (dwShowIcon)
648  }
649  dwSize = sizeof(dwNotifyDisconnect);
650  if (RegQueryValueExW(hSubKey, L"IpCheckingEnabled", NULL, NULL, (LPBYTE)&dwNotifyDisconnect, &dwSize) == ERROR_SUCCESS)
651  {
652  if (dwNotifyDisconnect)
654  }
655  RegCloseKey(hSubKey);
656  }
657 
658  /* Get the adapter device description */
659  dwSize = 0;
661  if (dwSize != 0)
662  {
663  pNew->Props.pszwDeviceName = static_cast<PWSTR>(CoTaskMemAlloc(dwSize));
664  if (pNew->Props.pszwDeviceName)
666  }
667 
668  if (pCurrent)
669  pCurrent->Next = pNew;
670  else
671  m_pHead = pNew;
672 
673  pCurrent = pNew;
674  } while (TRUE);
675 
676  CoTaskMemFree(pIfTable);
677  CoTaskMemFree(pAdapterInfo);
679 
681  return (m_pHead != NULL ? S_OK : S_FALSE);
682 }
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1792
BOOL GetAdapterIndexFromNetCfgInstanceId(PIP_ADAPTER_INFO pAdapterInfo, LPWSTR szNetCfg, PDWORD pIndex)
#define TRUE
Definition: types.h:120
LPWSTR pszwDeviceName
Definition: netcon.h:85
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:422
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD dwType
Definition: ifmib.h:39
#define KEY_READ
Definition: nt_native.h:1023
#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:3229
#define ZeroMemory
Definition: winbase.h:1635
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:52
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define S_FALSE
Definition: winerror.h:2357
#define NCCF_NOTIFY_DISCONNECTED
Definition: precomp.h:76
smooth NULL
Definition: ftsmooth.c:416
#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:2898
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:59
#define IF_TYPE_ETHERNET_CSMACD
Definition: ipifcons.h:26
NETCON_MEDIATYPE MediaType
Definition: netcon.h:87
DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow)
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:2247
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:406
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#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 684 of file connectmanager.cpp.

685 {
687  if (FAILED_UNEXPECTEDLY(hr))
688  {
689  /* If something went wrong during the enumeration print an error don't enumerate anything */
690  m_pCurrent = m_pHead = NULL;
691  return S_FALSE;
692  }
693  return S_OK;
694 }
HRESULT EnumerateINetConnections()
HRESULT hr
Definition: shlfolder.c:183
PINetConnectionItem m_pCurrent
PINetConnectionItem m_pHead
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
LONG HRESULT
Definition: typedefs.h:77
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:35
#define S_OK
Definition: intsafe.h:59

◆ Next()

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

Definition at line 402 of file connectmanager.cpp.

406 {
407  HRESULT hr;
408 
409  if (!pceltFetched || !rgelt)
410  return E_POINTER;
411 
412  if (celt != 1)
413  return E_FAIL;
414 
415  if (!m_pCurrent)
416  return S_FALSE;
417 
420 
421  return hr;
422 }
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:77
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 440 of file connectmanager.cpp.

441 {
443  return S_OK;
444 }
PINetConnectionItem m_pCurrent
PINetConnectionItem m_pHead
#define S_OK
Definition: intsafe.h:59

◆ Skip()

HRESULT WINAPI CNetConnectionManager::Skip ( ULONG  celt)
virtual

Definition at line 426 of file connectmanager.cpp.

427 {
428  while (m_pCurrent && celt-- > 0)
430 
431  if (celt)
432  return S_FALSE;
433  else
434  return S_OK;
435 
436 }
PINetConnectionItem m_pCurrent
#define S_FALSE
Definition: winerror.h:2357
struct tagINetConnectionItem * Next
Definition: connectmanager.h:4
#define S_OK
Definition: intsafe.h:59

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: