Author: janderwald Date: Wed Aug 27 21:57:10 2008 New Revision: 35718
URL: http://svn.reactos.org/svn/reactos?rev=35718&view=rev Log: - Use CoTaskMemAlloc / CoTaskMemFree for memory de-allocation - Implement INetConnectionManager, IEnumNetConnection, INetConnection interface for CLSID_ConnectionManager - Refactor Network Connections Shell Folder enumeration code to use the now available COM functionality
Added: trunk/reactos/dll/win32/netshell/connectmanager.c (with props) Modified: trunk/reactos/dll/win32/netshell/classfactory.c trunk/reactos/dll/win32/netshell/enumlist.c trunk/reactos/dll/win32/netshell/netshell.c trunk/reactos/dll/win32/netshell/netshell.rbuild trunk/reactos/dll/win32/netshell/precomp.h trunk/reactos/dll/win32/netshell/shfldr_netconnect.c
Modified: trunk/reactos/dll/win32/netshell/classfactory.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/classfac... ============================================================================== --- trunk/reactos/dll/win32/netshell/classfactory.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/classfactory.c [iso-8859-1] Wed Aug 27 21:57:10 2008 @@ -54,7 +54,7 @@
if (!refCount) { - HeapFree(GetProcessHeap(),0,This); + CoTaskMemFree(This); return 0; } return refCount; @@ -110,7 +110,7 @@ { IClassFactoryImpl* lpclf;
- lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IClassFactoryImpl)); + lpclf = CoTaskMemAlloc(sizeof(IClassFactoryImpl)); lpclf->ref = 1; lpclf->lpVtbl = &dclfvt; lpclf->lpfnCI = lpfnCI;
Added: trunk/reactos/dll/win32/netshell/connectmanager.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/connectm... ============================================================================== --- trunk/reactos/dll/win32/netshell/connectmanager.c (added) +++ trunk/reactos/dll/win32/netshell/connectmanager.c [iso-8859-1] Wed Aug 27 21:57:10 2008 @@ -1,0 +1,693 @@ +#include <precomp.h> + +typedef struct tagINetConnectionItem +{ + struct tagINetConnectionItem * Next; + NETCON_PROPERTIES Props; +}INetConnectionItem, *PINetConnectionItem; + +typedef struct +{ + const INetConnectionManagerVtbl * lpVtbl; + const IEnumNetConnectionVtbl * lpVtblNetConnection; + LONG ref; + PINetConnectionItem pHead; + PINetConnectionItem pCurrent; + +} INetConnectionManagerImpl, *LPINetConnectionManagerImpl; + +typedef struct +{ + const INetConnectionVtbl * lpVtbl; + LONG ref; + NETCON_PROPERTIES Props; +} INetConnectionImpl, *LPINetConnectionImpl; + + +static LPINetConnectionManagerImpl __inline impl_from_EnumNetConnection(IEnumNetConnection *iface) +{ + return (LPINetConnectionManagerImpl)((char *)iface - FIELD_OFFSET(INetConnectionManagerImpl, lpVtblNetConnection)); +} + + +static +HRESULT +WINAPI +INetConnectionManager_fnQueryInterface( + INetConnectionManager * iface, + REFIID iid, + LPVOID * ppvObj) +{ + INetConnectionManagerImpl * This = (INetConnectionManagerImpl*)iface; + *ppvObj = NULL; + + if (IsEqualIID (iid, &IID_IUnknown) || + IsEqualIID (iid, &IID_INetConnectionManager)) + { + *ppvObj = This; + INetConnectionManager_AddRef(iface); + return S_OK; + } + + return E_NOINTERFACE; +} + +static +ULONG +WINAPI +INetConnectionManager_fnAddRef( + INetConnectionManager * iface) +{ + INetConnectionManagerImpl * This = (INetConnectionManagerImpl*)iface; + ULONG refCount = InterlockedIncrement(&This->ref); + + return refCount; +} + +static +ULONG +WINAPI +INetConnectionManager_fnRelease( + INetConnectionManager * iface) +{ + INetConnectionManagerImpl * This = (INetConnectionManagerImpl*)iface; + ULONG refCount = InterlockedDecrement(&This->ref); + + if (!refCount) + { + CoTaskMemFree (This); + } + return refCount; +} + +static +HRESULT +WINAPI +INetConnectionManager_fnEnumConnections( + INetConnectionManager * iface, + NETCONMGR_ENUM_FLAGS Flags, + IEnumNetConnection **ppEnum) +{ + INetConnectionManagerImpl * This = (INetConnectionManagerImpl*)iface; + + if (!ppEnum) + return E_POINTER; + + if (Flags != NCME_DEFAULT) + return E_FAIL; + + *ppEnum = (IEnumNetConnection *)&This->lpVtblNetConnection; + INetConnectionManager_AddRef(iface); + return S_OK; +} + +static const INetConnectionManagerVtbl vt_NetConnectionManager = +{ + INetConnectionManager_fnQueryInterface, + INetConnectionManager_fnAddRef, + INetConnectionManager_fnRelease, + INetConnectionManager_fnEnumConnections, +}; + +/*************************************************************** + * INetConnection Interface + */ + +static +HRESULT +WINAPI +INetConnection_fnQueryInterface( + INetConnection * iface, + REFIID iid, + LPVOID * ppvObj) +{ + INetConnectionImpl * This = (INetConnectionImpl*)iface; + *ppvObj = NULL; + + if (IsEqualIID (iid, &IID_IUnknown) || + IsEqualIID (iid, &IID_INetConnection)) + { + *ppvObj = This; + INetConnection_AddRef(iface); + return S_OK; + } + + return E_NOINTERFACE; +} + +static +ULONG +WINAPI +INetConnection_fnAddRef( + INetConnection * iface) +{ + INetConnectionImpl * This = (INetConnectionImpl*)iface; + ULONG refCount = InterlockedIncrement(&This->ref); + + return refCount; +} + +static +ULONG +WINAPI +INetConnection_fnRelease( + INetConnection * iface) +{ + INetConnectionImpl * This = (INetConnectionImpl*)iface; + ULONG refCount = InterlockedDecrement(&This->ref); + + if (!refCount) + { + CoTaskMemFree(This->Props.pszwName); + CoTaskMemFree(This->Props.pszwDeviceName); + CoTaskMemFree(This); + } + return refCount; +} + +static +HRESULT +WINAPI +INetConnection_fnConnect( + INetConnection * iface) +{ + return E_NOTIMPL; +} + +static +HRESULT +WINAPI +INetConnection_fnDisconnect( + INetConnection * iface) +{ + return E_NOTIMPL; +} + + +static +HRESULT +WINAPI +INetConnection_fnDelete( + INetConnection * iface) +{ + return E_NOTIMPL; +} + +static +HRESULT +WINAPI +INetConnection_fnDuplicate( + INetConnection * iface, + LPCWSTR pszwDuplicateName, + INetConnection **ppCon) +{ + return E_NOTIMPL; +} + +static +HRESULT +WINAPI +INetConnection_fnGetProperties( + INetConnection * iface, + NETCON_PROPERTIES **ppProps) +{ +#if 0 + NETCON_PROPERTIES * pProperties; +#endif + INetConnectionImpl * This = (INetConnectionImpl*)iface; + + if (!ppProps) + return E_POINTER; + +#if 1 + *ppProps = &This->Props; +#else + pProperties = CoTaskMemAlloc(sizeof(NETCON_PROPERTIES)); + if (!pProperties) + return E_OUTOFMEMORY; + + CopyMemory(pProperties, &This->Props, sizeof(NETCON_PROPERTIES)); + if (This->Props.pszwName) + { + pProperties->pszwName = CoTaskMemAlloc((wcslen(This->Props.pszwName)+1)*sizeof(WCHAR)); + if (pProperties->pszwName) + wcscpy(pProperties->pszwName, This->Props.pszwName); + } + if (This->Props.pszwDeviceName) + { + pProperties->pszwDeviceName = CoTaskMemAlloc((wcslen(This->Props.pszwDeviceName)+1)*sizeof(WCHAR)); + if (pProperties->pszwDeviceName) + wcscpy(pProperties->pszwDeviceName, This->Props.pszwDeviceName); + } + + *ppProps = pProperties; +#endif + return NOERROR; +} + +static +HRESULT +WINAPI +INetConnection_fnGetUiObjectClassId( + INetConnection * iface, + CLSID *pclsid) +{ + return E_NOTIMPL; +} + +static +HRESULT +WINAPI +INetConnection_fnRename( + INetConnection * iface, + LPCWSTR pszwDuplicateName) +{ + return E_NOTIMPL; +} + + +static const INetConnectionVtbl vt_NetConnection = +{ + INetConnection_fnQueryInterface, + INetConnection_fnAddRef, + INetConnection_fnRelease, + INetConnection_fnConnect, + INetConnection_fnDisconnect, + INetConnection_fnDelete, + INetConnection_fnDuplicate, + INetConnection_fnGetProperties, + INetConnection_fnGetUiObjectClassId, + INetConnection_fnRename +}; + +HRESULT WINAPI IConnection_Constructor (INetConnection **ppv, PINetConnectionItem pItem) +{ + INetConnectionImpl *This; + + if (!ppv) + return E_POINTER; + + This = (INetConnectionImpl *) CoTaskMemAlloc(sizeof (INetConnectionImpl)); + if (!This) + return E_OUTOFMEMORY; + + This->ref = 1; + This->lpVtbl = &vt_NetConnection; + + CopyMemory(&This->Props, &pItem->Props, sizeof(NETCON_PROPERTIES)); + + This->Props.pszwName = CoTaskMemAlloc((wcslen(pItem->Props.pszwName)+1)*sizeof(WCHAR)); + if (This->Props.pszwName) + wcscpy(This->Props.pszwName, pItem->Props.pszwName); + + This->Props.pszwDeviceName = CoTaskMemAlloc((wcslen(pItem->Props.pszwDeviceName)+1)*sizeof(WCHAR)); + if (This->Props.pszwDeviceName) + wcscpy(This->Props.pszwDeviceName, pItem->Props.pszwDeviceName); + + *ppv = (INetConnection *)This; + + + return S_OK; +} + + +/*************************************************************** + * IEnumNetConnection Interface + */ + +static +HRESULT +WINAPI +IEnumNetConnection_fnQueryInterface( + IEnumNetConnection * iface, + REFIID iid, + LPVOID * ppvObj) +{ + INetConnectionManagerImpl * This = impl_from_EnumNetConnection(iface); + *ppvObj = NULL; + + if (IsEqualIID (iid, &IID_IUnknown) || + IsEqualIID (iid, &IID_INetConnectionManager)) + { + *ppvObj = This; + INetConnectionManager_AddRef(iface); + return S_OK; + } + + return E_NOINTERFACE; +} + +static +ULONG +WINAPI +IEnumNetConnection_fnAddRef( + IEnumNetConnection * iface) +{ + INetConnectionManagerImpl * This = impl_from_EnumNetConnection(iface); + ULONG refCount = InterlockedIncrement(&This->ref); + + return refCount; +} + +static +ULONG +WINAPI +IEnumNetConnection_fnRelease( + IEnumNetConnection * iface) +{ + INetConnectionManagerImpl * This = impl_from_EnumNetConnection(iface); + ULONG refCount = InterlockedDecrement(&This->ref); + + if (!refCount) + { + CoTaskMemFree (This); + } + return refCount; +} + +static +HRESULT +WINAPI +IEnumNetConnection_fnNext( + IEnumNetConnection * iface, + ULONG celt, + INetConnection **rgelt, + ULONG *pceltFetched) +{ + INetConnectionManagerImpl * This = impl_from_EnumNetConnection(iface); + HRESULT hr; + + if (!pceltFetched || !rgelt) + return E_POINTER; + + if (celt != 1) + return E_FAIL; + + if (!This->pCurrent) + return S_FALSE; + + hr = IConnection_Constructor(rgelt, This->pCurrent); + This->pCurrent = This->pCurrent->Next; + + return hr; +} + +static +HRESULT +WINAPI +IEnumNetConnection_fnSkip( + IEnumNetConnection * iface, + ULONG celt) +{ + INetConnectionManagerImpl * This = impl_from_EnumNetConnection(iface); + + while(This->pCurrent && celt-- > 0) + This->pCurrent = This->pCurrent->Next; + + if (celt) + return S_FALSE; + else + return NOERROR; + +} + +static +HRESULT +WINAPI +IEnumNetConnection_fnReset( + IEnumNetConnection * iface) +{ + INetConnectionManagerImpl * This = impl_from_EnumNetConnection(iface); + + This->pCurrent = This->pHead; + return NOERROR; +} + +static +HRESULT +WINAPI +IEnumNetConnection_fnClone( + IEnumNetConnection * iface, + IEnumNetConnection **ppenum) +{ + return E_NOTIMPL; +} + +static const IEnumNetConnectionVtbl vt_EnumNetConnection = +{ + IEnumNetConnection_fnQueryInterface, + IEnumNetConnection_fnAddRef, + IEnumNetConnection_fnRelease, + IEnumNetConnection_fnNext, + IEnumNetConnection_fnSkip, + IEnumNetConnection_fnReset, + IEnumNetConnection_fnClone +}; + +static +BOOL +GetAdapterIndexFromNetCfgInstanceId(PIP_ADAPTER_INFO pAdapterInfo, LPWSTR szNetCfg, PDWORD pIndex) +{ + WCHAR szBuffer[50]; + IP_ADAPTER_INFO * pCurrentAdapter; + + pCurrentAdapter = pAdapterInfo; + while(pCurrentAdapter) + { + szBuffer[0] = L'\0'; + if (MultiByteToWideChar(CP_ACP, 0, pCurrentAdapter->AdapterName, -1, szBuffer, sizeof(szBuffer)/sizeof(szBuffer[0]))) + { + szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0'; + } + if (!wcsicmp(szBuffer, szNetCfg)) + { + *pIndex = pCurrentAdapter->Index; + return TRUE; + } + pCurrentAdapter = pCurrentAdapter->Next; + } + return FALSE; +} + + +static +BOOL +EnumerateINetConnections(INetConnectionManagerImpl *This) +{ + DWORD dwSize, dwResult, dwIndex, dwAdapterIndex, dwShowIcon; + MIB_IFTABLE *pIfTable; + MIB_IFROW IfEntry; + IP_ADAPTER_INFO * pAdapterInfo; + HDEVINFO hInfo; + SP_DEVINFO_DATA DevInfo; + HKEY hSubKey; + WCHAR szNetCfg[50]; + WCHAR szAdapterNetCfg[50]; + WCHAR szDetail[200] = L"SYSTEM\CurrentControlSet\Control\Class\"; + WCHAR szName[130] = L"SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\"; + PINetConnectionItem pNew; + PINetConnectionItem pCurrent = NULL; + + /* get the IfTable */ + dwSize = 0; + if (GetIfTable(NULL, &dwSize, TRUE) != ERROR_INSUFFICIENT_BUFFER) + return FALSE; + + pIfTable = (PMIB_IFTABLE)CoTaskMemAlloc(dwSize); + if (!pIfTable) + return FALSE; + + dwResult = GetIfTable(pIfTable, &dwSize, TRUE); + if (dwResult != NO_ERROR) + { + CoTaskMemFree(pIfTable); + return FALSE; + } + + dwSize = 0; + dwResult = GetAdaptersInfo(NULL, &dwSize); + if (dwResult!= ERROR_BUFFER_OVERFLOW) + { + CoTaskMemFree(pIfTable); + return FALSE; + } + + pAdapterInfo = (PIP_ADAPTER_INFO)CoTaskMemAlloc(dwSize); + if (!pAdapterInfo) + { + CoTaskMemFree(pIfTable); + return FALSE; + } + + if (GetAdaptersInfo(pAdapterInfo, &dwSize) != NO_ERROR) + { + CoTaskMemFree(pIfTable); + CoTaskMemFree(pAdapterInfo); + return FALSE; + } + + + hInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT ); + if (!hInfo) + { + CoTaskMemFree(pIfTable); + CoTaskMemFree(pAdapterInfo); + return FALSE; + } + + dwIndex = 0; + do + { + ZeroMemory(&DevInfo, sizeof(SP_DEVINFO_DATA)); + DevInfo.cbSize = sizeof(DevInfo); + + /* get device info */ + if (!SetupDiEnumDeviceInfo(hInfo, dwIndex++, &DevInfo)) + break; + + /* get device software registry path */ + if (!SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_DRIVER, NULL, (LPBYTE)&szDetail[39], sizeof(szDetail)/sizeof(WCHAR) - 40, &dwSize)) + break; + + /* open device registry key */ + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szDetail, 0, KEY_READ, &hSubKey) != ERROR_SUCCESS) + break; + + /* query NetCfgInstanceId for current device */ + dwSize = sizeof(szNetCfg); + if (RegQueryValueExW(hSubKey, L"NetCfgInstanceId", NULL, NULL, (LPBYTE)szNetCfg, &dwSize) != ERROR_SUCCESS) + { + RegCloseKey(hSubKey); + break; + } + RegCloseKey(hSubKey); + /* get the current adapter index from NetCfgInstanceId */ + if (!GetAdapterIndexFromNetCfgInstanceId(pAdapterInfo, szNetCfg, &dwAdapterIndex)) + break; + + /* get detailed adapter info */ + ZeroMemory(&IfEntry, sizeof(IfEntry)); + IfEntry.dwIndex = dwAdapterIndex; + if(GetIfEntry(&IfEntry) != NO_ERROR) + break; + + /* allocate new INetConnectionItem */ + pNew = CoTaskMemAlloc(sizeof(INetConnectionItem)); + if (!pNew) + break; + + ZeroMemory(pNew, sizeof(INetConnectionItem)); + + /* store NetCfgInstanceId */ + CLSIDFromString(szNetCfg, &pNew->Props.guidId); + switch(IfEntry.dwOperStatus) + { + case MIB_IF_OPER_STATUS_NON_OPERATIONAL: + pNew->Props.Status = NCS_HARDWARE_DISABLED; + break; + case MIB_IF_OPER_STATUS_UNREACHABLE: + pNew->Props.Status = NCS_DISCONNECTED; + break; + case MIB_IF_OPER_STATUS_DISCONNECTED: + pNew->Props.Status = NCS_MEDIA_DISCONNECTED; + break; + case MIB_IF_OPER_STATUS_CONNECTING: + pNew->Props.Status = NCS_CONNECTING; + break; + case MIB_IF_OPER_STATUS_CONNECTED: + pNew->Props.Status = NCS_CONNECTED; + break; + case MIB_IF_OPER_STATUS_OPERATIONAL: + pNew->Props.Status = NCS_CONNECTED; + break; + default: + break; + } + + switch(IfEntry.dwType) + { + case IF_TYPE_ETHERNET_CSMACD: + pNew->Props.MediaType = NCM_LAN; + break; + case IF_TYPE_IEEE80211: + pNew->Props.MediaType = NCM_SHAREDACCESSHOST_RAS; + break; + default: + break; + } + /* open network connections details */ + wcscpy(&szName[80], szNetCfg); + wcscpy(&szName[118], L"\Connection"); + + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS) + { + /* retrieve name of connection */ + dwSize = sizeof(szAdapterNetCfg); + if (RegQueryValueExW(hSubKey, L"Name", NULL, NULL, (LPBYTE)szAdapterNetCfg, &dwSize) == ERROR_SUCCESS) + { + pNew->Props.pszwName = CoTaskMemAlloc((wcslen(szAdapterNetCfg)+1) * sizeof(WCHAR)); + if (pNew->Props.pszwName) + wcscpy(pNew->Props.pszwName, szAdapterNetCfg); + } + dwSize = sizeof(dwShowIcon); + if (RegQueryValueExW(hSubKey, L"ShowIcon", NULL, NULL, (LPBYTE)&dwShowIcon, &dwSize) == ERROR_SUCCESS) + { + if (dwShowIcon) + pNew->Props.dwCharacter |= NCCF_SHOW_ICON; + } + RegCloseKey(hSubKey); + } + if (SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_DEVICEDESC, NULL, (PBYTE)szNetCfg, sizeof(szNetCfg)/sizeof(WCHAR), &dwSize)) + { + szNetCfg[(sizeof(szNetCfg)/sizeof(WCHAR))-1] = L'\0'; + pNew->Props.pszwDeviceName = CoTaskMemAlloc((wcslen(szNetCfg)+1) * sizeof(WCHAR)); + if (pNew->Props.pszwDeviceName) + wcscpy(pNew->Props.pszwDeviceName, szNetCfg); + } + + if (pCurrent) + pCurrent->Next = pNew; + else + This->pHead = pNew; + + pCurrent = pNew; + }while(TRUE); + + CoTaskMemFree(pIfTable); + CoTaskMemFree(pAdapterInfo); + SetupDiDestroyDeviceInfoList(hInfo); + + This->pCurrent = This->pHead; + return TRUE; +} + +HRESULT WINAPI INetConnectionManager_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv) +{ + INetConnectionManagerImpl *sf; + + if (!ppv) + return E_POINTER; + if (pUnkOuter) + return CLASS_E_NOAGGREGATION; + + sf = (INetConnectionManagerImpl *) CoTaskMemAlloc(sizeof (INetConnectionManagerImpl)); + if (!sf) + return E_OUTOFMEMORY; + + sf->ref = 1; + sf->lpVtbl = &vt_NetConnectionManager; + sf->lpVtblNetConnection = &vt_EnumNetConnection; + + + if (!SUCCEEDED (INetConnectionManager_QueryInterface ((INetConnectionManager*)sf, riid, ppv))) + { + INetConnectionManager_Release((INetConnectionManager*)sf); + return E_NOINTERFACE; + } + + INetConnectionManager_Release((INetConnectionManager*)sf); + EnumerateINetConnections(sf); + return S_OK; +} + +
Propchange: trunk/reactos/dll/win32/netshell/connectmanager.c ------------------------------------------------------------------------------ svn:eol-style = native
Modified: trunk/reactos/dll/win32/netshell/enumlist.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/enumlist... ============================================================================== --- trunk/reactos/dll/win32/netshell/enumlist.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/enumlist.c [iso-8859-1] Wed Aug 27 21:57:10 2008 @@ -129,7 +129,7 @@ SHFree(pDelete->pidl); SHFree(pDelete); } - HeapFree(GetProcessHeap(),0,This); + CoTaskMemFree(This); } return refCount; } @@ -242,13 +242,15 @@
IEnumIDList * IEnumIDList_Constructor(void) { - IEnumIDListImpl *lpeidl = HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl)); + IEnumIDListImpl *lpeidl = CoTaskMemAlloc(sizeof(IEnumIDListImpl));
if (lpeidl) { lpeidl->ref = 1; lpeidl->lpVtbl = &eidlvt; + lpeidl->mpCurrent = NULL; + lpeidl->mpLast = NULL; + lpeidl->mpFirst = NULL; }
return (IEnumIDList*)lpeidl; @@ -322,34 +324,24 @@ return FALSE; }
-LPITEMIDLIST ILCreateNetConnectItem(MIB_IFROW * pRow, LPWSTR szName, LPWSTR szAdapterName) -{ - PIDLDATA tmp; +LPITEMIDLIST ILCreateNetConnectItem(INetConnection * pItem) +{ LPITEMIDLIST pidl; - VALUEStruct * p; - int size = sizeof(struct tagVALUEStruct); - - tmp.type = 0x00; - tmp.u.value.dummy = 0xFF; - - tmp.u.value.dwOperStatus = pRow->dwOperStatus; - tmp.u.value.dwType = pRow->dwType; - tmp.u.value.dwNameLength = wcslen(szName) + 1; - - size += (tmp.u.value.dwNameLength + wcslen(szAdapterName)) * sizeof(WCHAR); - - pidl = (LPITEMIDLIST)SHAlloc(size + 4); + LPPIDLDATA pdata; + int size = sizeof(PIDLDATA); + + pidl = (LPITEMIDLIST)SHAlloc(size + 2 * sizeof(SHITEMID)); if (!pidl) return pidl; - - pidl->mkid.cb = size+2; - memcpy(pidl->mkid.abID, &tmp, 2+sizeof(struct tagVALUEStruct)); - - p = &((PIDLDATA*)pidl->mkid.abID)->u.value; - wcscpy(&p->szName[0], szName); - wcscpy(p->szName + tmp.u.value.dwNameLength, szAdapterName); - - *(WORD*)((char*)pidl+(size+2)) = 0; + ZeroMemory(pidl, size + 2 * sizeof(SHITEMID)); + + pidl->mkid.cb = size + sizeof(SHITEMID); + + pdata = _ILGetDataPointer(pidl); + pdata->type = 0x99; + pdata->u.value.dummy = 0xFF; + pdata->u.value.pItem = (PVOID)pItem; + return pidl; }
@@ -357,7 +349,7 @@ { LPPIDLDATA pdata = _ILGetDataPointer(pidl);
- if (pdata && pdata->type==0x00) + if (pdata && pdata->type==0x99) return (VALUEStruct*)&(pdata->u.value);
return NULL;
Modified: trunk/reactos/dll/win32/netshell/netshell.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/netshell... ============================================================================== --- trunk/reactos/dll/win32/netshell/netshell.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/netshell.c [iso-8859-1] Wed Aug 27 21:57:10 2008 @@ -11,6 +11,10 @@ { &CLSID_NetworkConnections, ISF_NetConnect_Constructor + }, + { + &CLSID_ConnectionManager, + INetConnectionManager_Constructor }, { NULL,
Modified: trunk/reactos/dll/win32/netshell/netshell.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/netshell... ============================================================================== --- trunk/reactos/dll/win32/netshell/netshell.rbuild [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/netshell.rbuild [iso-8859-1] Wed Aug 27 21:57:10 2008 @@ -23,5 +23,6 @@ <file>enumlist.c</file> <file>netshell.rc</file> <file>classfactory.c</file> + <file>connectmanager.c</file> <file>netshell.spec</file> </module>
Modified: trunk/reactos/dll/win32/netshell/precomp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/precomp.... ============================================================================== --- trunk/reactos/dll/win32/netshell/precomp.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/precomp.h [iso-8859-1] Wed Aug 27 21:57:10 2008 @@ -32,6 +32,7 @@ #include <shtypes.h> #include <setupapi.h> #include <devguid.h> +#include <netcon.h>
#include "wine/debug.h" #include "wine/unicode.h" @@ -53,10 +54,7 @@ typedef struct tagVALUEStruct { BYTE dummy; - DWORD dwType; - DWORD dwOperStatus; - DWORD dwNameLength; - WCHAR szName[1]; + INetConnection * pItem; }VALUEStruct;
/* globals */ @@ -71,7 +69,7 @@ /* enumlist.c */ IEnumIDList * IEnumIDList_Constructor(void); LPITEMIDLIST _ILCreateNetConnect(); -LPITEMIDLIST ILCreateNetConnectItem(MIB_IFROW * pRow, LPWSTR szName, LPWSTR szAdapterName); +LPITEMIDLIST ILCreateNetConnectItem(INetConnection * pItem); BOOL _ILIsNetConnect (LPCITEMIDLIST pidl); BOOL AddToEnumList(IEnumIDList * iface, LPITEMIDLIST pidl); VALUEStruct * _ILGetValueStruct(LPCITEMIDLIST pidl); @@ -79,4 +77,7 @@ /* classfactory.c */ IClassFactory * IClassFactory_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
+/* connectmanager.c */ +HRESULT WINAPI INetConnectionManager_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv); + #endif
Modified: trunk/reactos/dll/win32/netshell/shfldr_netconnect.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/shfldr_n... ============================================================================== --- trunk/reactos/dll/win32/netshell/shfldr_netconnect.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/shfldr_netconnect.c [iso-8859-1] Wed Aug 27 21:57:10 2008 @@ -117,7 +117,7 @@ if (!refCount) { SHFree (This->pidlRoot); - HeapFree (GetProcessHeap(), 0, This); + CoTaskMemFree(This); } return refCount; } @@ -145,140 +145,46 @@ */ static BOOL CreateNetConnectEnumList(IEnumIDList *list, DWORD dwFlags) { - DWORD dwSize, dwResult, dwIndex; - MIB_IFTABLE *pIfTable; - MIB_IFROW IfEntry; - IP_ADAPTER_INFO * pAdapterInfo, *pCurrentAdapter; - HDEVINFO hInfo; - SP_DEVINFO_DATA DevInfo; - HKEY hSubKey; - WCHAR szNetCfg[50]; - WCHAR szAdapterNetCfg[50]; + HRESULT hr; + INetConnectionManager * INetConMan; + IEnumNetConnection * IEnumCon; + INetConnection * INetCon; + ULONG Count; LPITEMIDLIST pidl; - WCHAR szDetail[200] = L"SYSTEM\CurrentControlSet\Control\Class\"; - WCHAR szName[130] = L"SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\"; - - /* get the IfTable */ - dwSize = 0; - if (GetIfTable(NULL, &dwSize, TRUE) != ERROR_INSUFFICIENT_BUFFER) + + /* get an instance to of IConnectionManager */ + hr = INetConnectionManager_Constructor(NULL, &IID_INetConnectionManager, (LPVOID*)&INetConMan); + if (FAILED(hr)) return FALSE;
- pIfTable = (PMIB_IFTABLE)HeapAlloc(GetProcessHeap(), 0, dwSize); - if (!pIfTable) + hr = INetConnectionManager_EnumConnections(INetConMan, NCME_DEFAULT, &IEnumCon); + if (FAILED(hr)) + { + INetConnectionManager_Release(INetConMan); return FALSE; - - dwResult = GetIfTable(pIfTable, &dwSize, TRUE); - if (dwResult != NO_ERROR) - { - HeapFree(GetProcessHeap(), 0, pIfTable); - return FALSE; - } - - dwSize = 0; - dwResult = GetAdaptersInfo(NULL, &dwSize); - if (dwResult!= ERROR_BUFFER_OVERFLOW) - { - HeapFree(GetProcessHeap(), 0, pIfTable); - return FALSE; - } - - pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, dwSize); - if (!pAdapterInfo) - { - HeapFree(GetProcessHeap(), 0, pIfTable); - return FALSE; - } - - if (GetAdaptersInfo(pAdapterInfo, &dwSize) != NO_ERROR) - { - HeapFree(GetProcessHeap(), 0, pIfTable); - HeapFree(GetProcessHeap(), 0, pAdapterInfo); - return FALSE; - } - - - hInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT ); - if (!hInfo) - { - HeapFree(GetProcessHeap(), 0, pIfTable); - HeapFree(GetProcessHeap(), 0, pAdapterInfo); - return FALSE; - } - - dwIndex = 0; + } + do { - ZeroMemory(&DevInfo, sizeof(SP_DEVINFO_DATA)); - DevInfo.cbSize = sizeof(DevInfo); - if (SetupDiEnumDeviceInfo(hInfo, dwIndex++, &DevInfo)) + hr = IEnumNetConnection_Next(IEnumCon, 1, &INetCon, &Count); + if (hr == S_OK) { - if (SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_DRIVER, NULL, (LPBYTE)&szDetail[39], sizeof(szDetail)/sizeof(WCHAR) - 40, &dwSize)) + pidl = ILCreateNetConnectItem(INetCon); + if (pidl) { - if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szDetail, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS) - { - dwSize = sizeof(szNetCfg); - dwResult = RegQueryValueExW(hSubKey, L"NetCfgInstanceId", NULL, NULL, (LPBYTE)szNetCfg, &dwSize); - if (dwResult == ERROR_SUCCESS) - { - pCurrentAdapter = pAdapterInfo; - while(pCurrentAdapter) - { - szAdapterNetCfg[0] = L'\0'; - if (MultiByteToWideChar(CP_ACP, 0, pCurrentAdapter->AdapterName, -1, szAdapterNetCfg, sizeof(szAdapterNetCfg)/sizeof(szAdapterNetCfg[0]))) - { - szAdapterNetCfg[(sizeof(szAdapterNetCfg)/sizeof(WCHAR))-1] = L'\0'; - } - if (!wcsicmp(szAdapterNetCfg, szNetCfg)) - { - ZeroMemory(&IfEntry, sizeof(IfEntry)); - IfEntry.dwIndex = pCurrentAdapter->Index; - dwResult = GetIfEntry(&IfEntry); - if (dwResult == NO_ERROR) - { - if (IfEntry.dwType == IF_TYPE_ETHERNET_CSMACD || IfEntry.dwType == IF_TYPE_IEEE80211) - { - wcscpy(&szName[80], szNetCfg); - wcscpy(&szName[118], L"\Connection"); - if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS) - { - dwSize = sizeof(szAdapterNetCfg); - if (RegQueryValueExW(hSubKey, L"Name", NULL, NULL, (LPBYTE)szAdapterNetCfg, &dwSize) != ERROR_SUCCESS) - { - if (!SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_FRIENDLYNAME, NULL, (PBYTE)szAdapterNetCfg, sizeof(szAdapterNetCfg)/sizeof(WCHAR), &dwSize)) - { - szDetail[0] = 0; - } - } - RegCloseKey(hSubKey); - } - szNetCfg[0] = 0; - SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_DEVICEDESC, NULL, (PBYTE)szNetCfg, sizeof(szNetCfg)/sizeof(WCHAR), &dwSize); - pidl = ILCreateNetConnectItem(&IfEntry, szAdapterNetCfg, szNetCfg); - if (pidl) - { - AddToEnumList(list, pidl); - } - } - } - break; - } - pCurrentAdapter = pCurrentAdapter->Next; - } - } - } + AddToEnumList(list, pidl); } - }else if (GetLastError() == ERROR_NO_MORE_ITEMS) + } + else { break; } }while(TRUE);
- HeapFree(GetProcessHeap(), 0, pAdapterInfo); - HeapFree(GetProcessHeap(), 0, pIfTable); - SetupDiDestroyDeviceInfoList(hInfo); - - return FALSE; - + IEnumNetConnection_Release(IEnumCon); + INetConnectionManager_Release(INetConMan); + + return TRUE; }
/************************************************************************** @@ -450,6 +356,8 @@ { LPWSTR pszName; HRESULT hr = E_FAIL; + NETCON_PROPERTIES * pProperties; + VALUEStruct * val; //IGenericSFImpl *This = (IGenericSFImpl *)iface;
if (!strRet) @@ -469,11 +377,18 @@ } else { - VALUEStruct * val = _ILGetValueStruct(pidl); + val = _ILGetValueStruct(pidl); if (val) { - wcscpy(pszName, val->szName); - hr = S_OK; + if (INetConnection_GetProperties((INetConnection*)val->pItem, &pProperties) == NOERROR) + { + if (pProperties->pszwName) + { + wcscpy(pszName, pProperties->pszwName); + hr = S_OK; + } + //NcFreeNetconProperties(pProperties); + } }
} @@ -567,6 +482,7 @@ WCHAR buffer[MAX_PATH] = {0}; HRESULT hr = E_FAIL; VALUEStruct * val; + NETCON_PROPERTIES * pProperties;
if (iColumn >= NETCONNECTSHELLVIEWCOLUMNS) return E_FAIL; @@ -592,10 +508,14 @@ if (!val) return E_FAIL;
+ if (INetConnection_GetProperties((INetConnection*)val->pItem, &pProperties) != NOERROR) + return E_FAIL; + + switch(iColumn) { case COLUMN_TYPE: - if (val->dwType == IF_TYPE_ETHERNET_CSMACD || val->dwType == IF_TYPE_IEEE80211) + if (pProperties->MediaType == NCM_LAN || pProperties->MediaType == NCM_SHAREDACCESSHOST_RAS) { if (LoadStringW(netshell_hInstance, IDS_TYPE_ETHERNET, buffer, MAX_PATH)) { @@ -606,18 +526,16 @@ break; case COLUMN_STATUS: buffer[0] = L'\0'; - if (val->dwOperStatus == MIB_IF_OPER_STATUS_NON_OPERATIONAL) + if (pProperties->Status == NCS_HARDWARE_DISABLED) LoadStringW(netshell_hInstance, IDS_STATUS_NON_OPERATIONAL, buffer, MAX_PATH); - else if (val->dwOperStatus == MIB_IF_OPER_STATUS_UNREACHABLE) + else if (pProperties->Status == NCS_DISCONNECTED) LoadStringW(netshell_hInstance, IDS_STATUS_UNREACHABLE, buffer, MAX_PATH); - else if (val->dwOperStatus == MIB_IF_OPER_STATUS_DISCONNECTED) + else if (pProperties->Status == NCS_MEDIA_DISCONNECTED) LoadStringW(netshell_hInstance, IDS_STATUS_DISCONNECTED, buffer, MAX_PATH); - else if (val->dwOperStatus == MIB_IF_OPER_STATUS_CONNECTING) + else if (pProperties->Status == NCS_CONNECTING) LoadStringW(netshell_hInstance, IDS_STATUS_CONNECTING, buffer, MAX_PATH); - else if (val->dwOperStatus == MIB_IF_OPER_STATUS_CONNECTED) + else if (pProperties->Status == NCS_CONNECTED) LoadStringW(netshell_hInstance, IDS_STATUS_CONNECTED, buffer, MAX_PATH); - else if (val->dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL) - LoadStringW(netshell_hInstance, IDS_STATUS_OPERATIONAL, buffer, MAX_PATH);
if (buffer[0]) { @@ -627,7 +545,7 @@ } break; case COLUMN_DEVNAME: - wcscpy(buffer, val->szName + val->dwNameLength); + wcscpy(buffer, pProperties->pszwDeviceName); buffer[MAX_PATH-1] = L'\0'; psd->str.uType = STRRET_WSTR; hr = SHStrDupW(buffer, &psd->str.u.pOleStr); @@ -638,7 +556,9 @@ psd->str.uType = STRRET_CSTR; break; } - +#if 0 + NcFreeNetconProperties(pProperties); +#endif return hr; }
@@ -885,7 +805,7 @@ if (pUnkOuter) return CLASS_E_NOAGGREGATION;
- sf = (IGenericSFImpl *) HeapAlloc ( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (IGenericSFImpl)); + sf = (IGenericSFImpl *) CoTaskMemAlloc(sizeof (IGenericSFImpl)); if (!sf) return E_OUTOFMEMORY;