ReactOS 0.4.15-dev-8413-gc1c91f2
CNetConnectionManager Class Reference

#include <connectmanager.h>

Inheritance diagram for CNetConnectionManager:
Collaboration diagram for CNetConnectionManager:

Public Member Functions

 CNetConnectionManager ()
 
HRESULT Initialize ()
 
HRESULT EnumerateINetConnections ()
 
STDMETHOD() EnumConnections (NETCONMGR_ENUM_FLAGS Flags, IEnumNetConnection **ppEnum) override
 
STDMETHOD() Next (ULONG celt, INetConnection **rgelt, ULONG *pceltFetched) override
 
STDMETHOD() Skip (ULONG celt) override
 
STDMETHOD() Reset () override
 
STDMETHOD() Clone (IEnumNetConnection **ppenum) override
 
- 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 381 of file connectmanager.cpp.

381 :
382 m_pHead(NULL),
384{
385}
PINetConnectionItem m_pCurrent
PINetConnectionItem m_pHead
#define NULL
Definition: types.h:112

Member Function Documentation

◆ Clone()

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

Definition at line 458 of file connectmanager.cpp.

459{
460 return E_NOTIMPL;
461}
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ EnumConnections()

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

Definition at line 389 of file connectmanager.cpp.

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

◆ EnumerateINetConnections()

HRESULT CNetConnectionManager::EnumerateINetConnections ( )

Definition at line 518 of file connectmanager.cpp.

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

Referenced by Initialize().

◆ Initialize()

HRESULT CNetConnectionManager::Initialize ( )

Definition at line 694 of file connectmanager.cpp.

695{
698 {
699 /* If something went wrong during the enumeration print an error don't enumerate anything */
701 return S_FALSE;
702 }
703 return S_OK;
704}
HRESULT EnumerateINetConnections()
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
HRESULT hr
Definition: shlfolder.c:183

◆ Next()

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

Definition at line 412 of file connectmanager.cpp.

416{
417 HRESULT hr;
418
419 if (!pceltFetched || !rgelt)
420 return E_POINTER;
421
422 if (celt != 1)
423 return E_FAIL;
424
425 if (!m_pCurrent)
426 return S_FALSE;
427
430
431 return hr;
432}
HRESULT WINAPI CNetConnection_CreateInstance(PINetConnectionItem pItem, REFIID riid, LPVOID *ppv)
#define IID_PPV_ARG(Itype, ppType)

◆ Reset()

HRESULT WINAPI CNetConnectionManager::Reset ( )
override

Definition at line 450 of file connectmanager.cpp.

451{
453 return S_OK;
454}

◆ Skip()

HRESULT WINAPI CNetConnectionManager::Skip ( ULONG  celt)
override

Definition at line 436 of file connectmanager.cpp.

437{
438 while (m_pCurrent && celt-- > 0)
440
441 if (celt)
442 return S_FALSE;
443 else
444 return S_OK;
445
446}

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: