2008-08-28 02:57:10 +00:00
|
|
|
#include <precomp.h>
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL (shell);
|
|
|
|
|
2008-08-28 02:57:10 +00:00
|
|
|
typedef struct tagINetConnectionItem
|
|
|
|
{
|
|
|
|
struct tagINetConnectionItem * Next;
|
2008-09-18 09:01:52 +00:00
|
|
|
DWORD dwAdapterIndex;
|
2008-08-28 02:57:10 +00:00
|
|
|
NETCON_PROPERTIES Props;
|
2012-01-20 21:50:54 +00:00
|
|
|
} INetConnectionItem, *PINetConnectionItem;
|
|
|
|
|
|
|
|
class CNetConnectionManager:
|
|
|
|
public INetConnectionManager,
|
|
|
|
public IEnumNetConnection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CNetConnectionManager();
|
|
|
|
BOOL EnumerateINetConnections();
|
|
|
|
|
|
|
|
// IUnknown
|
|
|
|
virtual HRESULT WINAPI QueryInterface(REFIID riid, LPVOID *ppvOut);
|
|
|
|
virtual ULONG WINAPI AddRef();
|
|
|
|
virtual ULONG WINAPI Release();
|
|
|
|
|
|
|
|
// INetConnectionManager
|
|
|
|
virtual HRESULT WINAPI EnumConnections(NETCONMGR_ENUM_FLAGS Flags, IEnumNetConnection **ppEnum);
|
|
|
|
|
|
|
|
// IEnumNetConnection
|
|
|
|
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);
|
|
|
|
|
|
|
|
private:
|
|
|
|
LONG ref;
|
|
|
|
PINetConnectionItem pHead;
|
|
|
|
PINetConnectionItem pCurrent;
|
|
|
|
};
|
2008-08-28 02:57:10 +00:00
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
class CNetConnection:
|
|
|
|
public INetConnection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CNetConnection(PINetConnectionItem pItem);
|
|
|
|
|
|
|
|
// IUnknown
|
|
|
|
virtual HRESULT WINAPI QueryInterface(REFIID riid, LPVOID *ppvOut);
|
|
|
|
virtual ULONG WINAPI AddRef();
|
|
|
|
virtual ULONG WINAPI Release();
|
|
|
|
|
|
|
|
// INetConnection
|
|
|
|
HRESULT WINAPI Connect();
|
|
|
|
HRESULT WINAPI Disconnect();
|
|
|
|
HRESULT WINAPI Delete();
|
|
|
|
HRESULT WINAPI Duplicate(LPCWSTR pszwDuplicateName, INetConnection **ppCon);
|
|
|
|
HRESULT WINAPI GetProperties(NETCON_PROPERTIES **ppProps);
|
|
|
|
HRESULT WINAPI GetUiObjectClassId(CLSID *pclsid);
|
|
|
|
HRESULT WINAPI Rename(LPCWSTR pszwDuplicateName);
|
|
|
|
|
|
|
|
private:
|
|
|
|
LONG ref;
|
|
|
|
NETCON_PROPERTIES Props;
|
|
|
|
DWORD dwAdapterIndex;
|
|
|
|
};
|
2008-08-28 02:57:10 +00:00
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
VOID NormalizeOperStatus(MIB_IFROW *IfEntry, NETCON_PROPERTIES * Props);
|
2008-08-28 02:57:10 +00:00
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager::CNetConnectionManager()
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
ref = 0;
|
|
|
|
pHead = NULL;
|
|
|
|
pCurrent = NULL;
|
2008-08-28 02:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager::QueryInterface(
|
2008-08-28 02:57:10 +00:00
|
|
|
REFIID iid,
|
2012-01-20 21:50:54 +00:00
|
|
|
LPVOID *ppvObj)
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
|
|
|
*ppvObj = NULL;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
if (IsEqualIID(iid, IID_IUnknown) ||
|
|
|
|
IsEqualIID(iid, IID_INetConnectionManager))
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
*ppvObj = (INetConnectionManager*)this;
|
|
|
|
AddRef();
|
2008-08-28 02:57:10 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager::AddRef()
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
ULONG refCount = InterlockedIncrement(&ref);
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager::Release()
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
ULONG refCount = InterlockedDecrement(&ref);
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
if (!refCount)
|
2012-01-20 21:50:54 +00:00
|
|
|
delete this;
|
|
|
|
|
2008-08-28 02:57:10 +00:00
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager::EnumConnections(
|
2008-08-28 02:57:10 +00:00
|
|
|
NETCONMGR_ENUM_FLAGS Flags,
|
|
|
|
IEnumNetConnection **ppEnum)
|
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
TRACE("EnumConnections\n");
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
if (!ppEnum)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (Flags != NCME_DEFAULT)
|
|
|
|
return E_FAIL;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
*ppEnum = (IEnumNetConnection*)this;
|
|
|
|
AddRef();
|
2008-08-28 02:57:10 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
* INetConnection Interface
|
|
|
|
*/
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::CNetConnection(PINetConnectionItem pItem)
|
|
|
|
{
|
|
|
|
ref = 0;
|
|
|
|
dwAdapterIndex = pItem->dwAdapterIndex;
|
|
|
|
CopyMemory(&Props, &pItem->Props, sizeof(NETCON_PROPERTIES));
|
|
|
|
|
|
|
|
if (pItem->Props.pszwName)
|
|
|
|
{
|
|
|
|
Props.pszwName = (LPWSTR)CoTaskMemAlloc((wcslen(pItem->Props.pszwName)+1)*sizeof(WCHAR));
|
|
|
|
if (Props.pszwName)
|
|
|
|
wcscpy(Props.pszwName, pItem->Props.pszwName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pItem->Props.pszwDeviceName)
|
|
|
|
{
|
|
|
|
Props.pszwDeviceName = (LPWSTR)CoTaskMemAlloc((wcslen(pItem->Props.pszwDeviceName)+1)*sizeof(WCHAR));
|
|
|
|
if (Props.pszwDeviceName)
|
|
|
|
wcscpy(Props.pszwDeviceName, pItem->Props.pszwDeviceName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-28 02:57:10 +00:00
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::QueryInterface(
|
2008-08-28 02:57:10 +00:00
|
|
|
REFIID iid,
|
|
|
|
LPVOID * ppvObj)
|
|
|
|
{
|
|
|
|
*ppvObj = NULL;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
if (IsEqualIID(iid, IID_IUnknown) ||
|
|
|
|
IsEqualIID(iid, IID_INetConnection))
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
*ppvObj = this;
|
|
|
|
AddRef();
|
2008-08-28 02:57:10 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::AddRef()
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
ULONG refCount = InterlockedIncrement(&ref);
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::Release()
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
ULONG refCount = InterlockedDecrement(&ref);
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
if (!refCount)
|
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
CoTaskMemFree(Props.pszwName);
|
|
|
|
CoTaskMemFree(Props.pszwDeviceName);
|
|
|
|
delete this;
|
2008-08-28 02:57:10 +00:00
|
|
|
}
|
2012-01-20 21:50:54 +00:00
|
|
|
|
2008-08-28 02:57:10 +00:00
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::Connect()
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::Disconnect()
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::Delete()
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::Duplicate(
|
2008-08-28 02:57:10 +00:00
|
|
|
LPCWSTR pszwDuplicateName,
|
|
|
|
INetConnection **ppCon)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::GetProperties(NETCON_PROPERTIES **ppProps)
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2008-09-18 09:01:52 +00:00
|
|
|
MIB_IFROW IfEntry;
|
2008-09-28 10:50:10 +00:00
|
|
|
HKEY hKey;
|
|
|
|
LPOLESTR pStr;
|
|
|
|
WCHAR szName[140];
|
|
|
|
DWORD dwShowIcon, dwType, dwSize;
|
2008-08-28 02:57:10 +00:00
|
|
|
NETCON_PROPERTIES * pProperties;
|
2008-09-28 10:50:10 +00:00
|
|
|
HRESULT hr;
|
2008-08-29 14:18:55 +00:00
|
|
|
|
2008-08-28 02:57:10 +00:00
|
|
|
if (!ppProps)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
pProperties = (NETCON_PROPERTIES*)CoTaskMemAlloc(sizeof(NETCON_PROPERTIES));
|
2008-08-28 02:57:10 +00:00
|
|
|
if (!pProperties)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
CopyMemory(pProperties, &Props, sizeof(NETCON_PROPERTIES));
|
2008-09-28 10:50:10 +00:00
|
|
|
pProperties->pszwName = NULL;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
if (Props.pszwDeviceName)
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
pProperties->pszwDeviceName = (LPWSTR)CoTaskMemAlloc((wcslen(Props.pszwDeviceName)+1)*sizeof(WCHAR));
|
2008-08-28 02:57:10 +00:00
|
|
|
if (pProperties->pszwDeviceName)
|
2012-01-20 21:50:54 +00:00
|
|
|
wcscpy(pProperties->pszwDeviceName, Props.pszwDeviceName);
|
2008-08-28 02:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*ppProps = pProperties;
|
2008-09-18 09:01:52 +00:00
|
|
|
|
|
|
|
/* get updated adapter characteristics */
|
|
|
|
ZeroMemory(&IfEntry, sizeof(IfEntry));
|
2012-01-20 21:50:54 +00:00
|
|
|
IfEntry.dwIndex = dwAdapterIndex;
|
2008-09-18 09:01:52 +00:00
|
|
|
if(GetIfEntry(&IfEntry) != NO_ERROR)
|
|
|
|
return NOERROR;
|
|
|
|
|
|
|
|
NormalizeOperStatus(&IfEntry, pProperties);
|
|
|
|
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
hr = StringFromCLSID((CLSID)Props.guidId, &pStr);
|
2008-09-28 10:50:10 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
wcscpy(szName, L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\");
|
|
|
|
wcscat(szName, pStr);
|
|
|
|
wcscat(szName, L"\\Connection");
|
|
|
|
|
|
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
dwSize = sizeof(dwShowIcon);
|
|
|
|
if (RegQueryValueExW(hKey, L"ShowIcon", NULL, &dwType, (LPBYTE)&dwShowIcon, &dwSize) == ERROR_SUCCESS && dwType == REG_DWORD)
|
|
|
|
{
|
|
|
|
if (dwShowIcon)
|
|
|
|
pProperties->dwCharacter |= NCCF_SHOW_ICON;
|
|
|
|
else
|
|
|
|
pProperties->dwCharacter &= ~NCCF_SHOW_ICON;
|
|
|
|
}
|
|
|
|
dwSize = sizeof(szName);
|
|
|
|
if (RegQueryValueExW(hKey, L"Name", NULL, &dwType, (LPBYTE)szName, &dwSize) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
/* use updated name */
|
|
|
|
dwSize = wcslen(szName) + 1;
|
2012-01-20 21:50:54 +00:00
|
|
|
pProperties->pszwName = (LPWSTR)CoTaskMemAlloc(dwSize * sizeof(WCHAR));
|
2008-09-28 10:50:10 +00:00
|
|
|
if (pProperties->pszwName)
|
|
|
|
CopyMemory(pProperties->pszwName, szName, dwSize * sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* use cached name */
|
2012-01-20 21:50:54 +00:00
|
|
|
if (Props.pszwName)
|
2008-09-28 10:50:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
pProperties->pszwName = (LPWSTR)CoTaskMemAlloc((wcslen(Props.pszwName)+1)*sizeof(WCHAR));
|
2008-09-28 10:50:10 +00:00
|
|
|
if (pProperties->pszwName)
|
2012-01-20 21:50:54 +00:00
|
|
|
wcscpy(pProperties->pszwName, Props.pszwName);
|
2008-09-28 10:50:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
CoTaskMemFree(pStr);
|
|
|
|
}
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
return S_OK;
|
2008-08-28 02:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::GetUiObjectClassId(CLSID *pclsid)
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
if (Props.MediaType == NCM_LAN)
|
2008-08-29 14:18:55 +00:00
|
|
|
{
|
|
|
|
CopyMemory(pclsid, &CLSID_LANConnectUI, sizeof(CLSID));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-28 02:57:10 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection::Rename(LPCWSTR pszwDuplicateName)
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
HRESULT WINAPI IConnection_Constructor(INetConnection **ppv, PINetConnectionItem pItem)
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
|
|
|
if (!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnection *pConnection = new CNetConnection(pItem);
|
|
|
|
if (!pConnection)
|
2008-08-28 02:57:10 +00:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
pConnection->AddRef();
|
|
|
|
*ppv = (INetConnection *)pConnection;
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
* IEnumNetConnection Interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager::Next(
|
2008-08-28 02:57:10 +00:00
|
|
|
ULONG celt,
|
|
|
|
INetConnection **rgelt,
|
|
|
|
ULONG *pceltFetched)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!pceltFetched || !rgelt)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (celt != 1)
|
|
|
|
return E_FAIL;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
if (!pCurrent)
|
2008-08-28 02:57:10 +00:00
|
|
|
return S_FALSE;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
hr = IConnection_Constructor(rgelt, pCurrent);
|
|
|
|
pCurrent = pCurrent->Next;
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager::Skip(ULONG celt)
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
while(pCurrent && celt-- > 0)
|
|
|
|
pCurrent = pCurrent->Next;
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
if (celt)
|
|
|
|
return S_FALSE;
|
|
|
|
else
|
2012-01-20 21:50:54 +00:00
|
|
|
return S_OK;
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager::Reset()
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
pCurrent = pHead;
|
|
|
|
return S_OK;
|
2008-08-28 02:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
WINAPI
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager::Clone(IEnumNetConnection **ppenum)
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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';
|
|
|
|
}
|
2008-12-23 01:23:25 +00:00
|
|
|
if (!_wcsicmp(szBuffer, szNetCfg))
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
|
|
|
*pIndex = pCurrentAdapter->Index;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
pCurrentAdapter = pCurrentAdapter->Next;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-18 09:01:52 +00:00
|
|
|
VOID
|
|
|
|
NormalizeOperStatus(
|
|
|
|
MIB_IFROW *IfEntry,
|
|
|
|
NETCON_PROPERTIES * Props)
|
|
|
|
{
|
|
|
|
switch(IfEntry->dwOperStatus)
|
|
|
|
{
|
|
|
|
case MIB_IF_OPER_STATUS_NON_OPERATIONAL:
|
|
|
|
Props->Status = NCS_HARDWARE_DISABLED;
|
|
|
|
break;
|
|
|
|
case MIB_IF_OPER_STATUS_UNREACHABLE:
|
|
|
|
Props->Status = NCS_DISCONNECTED;
|
|
|
|
break;
|
|
|
|
case MIB_IF_OPER_STATUS_DISCONNECTED:
|
|
|
|
Props->Status = NCS_MEDIA_DISCONNECTED;
|
|
|
|
break;
|
|
|
|
case MIB_IF_OPER_STATUS_CONNECTING:
|
|
|
|
Props->Status = NCS_CONNECTING;
|
|
|
|
break;
|
|
|
|
case MIB_IF_OPER_STATUS_CONNECTED:
|
|
|
|
Props->Status = NCS_CONNECTED;
|
|
|
|
break;
|
|
|
|
case MIB_IF_OPER_STATUS_OPERATIONAL:
|
|
|
|
Props->Status = NCS_CONNECTED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-28 02:57:10 +00:00
|
|
|
BOOL
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager::EnumerateINetConnections()
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
|
|
|
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 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);
|
2008-09-17 13:58:48 +00:00
|
|
|
|
2008-08-28 02:57:10 +00:00
|
|
|
/* get the current adapter index from NetCfgInstanceId */
|
|
|
|
if (!GetAdapterIndexFromNetCfgInstanceId(pAdapterInfo, szNetCfg, &dwAdapterIndex))
|
2008-09-17 13:58:48 +00:00
|
|
|
continue;
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
/* get detailed adapter info */
|
|
|
|
ZeroMemory(&IfEntry, sizeof(IfEntry));
|
|
|
|
IfEntry.dwIndex = dwAdapterIndex;
|
|
|
|
if(GetIfEntry(&IfEntry) != NO_ERROR)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* allocate new INetConnectionItem */
|
2012-01-20 21:50:54 +00:00
|
|
|
PINetConnectionItem pNew = (PINetConnectionItem)CoTaskMemAlloc(sizeof(INetConnectionItem));
|
2008-08-28 02:57:10 +00:00
|
|
|
if (!pNew)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ZeroMemory(pNew, sizeof(INetConnectionItem));
|
2008-09-18 09:01:52 +00:00
|
|
|
pNew->dwAdapterIndex = dwAdapterIndex;
|
2008-08-28 02:57:10 +00:00
|
|
|
/* store NetCfgInstanceId */
|
|
|
|
CLSIDFromString(szNetCfg, &pNew->Props.guidId);
|
2008-09-18 09:01:52 +00:00
|
|
|
NormalizeOperStatus(&IfEntry, &pNew->Props);
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
pNew->Props.pszwName = (LPWSTR)CoTaskMemAlloc((wcslen(szAdapterNetCfg)+1) * sizeof(WCHAR));
|
2008-08-28 02:57:10 +00:00
|
|
|
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';
|
2012-01-20 21:50:54 +00:00
|
|
|
pNew->Props.pszwDeviceName = (LPWSTR)CoTaskMemAlloc((wcslen(szNetCfg)+1) * sizeof(WCHAR));
|
2008-08-28 02:57:10 +00:00
|
|
|
if (pNew->Props.pszwDeviceName)
|
|
|
|
wcscpy(pNew->Props.pszwDeviceName, szNetCfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pCurrent)
|
|
|
|
pCurrent->Next = pNew;
|
|
|
|
else
|
2012-01-20 21:50:54 +00:00
|
|
|
pHead = pNew;
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
pCurrent = pNew;
|
|
|
|
}while(TRUE);
|
|
|
|
|
|
|
|
CoTaskMemFree(pIfTable);
|
|
|
|
CoTaskMemFree(pAdapterInfo);
|
|
|
|
SetupDiDestroyDeviceInfoList(hInfo);
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
this->pCurrent = pHead;
|
2008-08-28 02:57:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
HRESULT WINAPI INetConnectionManager_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID * ppv)
|
2008-08-28 02:57:10 +00:00
|
|
|
{
|
2012-01-20 21:50:54 +00:00
|
|
|
TRACE("INetConnectionManager_Constructor\n");
|
2008-08-28 02:57:10 +00:00
|
|
|
|
|
|
|
if (!ppv)
|
|
|
|
return E_POINTER;
|
|
|
|
if (pUnkOuter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
CNetConnectionManager *pConnectionMgr = new CNetConnectionManager;
|
|
|
|
if (!pConnectionMgr)
|
2008-08-28 02:57:10 +00:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
pConnectionMgr->AddRef();
|
|
|
|
HRESULT hr = pConnectionMgr->QueryInterface(riid, ppv);
|
2008-08-28 02:57:10 +00:00
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
pConnectionMgr->EnumerateINetConnections();
|
2008-08-28 02:57:10 +00:00
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
pConnectionMgr->Release();
|
2008-08-28 02:57:10 +00:00
|
|
|
|
2012-01-20 21:50:54 +00:00
|
|
|
return hr;
|
2008-08-28 02:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|