HRESULT HrGetComponentEnum (INetCfg* pnc, IN const GUID* pguidClass, OUT IEnumNetCfgComponent **ppencc) { INetCfgClass *pncclass; HRESULT hr; *ppencc = NULL; // // Get the class reference. // hr = pnc->QueryNetCfgClass( pguidClass, IID_INetCfgClass, (PVOID *)&pncclass ); if ( hr == S_OK ) { // // Get the enumerator reference. // hr = pncclass->EnumComponents( ppencc ); // // We don't need the class reference any more. // ReleaseRef( pncclass ); } return hr; }
//+--------------------------------------------------------------------------- // // Function: HrShowNetComponents // // Purpose: Display the list of installed components of the // specified class. // // Arguments: // pnc [in] pointer to INetCfg object // pguidClass [in] pointer to class GUID // // Returns: S_OK on success, otherwise an error code // // Notes: // HRESULT HrShowNetComponents(IN INetCfg* pnc, IN const GUID* pguidClass) { HRESULT hr=S_OK; PWSTR szInfId; PWSTR szDisplayName; DWORD dwcc; INetCfgComponent* pncc; INetCfgClass* pncclass; IEnumNetCfgComponent* pencc; ULONG celtFetched; hr = pnc->QueryNetCfgClass(pguidClass, IID_INetCfgClass, (void**)&pncclass); if (SUCCEEDED(hr)) { // get IEnumNetCfgComponent so that we can enumerate hr = pncclass->EnumComponents(&pencc); ReleaseObj(pncclass); while (SUCCEEDED(hr) && (S_OK == (hr = pencc->Next(1, &pncc, &celtFetched)))) { if (pguidClass == &GUID_DEVCLASS_NET) { // we are interested only in physical netcards // hr = pncc->GetCharacteristics(&dwcc); if (FAILED(hr) || !(dwcc & NCF_PHYSICAL)) { hr = S_OK; ReleaseObj(pncc); continue; } } hr = pncc->GetId(&szInfId); if (S_OK == hr) { hr = pncc->GetDisplayName(&szDisplayName); if (SUCCEEDED(hr)) { LogPrintf(_T("%-26s %s\n"), szInfId, szDisplayName); CoTaskMemFree(szDisplayName); } CoTaskMemFree(szInfId); } // we dont want to stop enumeration just because 1 component // failed either GetId or GetDisplayName, therefore reset hr to S_OK hr = S_OK; ReleaseObj(pncc); } ReleaseObj(pencc); } if (S_FALSE == hr) { hr = S_OK; } return hr; }