Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygennetcfg_iface.c
Go to the documentation of this file.
00001 #include "precomp.h" 00002 00003 typedef struct 00004 { 00005 const INetCfg * lpVtbl; 00006 const INetCfgLock * lpVtblLock; 00007 LONG ref; 00008 BOOL bInitialized; 00009 HANDLE hMutex; 00010 NetCfgComponentItem *pNet; 00011 NetCfgComponentItem * pService; 00012 NetCfgComponentItem * pClient; 00013 NetCfgComponentItem * pProtocol; 00014 } INetCfgImpl, *LPINetCfgImpl; 00015 00016 static __inline LPINetCfgImpl impl_from_INetCfgLock(INetCfgLock *iface) 00017 { 00018 return (INetCfgImpl*)((char *)iface - FIELD_OFFSET(INetCfgImpl, lpVtblLock)); 00019 } 00020 00021 00022 00023 HRESULT 00024 WINAPI 00025 INetCfgLock_fnQueryInterface( 00026 INetCfgLock * iface, 00027 REFIID iid, 00028 LPVOID * ppvObj) 00029 { 00030 INetCfgImpl * This = impl_from_INetCfgLock(iface); 00031 return INetCfg_QueryInterface((INetCfg*)This, iid, ppvObj); 00032 } 00033 00034 00035 ULONG 00036 WINAPI 00037 INetCfgLock_fnAddRef( 00038 INetCfgLock * iface) 00039 { 00040 INetCfgImpl * This = impl_from_INetCfgLock(iface); 00041 00042 return INetCfg_AddRef((INetCfg*)This); 00043 } 00044 00045 ULONG 00046 WINAPI 00047 INetCfgLock_fnRelease( 00048 INetCfgLock * iface) 00049 { 00050 INetCfgImpl * This = impl_from_INetCfgLock(iface); 00051 return INetCfg_Release((INetCfg*)This); 00052 } 00053 00054 HRESULT 00055 WINAPI 00056 INetCfgLock_fnAcquireWriteLock( 00057 INetCfgLock * iface, 00058 DWORD cmsTimeout, 00059 LPCWSTR pszwClientDescription, 00060 LPWSTR *ppszwClientDescription) 00061 { 00062 DWORD dwResult; 00063 HKEY hKey; 00064 WCHAR szValue[100]; 00065 INetCfgImpl * This = impl_from_INetCfgLock(iface); 00066 00067 if (This->bInitialized) 00068 return NETCFG_E_ALREADY_INITIALIZED; 00069 00070 dwResult = WaitForSingleObject(This->hMutex, cmsTimeout); 00071 if (dwResult == WAIT_TIMEOUT) 00072 { 00073 if (ppszwClientDescription) 00074 { 00075 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Network\\NetCfgLockHolder", 0, KEY_READ, &hKey) == ERROR_SUCCESS) 00076 { 00077 dwResult = sizeof(szValue); 00078 if (RegQueryValueExW(hKey, NULL, NULL, NULL, (LPBYTE)szValue, &dwResult) == ERROR_SUCCESS) 00079 { 00080 szValue[(sizeof(szValue)/sizeof(WCHAR))-1] = L'\0'; 00081 *ppszwClientDescription = CoTaskMemAlloc((wcslen(szValue)+1) * sizeof(WCHAR)); 00082 if (*ppszwClientDescription) 00083 wcscpy(*ppszwClientDescription, szValue); 00084 } 00085 RegCloseKey(hKey); 00086 } 00087 } 00088 return S_FALSE; 00089 } 00090 else if (dwResult == WAIT_OBJECT_0) 00091 { 00092 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Network\\NetCfgLockHolder", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) 00093 { 00094 RegSetValueExW(hKey, NULL, 0, REG_SZ, (LPBYTE)pszwClientDescription, (wcslen(pszwClientDescription)+1) * sizeof(WCHAR)); 00095 RegCloseKey(hKey); 00096 } 00097 return S_OK; 00098 } 00099 00100 return E_FAIL; 00101 } 00102 00103 HRESULT 00104 WINAPI 00105 INetCfgLock_fnReleaseWriteLock( 00106 INetCfgLock * iface) 00107 { 00108 INetCfgImpl * This = impl_from_INetCfgLock(iface); 00109 00110 if (This->bInitialized) 00111 return NETCFG_E_ALREADY_INITIALIZED; 00112 00113 00114 if (ReleaseMutex(This->hMutex)) 00115 return S_OK; 00116 else 00117 return S_FALSE; 00118 } 00119 00120 HRESULT 00121 WINAPI 00122 INetCfgLock_fnIsWriteLocked( 00123 INetCfgLock * iface, 00124 LPWSTR *ppszwClientDescription) 00125 { 00126 HKEY hKey; 00127 WCHAR szValue[100]; 00128 DWORD dwSize, dwType; 00129 HRESULT hr; 00130 00131 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Network\\NetCfgLockHolder", 0, KEY_READ, &hKey) != ERROR_SUCCESS) 00132 return S_FALSE; 00133 00134 dwSize = sizeof(szValue); 00135 if (RegQueryValueExW(hKey, NULL, NULL, &dwType, (LPBYTE)szValue, &dwSize) == ERROR_SUCCESS && dwType == REG_SZ) 00136 { 00137 hr = S_OK; 00138 szValue[(sizeof(szValue)/sizeof(WCHAR))-1] = L'\0'; 00139 *ppszwClientDescription = CoTaskMemAlloc((wcslen(szValue)+1) * sizeof(WCHAR)); 00140 if (*ppszwClientDescription) 00141 wcscpy(*ppszwClientDescription, szValue); 00142 else 00143 hr = E_OUTOFMEMORY; 00144 } 00145 else 00146 { 00147 hr = E_FAIL; 00148 } 00149 RegCloseKey(hKey); 00150 return hr; 00151 } 00152 00153 static const INetCfgLockVtbl vt_NetCfgLock = 00154 { 00155 INetCfgLock_fnQueryInterface, 00156 INetCfgLock_fnAddRef, 00157 INetCfgLock_fnRelease, 00158 INetCfgLock_fnAcquireWriteLock, 00159 INetCfgLock_fnReleaseWriteLock, 00160 INetCfgLock_fnIsWriteLocked 00161 }; 00162 00163 /*************************************************************** 00164 * INetCfg 00165 */ 00166 00167 HRESULT 00168 EnumClientServiceProtocol(HKEY hKey, const GUID * pGuid, NetCfgComponentItem ** pHead) 00169 { 00170 DWORD dwIndex = 0; 00171 DWORD dwSize; 00172 DWORD dwType; 00173 WCHAR szName[100]; 00174 WCHAR szText[100]; 00175 HKEY hSubKey, hNDIKey; 00176 NetCfgComponentItem * pLast = NULL, *pCurrent; 00177 00178 *pHead = NULL; 00179 do 00180 { 00181 szText[0] = L'\0'; 00182 00183 dwSize = sizeof(szName)/sizeof(WCHAR); 00184 if (RegEnumKeyExW(hKey, dwIndex++, szName, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) 00185 { 00186 pCurrent = CoTaskMemAlloc(sizeof(NetCfgComponentItem)); 00187 if (!pCurrent) 00188 return E_OUTOFMEMORY; 00189 00190 ZeroMemory(pCurrent, sizeof(NetCfgComponentItem)); 00191 CopyMemory(&pCurrent->ClassGUID, pGuid, sizeof(GUID)); 00192 00193 if (FAILED(CLSIDFromString(szName, &pCurrent->InstanceId))) 00194 { 00196 //CoTaskMemFree(pCurrent); 00197 //return E_FAIL; 00198 } 00199 if (RegOpenKeyExW(hKey, szName, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS) 00200 { 00201 /* retrieve Characteristics */ 00202 dwSize = sizeof(DWORD); 00203 00204 RegQueryValueExW(hSubKey, L"Characteristics", NULL, &dwType, (LPBYTE)&pCurrent->dwCharacteristics, &dwSize); 00205 if (dwType != REG_DWORD) 00206 pCurrent->dwCharacteristics = 0; 00207 00208 /* retrieve ComponentId */ 00209 dwSize = sizeof(szText); 00210 if (RegQueryValueExW(hSubKey, L"ComponentId", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS) 00211 { 00212 if (dwType == REG_SZ) 00213 { 00214 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0'; 00215 pCurrent->szId = CoTaskMemAlloc((wcslen(szText)+1)* sizeof(WCHAR)); 00216 if (pCurrent->szId) 00217 wcscpy(pCurrent->szId, szText); 00218 } 00219 } 00220 00221 /* retrieve Description */ 00222 dwSize = sizeof(szText); 00223 if (RegQueryValueExW(hSubKey, L"Description", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS) 00224 { 00225 if (dwType == REG_SZ) 00226 { 00227 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0'; 00228 pCurrent->szDisplayName = CoTaskMemAlloc((wcslen(szText)+1)* sizeof(WCHAR)); 00229 if (pCurrent->szDisplayName) 00230 wcscpy(pCurrent->szDisplayName, szText); 00231 } 00232 } 00233 00234 if (RegOpenKeyExW(hKey, L"NDI", 0, KEY_READ, &hNDIKey) == ERROR_SUCCESS) 00235 { 00236 /* retrieve HelpText */ 00237 dwSize = sizeof(szText); 00238 if (RegQueryValueExW(hNDIKey, L"HelpText", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS) 00239 { 00240 if (dwType == REG_SZ) 00241 { 00242 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0'; 00243 pCurrent->szHelpText = CoTaskMemAlloc((wcslen(szText)+1)* sizeof(WCHAR)); 00244 if (pCurrent->szHelpText) 00245 wcscpy(pCurrent->szHelpText, szText); 00246 } 00247 } 00248 00249 /* retrieve Service */ 00250 dwSize = sizeof(szText); 00251 if (RegQueryValueExW(hNDIKey, L"Service", NULL, &dwType, (LPBYTE)szText, &dwSize) == ERROR_SUCCESS) 00252 { 00253 if (dwType == REG_SZ) 00254 { 00255 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0'; 00256 pCurrent->szBindName = CoTaskMemAlloc((wcslen(szText)+1)* sizeof(WCHAR)); 00257 if (pCurrent->szBindName) 00258 wcscpy(pCurrent->szBindName, szText); 00259 } 00260 } 00261 RegCloseKey(hNDIKey); 00262 } 00263 RegCloseKey(hSubKey); 00264 00265 if (!pLast) 00266 *pHead = pCurrent; 00267 else 00268 pLast->pNext = pCurrent; 00269 00270 pLast = pCurrent; 00271 } 00272 } 00273 else 00274 break; 00275 00276 }while(TRUE); 00277 return S_OK; 00278 } 00279 00280 00281 00282 HRESULT 00283 EnumerateNetworkComponent( 00284 const GUID *pGuid, NetCfgComponentItem ** pHead) 00285 { 00286 HKEY hKey; 00287 LPOLESTR pszGuid; 00288 HRESULT hr; 00289 WCHAR szName[150]; 00290 00291 hr = StringFromCLSID(pGuid, &pszGuid); 00292 if (SUCCEEDED(hr)) 00293 { 00294 swprintf(szName, L"SYSTEM\\CurrentControlSet\\Control\\Network\\%s", pszGuid); 00295 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) 00296 { 00297 hr = EnumClientServiceProtocol(hKey, pGuid, pHead); 00298 RegCloseKey(hKey); 00299 } 00300 CoTaskMemFree(pszGuid); 00301 } 00302 return hr; 00303 } 00304 00305 HRESULT 00306 EnumerateNetworkAdapter(NetCfgComponentItem ** pHead) 00307 { 00308 DWORD dwSize, dwIndex; 00309 HDEVINFO hInfo; 00310 SP_DEVINFO_DATA DevInfo; 00311 HKEY hKey; 00312 WCHAR szNetCfg[50]; 00313 WCHAR szAdapterNetCfg[50]; 00314 WCHAR szDetail[200] = L"SYSTEM\\CurrentControlSet\\Control\\Class\\"; 00315 WCHAR szName[130] = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\"; 00316 NetCfgComponentItem * pLast = NULL, *pCurrent; 00317 00318 hInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT ); 00319 if (!hInfo) 00320 { 00321 return E_FAIL; 00322 } 00323 00324 dwIndex = 0; 00325 do 00326 { 00327 ZeroMemory(&DevInfo, sizeof(SP_DEVINFO_DATA)); 00328 DevInfo.cbSize = sizeof(DevInfo); 00329 00330 /* get device info */ 00331 if (!SetupDiEnumDeviceInfo(hInfo, dwIndex++, &DevInfo)) 00332 break; 00333 00334 /* get device software registry path */ 00335 if (!SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_DRIVER, NULL, (LPBYTE)&szDetail[39], sizeof(szDetail)/sizeof(WCHAR) - 40, &dwSize)) 00336 break; 00337 00338 /* open device registry key */ 00339 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szDetail, 0, KEY_READ, &hKey) != ERROR_SUCCESS) 00340 break; 00341 00342 /* query NetCfgInstanceId for current device */ 00343 dwSize = sizeof(szNetCfg); 00344 if (RegQueryValueExW(hKey, L"NetCfgInstanceId", NULL, NULL, (LPBYTE)szNetCfg, &dwSize) != ERROR_SUCCESS) 00345 { 00346 RegCloseKey(hKey); 00347 break; 00348 } 00349 00350 /* allocate new INetConnectionItem */ 00351 pCurrent = CoTaskMemAlloc(sizeof(NetCfgComponentItem)); 00352 if (!pCurrent) 00353 break; 00354 00355 ZeroMemory(pCurrent, sizeof(NetCfgComponentItem)); 00356 CopyMemory(&pCurrent->ClassGUID, &GUID_DEVCLASS_NET, sizeof(GUID)); 00357 CLSIDFromString(szNetCfg, &pCurrent->InstanceId); //FIXME 00358 00359 /* set bind name */ 00360 pCurrent->szBindName = CoTaskMemAlloc((wcslen(szNetCfg)+1) *sizeof(WCHAR)); 00361 if (pCurrent->szBindName) 00362 wcscpy(pCurrent->szBindName, szNetCfg); 00363 00364 /* retrieve ComponentId */ 00365 dwSize = sizeof(szAdapterNetCfg); 00366 if (RegQueryValueExW(hKey, L"ComponentId", NULL, NULL, (LPBYTE)szAdapterNetCfg, &dwSize) == ERROR_SUCCESS) 00367 { 00368 pCurrent->szId = CoTaskMemAlloc((wcslen(szAdapterNetCfg)+1) * sizeof(WCHAR)); 00369 if (pCurrent->szId) 00370 wcscpy(pCurrent->szId, szAdapterNetCfg); 00371 } 00372 /* set INetCfgComponent::GetDisplayName */ 00373 dwSize = sizeof(szAdapterNetCfg); 00374 if (RegQueryValueExW(hKey, L"DriverDesc", NULL, NULL, (LPBYTE)szAdapterNetCfg, &dwSize) == ERROR_SUCCESS) 00375 { 00376 pCurrent->szDisplayName = CoTaskMemAlloc((wcslen(szAdapterNetCfg)+1) * sizeof(WCHAR)); 00377 if (pCurrent->szDisplayName) 00378 wcscpy(pCurrent->szDisplayName, szAdapterNetCfg); 00379 } 00380 00381 RegCloseKey(hKey); 00382 /* open network connections details */ 00383 wcscpy(&szName[80], szNetCfg); 00384 wcscpy(&szName[118], L"\\Connection"); 00385 00386 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) 00387 { 00388 /* retrieve pnp instance id */ 00389 dwSize = sizeof(szAdapterNetCfg); 00390 if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, NULL, (LPBYTE)szAdapterNetCfg, &dwSize) == ERROR_SUCCESS) 00391 { 00392 pCurrent->szNodeId = CoTaskMemAlloc((wcslen(szAdapterNetCfg)+1) * sizeof(WCHAR)); 00393 if (pCurrent->szNodeId) 00394 wcscpy(pCurrent->szNodeId, szAdapterNetCfg); 00395 } 00396 RegCloseKey(hKey); 00397 } 00398 00399 if (SetupDiGetDeviceRegistryPropertyW(hInfo, &DevInfo, SPDRP_DEVICEDESC, NULL, (PBYTE)szNetCfg, sizeof(szNetCfg)/sizeof(WCHAR), &dwSize)) 00400 { 00401 szNetCfg[(sizeof(szNetCfg)/sizeof(WCHAR))-1] = L'\0'; 00402 pCurrent->szDisplayName = CoTaskMemAlloc((wcslen(szNetCfg)+1) * sizeof(WCHAR)); 00403 if (pCurrent->szDisplayName) 00404 wcscpy(pCurrent->szDisplayName, szNetCfg); 00405 } 00406 00407 if (pLast) 00408 pLast->pNext = pCurrent; 00409 else 00410 *pHead = pCurrent; 00411 00412 pLast = pCurrent; 00413 00414 }while(TRUE); 00415 00416 SetupDiDestroyDeviceInfoList(hInfo); 00417 return NOERROR; 00418 } 00419 00420 00421 HRESULT 00422 FindNetworkComponent( 00423 NetCfgComponentItem * pHead, 00424 LPCWSTR pszwComponentId, 00425 INetCfgComponent **pComponent, 00426 INetCfg * iface) 00427 { 00428 while(pHead) 00429 { 00430 if (!_wcsicmp(pHead->szId, pszwComponentId)) 00431 { 00432 return INetCfgComponent_Constructor(NULL, &IID_INetCfgComponent, (LPVOID*)pComponent, pHead, iface); 00433 } 00434 pHead = pHead->pNext; 00435 } 00436 return S_FALSE; 00437 } 00438 00439 00440 00441 HRESULT 00442 WINAPI 00443 INetCfg_fnQueryInterface( 00444 INetCfg * iface, 00445 REFIID iid, 00446 LPVOID * ppvObj) 00447 { 00448 INetCfgImpl * This = (INetCfgImpl*)iface; 00449 *ppvObj = NULL; 00450 00451 if (IsEqualIID (iid, &IID_IUnknown) || 00452 IsEqualIID (iid, &IID_INetCfg)) 00453 { 00454 *ppvObj = This; 00455 INetCfg_AddRef(iface); 00456 return S_OK; 00457 } 00458 else if (IsEqualIID (iid, &IID_INetCfgLock)) 00459 { 00460 if (This->bInitialized) 00461 return NETCFG_E_ALREADY_INITIALIZED; 00462 00463 *ppvObj = (LPVOID)&This->lpVtblLock; 00464 This->hMutex = CreateMutexW(NULL, FALSE, L"NetCfgLock"); 00465 00466 INetCfgLock_AddRef(iface); 00467 return S_OK; 00468 } 00469 00470 return E_NOINTERFACE; 00471 } 00472 00473 ULONG 00474 WINAPI 00475 INetCfg_fnAddRef( 00476 INetCfg * iface) 00477 { 00478 INetCfgImpl * This = (INetCfgImpl*)iface; 00479 ULONG refCount = InterlockedIncrement(&This->ref); 00480 00481 return refCount; 00482 } 00483 00484 ULONG 00485 WINAPI 00486 INetCfg_fnRelease( 00487 INetCfg * iface) 00488 { 00489 INetCfgImpl * This = (INetCfgImpl*)iface; 00490 ULONG refCount = InterlockedDecrement(&This->ref); 00491 00492 if (!refCount) 00493 { 00494 CoTaskMemFree (This); 00495 } 00496 return refCount; 00497 } 00498 00499 HRESULT 00500 WINAPI 00501 INetCfg_fnInitialize( 00502 INetCfg * iface, 00503 PVOID pReserved) 00504 { 00505 HRESULT hr; 00506 INetCfgImpl *This = (INetCfgImpl *)iface; 00507 00508 if (This->bInitialized) 00509 return NETCFG_E_ALREADY_INITIALIZED; 00510 00511 hr = EnumerateNetworkAdapter(&This->pNet); 00512 if (FAILED(hr)) 00513 return hr; 00514 00515 00516 hr = EnumerateNetworkComponent(&GUID_DEVCLASS_NETCLIENT, &This->pClient); 00517 if (FAILED(hr)) 00518 return hr; 00519 00520 hr = EnumerateNetworkComponent(&GUID_DEVCLASS_NETSERVICE, &This->pService); 00521 if (FAILED(hr)) 00522 return hr; 00523 00524 00525 hr = EnumerateNetworkComponent(&GUID_DEVCLASS_NETTRANS, &This->pProtocol); 00526 if (FAILED(hr)) 00527 return hr; 00528 00529 This->bInitialized = TRUE; 00530 return S_OK; 00531 } 00532 00533 VOID 00534 ApplyOrCancelChanges( 00535 NetCfgComponentItem *pHead, 00536 const CLSID * lpClassGUID, 00537 BOOL bApply) 00538 { 00539 HKEY hKey; 00540 WCHAR szName[200]; 00541 LPOLESTR pszGuid; 00542 00543 while(pHead) 00544 { 00545 if (pHead->bChanged) 00546 { 00547 if (IsEqualGUID(lpClassGUID, &GUID_DEVCLASS_NET)) 00548 { 00549 if (bApply) 00550 { 00551 if (StringFromCLSID(&pHead->InstanceId, &pszGuid) == NOERROR) 00552 { 00553 swprintf(szName, L"SYSTEM\\CurrentControlSet\\Control\\Network\\%s", pszGuid); 00554 CoTaskMemFree(pszGuid); 00555 00556 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) 00557 { 00558 RegSetValueExW(hKey, NULL, 0, REG_SZ, (LPBYTE)pHead->szDisplayName, (wcslen(pHead->szDisplayName)+1) * sizeof(WCHAR)); 00559 RegCloseKey(hKey); 00560 } 00561 } 00562 } 00563 } 00564 else if (pHead->pNCCC) 00565 { 00566 if (bApply) 00567 { 00568 INetCfgComponentControl_ApplyRegistryChanges(pHead->pNCCC); 00569 //FIXME 00570 // implement INetCfgPnpReconfigCallback and pass it to 00571 //INetCfgComponentControl_ApplyPnpChanges(pHead->pNCCC, NULL); 00572 } 00573 else 00574 { 00575 INetCfgComponentControl_CancelChanges(pHead->pNCCC); 00576 } 00577 } 00578 } 00579 pHead = pHead->pNext; 00580 } 00581 } 00582 00583 HRESULT 00584 WINAPI 00585 INetCfg_fnUninitialize( 00586 INetCfg * iface) 00587 { 00588 INetCfgImpl *This = (INetCfgImpl *)iface; 00589 00590 if (!This->bInitialized) 00591 return NETCFG_E_NOT_INITIALIZED; 00592 00593 return E_FAIL; 00594 } 00595 00596 00597 HRESULT 00598 WINAPI 00599 INetCfg_fnApply( 00600 INetCfg * iface) 00601 { 00602 INetCfgImpl *This = (INetCfgImpl *)iface; 00603 00604 if (!This->bInitialized) 00605 return NETCFG_E_NOT_INITIALIZED; 00606 00607 ApplyOrCancelChanges(This->pNet, &GUID_DEVCLASS_NET, TRUE); 00608 ApplyOrCancelChanges(This->pClient, &GUID_DEVCLASS_NETCLIENT, TRUE); 00609 ApplyOrCancelChanges(This->pService, &GUID_DEVCLASS_NETSERVICE, TRUE); 00610 ApplyOrCancelChanges(This->pProtocol, &GUID_DEVCLASS_NETTRANS, TRUE); 00611 00612 return S_OK; 00613 } 00614 00615 HRESULT 00616 WINAPI 00617 INetCfg_fnCancel( 00618 INetCfg * iface) 00619 { 00620 INetCfgImpl *This = (INetCfgImpl *)iface; 00621 00622 if (!This->bInitialized) 00623 return NETCFG_E_NOT_INITIALIZED; 00624 00625 ApplyOrCancelChanges(This->pClient, &GUID_DEVCLASS_NETCLIENT, FALSE); 00626 ApplyOrCancelChanges(This->pService, &GUID_DEVCLASS_NETSERVICE, FALSE); 00627 ApplyOrCancelChanges(This->pProtocol, &GUID_DEVCLASS_NETTRANS, FALSE); 00628 00629 return S_OK; 00630 } 00631 00632 HRESULT 00633 WINAPI 00634 INetCfg_fnEnumComponents( 00635 INetCfg * iface, 00636 const GUID *pguidClass, 00637 IEnumNetCfgComponent **ppenumComponent) 00638 { 00639 INetCfgImpl *This = (INetCfgImpl *)iface; 00640 00641 if (!This->bInitialized) 00642 return NETCFG_E_NOT_INITIALIZED; 00643 00644 if (IsEqualGUID(&GUID_DEVCLASS_NET, pguidClass)) 00645 return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pNet, iface); 00646 else if (IsEqualGUID(&GUID_DEVCLASS_NETCLIENT, pguidClass)) 00647 return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pClient, iface); 00648 else if (IsEqualGUID(&GUID_DEVCLASS_NETSERVICE, pguidClass)) 00649 return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pService, iface); 00650 else if (IsEqualGUID(&GUID_DEVCLASS_NETTRANS, pguidClass)) 00651 return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pProtocol, iface); 00652 else 00653 return E_NOINTERFACE; 00654 } 00655 00656 00657 HRESULT 00658 WINAPI 00659 INetCfg_fnFindComponent( 00660 INetCfg * iface, 00661 LPCWSTR pszwComponentId, 00662 INetCfgComponent **pComponent) 00663 { 00664 HRESULT hr; 00665 INetCfgImpl *This = (INetCfgImpl *)iface; 00666 00667 if (!This->bInitialized) 00668 return NETCFG_E_NOT_INITIALIZED; 00669 00670 hr = FindNetworkComponent(This->pClient, pszwComponentId, pComponent, iface); 00671 if (hr == S_OK) 00672 return hr; 00673 00674 hr = FindNetworkComponent(This->pService, pszwComponentId, pComponent, iface); 00675 if (hr == S_OK) 00676 return hr; 00677 00678 hr = FindNetworkComponent(This->pProtocol, pszwComponentId, pComponent, iface); 00679 if (hr == S_OK) 00680 return hr; 00681 00682 return S_FALSE; 00683 } 00684 00685 HRESULT 00686 WINAPI 00687 INetCfg_fnQueryNetCfgClass( 00688 INetCfg * iface, 00689 const GUID *pguidClass, 00690 REFIID riid, 00691 void **ppvObject) 00692 { 00693 return E_FAIL; 00694 } 00695 00696 static const INetCfgVtbl vt_NetCfg = 00697 { 00698 INetCfg_fnQueryInterface, 00699 INetCfg_fnAddRef, 00700 INetCfg_fnRelease, 00701 INetCfg_fnInitialize, 00702 INetCfg_fnUninitialize, 00703 INetCfg_fnApply, 00704 INetCfg_fnCancel, 00705 INetCfg_fnEnumComponents, 00706 INetCfg_fnFindComponent, 00707 INetCfg_fnQueryNetCfgClass, 00708 }; 00709 00710 HRESULT WINAPI INetCfg_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv) 00711 { 00712 INetCfgImpl *This; 00713 00714 if (!ppv) 00715 return E_POINTER; 00716 00717 This = (INetCfgImpl *) CoTaskMemAlloc(sizeof (INetCfgImpl)); 00718 if (!This) 00719 return E_OUTOFMEMORY; 00720 00721 This->ref = 1; 00722 This->lpVtbl = (const INetCfg*)&vt_NetCfg; 00723 This->lpVtblLock = (const INetCfgLock*)&vt_NetCfgLock; 00724 This->hMutex = NULL; 00725 This->bInitialized = FALSE; 00726 This->pNet = NULL; 00727 This->pClient = NULL; 00728 This->pService = NULL; 00729 This->pProtocol = NULL; 00730 00731 if (!SUCCEEDED (INetCfg_QueryInterface ((INetCfg*)This, riid, ppv))) 00732 { 00733 INetCfg_Release((INetCfg*)This); 00734 return E_NOINTERFACE; 00735 } 00736 00737 INetCfg_Release((INetCfg*)This); 00738 return S_OK; 00739 } Generated on Sun May 27 2012 04:25:28 for ReactOS by
1.7.6.1
|