BOOL GetINetCfgComponent(INetCfg * pNCfg, INetConnectionPropertyUiImpl * This, INetCfgComponent ** pOut) { LPWSTR pName; HRESULT hr; INetCfgComponent * pNCg; ULONG Fetched; IEnumNetCfgComponent * pEnumCfg; hr = INetCfg_EnumComponents(pNCfg, &GUID_DEVCLASS_NET, &pEnumCfg); if (FAILED(hr)) { return FALSE; } while(IEnumNetCfgComponent_Next(pEnumCfg, 1, &pNCg, &Fetched) == S_OK) { hr = INetCfgComponent_GetDisplayName(pNCg, &pName); if (SUCCEEDED(hr)) { if (!_wcsicmp(pName, This->pProperties->pszwDeviceName)) { *pOut = pNCg; IEnumNetCfgComponent_Release(pEnumCfg); return TRUE; } CoTaskMemFree(pName); } INetCfgComponent_Release(pNCg); } IEnumNetCfgComponent_Release(pEnumCfg); return FALSE; }
static void create_configuration(void) { static const WCHAR tcpipW[] = {'M','S','_','T','C','P','I','P',0}; static const WCHAR myclient[] = {'M','Y',' ','C','L','I','E','N','T',0}; HRESULT hr; INetCfg *config = NULL; INetCfgLock *netlock = NULL; INetCfgComponent *component = NULL; LPWSTR client = NULL; hr = CoCreateInstance( &CLSID_CNetCfg, NULL, CLSCTX_ALL, &IID_INetCfg, (LPVOID*)&config); ok(hr == S_OK, "Failed to create object\n"); if(SUCCEEDED(hr)) { hr = INetCfg_QueryInterface(config, &IID_INetCfgLock, (LPVOID*)&netlock); ok(hr == S_OK, "got 0x%08x\n", hr); hr = INetCfgLock_AcquireWriteLock(netlock, 5000, myclient, &client); ok(hr == S_OK || hr == E_ACCESSDENIED /* Not run as admin */, "got 0x%08x\n", hr); if(hr == S_OK) { trace("Lock value: %s\n", wine_dbgstr_w(client)); CoTaskMemFree(client); } else if(hr == E_ACCESSDENIED) trace("Not run with Admin permissions\n"); hr = INetCfg_Initialize(config, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); /* AcquireWriteLock needs to be run before Initialize */ hr = INetCfgLock_AcquireWriteLock(netlock, 5000, myclient, &client); todo_wine ok(hr == NETCFG_E_ALREADY_INITIALIZED || hr == E_ACCESSDENIED, "got 0x%08x\n", hr); hr = INetCfg_FindComponent(config, tcpipW, &component); todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); if(hr == S_OK) { INetCfgComponent_Release(component); } hr = INetCfg_Apply(config); todo_wine ok(hr == S_OK || hr == NETCFG_E_NO_WRITE_LOCK, "got 0x%08x\n", hr); hr = INetCfg_Uninitialize(config); ok(hr == S_OK, "got 0x%08x\n", hr); hr = INetCfgLock_ReleaseWriteLock(netlock); ok(hr == S_OK, "got 0x%08x\n", hr); INetCfg_Release(config); } }
VOID EnumComponents(HWND hDlgCtrl, INetConnectionPropertyUiImpl * This, INetCfg * pNCfg, const GUID * CompGuid, UINT Type) { HRESULT hr; IEnumNetCfgComponent * pENetCfg; INetCfgComponent *pNCfgComp, *pAdapterCfgComp; INetCfgComponentBindings * pCompBind; ULONG Num; DWORD dwCharacteristics; LPOLESTR pDisplayName, pHelpText; PNET_ITEM pItem; BOOL bChecked; hr = INetCfg_EnumComponents(pNCfg, CompGuid, &pENetCfg); if (FAILED(hr)) { INetCfg_Release(pNCfg); return; } while(IEnumNetCfgComponent_Next(pENetCfg, 1, &pNCfgComp, &Num) == S_OK) { hr = INetCfgComponent_GetCharacteristics(pNCfgComp, &dwCharacteristics); if (SUCCEEDED(hr) && (dwCharacteristics & NCF_HIDDEN)) { INetCfgComponent_Release(pNCfgComp); continue; } pDisplayName = NULL; pHelpText = NULL; hr = INetCfgComponent_GetDisplayName(pNCfgComp, &pDisplayName); hr = INetCfgComponent_GetHelpText(pNCfgComp, &pHelpText); bChecked = TRUE; //Odyssey hack hr = INetCfgComponent_QueryInterface(pNCfgComp, &IID_INetCfgComponentBindings, (LPVOID*)&pCompBind); if (SUCCEEDED(hr)) { if (GetINetCfgComponent(pNCfg, This, &pAdapterCfgComp)) { hr = INetCfgComponentBindings_IsBoundTo(pCompBind, pAdapterCfgComp); if (hr == S_OK) bChecked = TRUE; else bChecked = FALSE; INetCfgComponent_Release(pAdapterCfgComp); INetCfgComponentBindings_Release(pCompBind); } } pItem = CoTaskMemAlloc(sizeof(NET_ITEM)); if (!pItem) continue; pItem->dwCharacteristics = dwCharacteristics; pItem->szHelp = pHelpText; pItem->Type = Type; pItem->pNCfgComp = pNCfgComp; pItem->NumPropDialogOpen = 0; AddItemToListView(hDlgCtrl, pItem, pDisplayName, bChecked); CoTaskMemFree(pDisplayName); } IEnumNetCfgComponent_Release(pENetCfg); }