Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygeninetcfgcomp_iface.c
Go to the documentation of this file.
00001 #include "precomp.h" 00002 00003 typedef struct 00004 { 00005 const INetCfgComponent * lpVtbl; 00006 LONG ref; 00007 NetCfgComponentItem * pItem; 00008 INetCfgComponentPropertyUi * pProperty; 00009 INetCfg * pNCfg; 00010 }INetCfgComponentImpl; 00011 00012 typedef struct 00013 { 00014 const IEnumNetCfgComponent * lpVtbl; 00015 LONG ref; 00016 NetCfgComponentItem * pCurrent; 00017 NetCfgComponentItem * pHead; 00018 INetCfg * pNCfg; 00019 }IEnumNetCfgComponentImpl; 00020 00021 HRESULT 00022 WINAPI 00023 INetCfgComponent_fnQueryInterface( 00024 INetCfgComponent * iface, 00025 REFIID iid, 00026 LPVOID * ppvObj) 00027 { 00028 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00029 *ppvObj = NULL; 00030 00031 if (IsEqualIID (iid, &IID_IUnknown) || 00032 IsEqualIID (iid, &IID_INetCfgComponent)) 00033 { 00034 *ppvObj = This; 00035 INetCfg_AddRef(iface); 00036 return S_OK; 00037 } 00038 00039 return E_NOINTERFACE; 00040 } 00041 00042 ULONG 00043 WINAPI 00044 INetCfgComponent_fnAddRef( 00045 INetCfgComponent * iface) 00046 { 00047 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00048 ULONG refCount = InterlockedIncrement(&This->ref); 00049 00050 return refCount; 00051 } 00052 00053 ULONG 00054 WINAPI 00055 INetCfgComponent_fnRelease( 00056 INetCfgComponent * iface) 00057 { 00058 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00059 ULONG refCount = InterlockedDecrement(&This->ref); 00060 00061 if (!refCount) 00062 { 00063 CoTaskMemFree(This); 00064 } 00065 return refCount; 00066 } 00067 00068 HRESULT 00069 WINAPI 00070 INetCfgComponent_fnGetDisplayName( 00071 INetCfgComponent * iface, 00072 LPWSTR * ppszwDisplayName) 00073 { 00074 LPWSTR szName; 00075 UINT Length; 00076 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00077 00078 if (This == NULL || ppszwDisplayName == NULL) 00079 return E_POINTER; 00080 00081 if (This->pItem->szDisplayName) 00082 Length = wcslen(This->pItem->szDisplayName)+1; 00083 else 00084 Length = 1; 00085 00086 szName = CoTaskMemAlloc(Length * sizeof(WCHAR)); 00087 if (!szName) 00088 return E_OUTOFMEMORY; 00089 00090 if (Length > 1) 00091 wcscpy(szName, This->pItem->szDisplayName); 00092 else 00093 szName[0] = L'\0'; 00094 00095 *ppszwDisplayName = szName; 00096 00097 return S_OK; 00098 } 00099 00100 HRESULT 00101 WINAPI 00102 INetCfgComponent_fnSetDisplayName( 00103 INetCfgComponent * iface, 00104 LPCWSTR ppszwDisplayName) 00105 { 00106 LPWSTR szName; 00107 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00108 00109 if (This == NULL || ppszwDisplayName == NULL) 00110 return E_POINTER; 00111 00112 /* setting name is only supported for network cards */ 00113 if (!IsEqualGUID(&This->pItem->ClassGUID, &GUID_DEVCLASS_NET)) 00114 return E_NOTIMPL; 00115 00119 00120 szName = CoTaskMemAlloc((wcslen(ppszwDisplayName)+1) * sizeof(WCHAR)); 00121 if (!szName) 00122 return E_OUTOFMEMORY; 00123 00124 wcscpy(szName, ppszwDisplayName); 00125 CoTaskMemFree(This->pItem->szDisplayName); 00126 This->pItem->szDisplayName = szName; 00127 This->pItem->bChanged = TRUE; 00128 00129 return S_OK; 00130 } 00131 00132 HRESULT 00133 WINAPI 00134 INetCfgComponent_fnGetHelpText( 00135 INetCfgComponent * iface, 00136 LPWSTR * ppszwHelpText) 00137 { 00138 LPWSTR szHelp; 00139 UINT Length; 00140 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00141 00142 if (This == NULL || ppszwHelpText == NULL) 00143 return E_POINTER; 00144 00145 if (This->pItem->szHelpText) 00146 Length = wcslen(This->pItem->szHelpText)+1; 00147 else 00148 Length = 1; 00149 00150 szHelp = CoTaskMemAlloc(Length * sizeof(WCHAR)); 00151 if (!szHelp) 00152 return E_OUTOFMEMORY; 00153 00154 if (Length > 1) 00155 wcscpy(szHelp, This->pItem->szHelpText); 00156 else 00157 szHelp[0] = L'\0'; 00158 00159 *ppszwHelpText = szHelp; 00160 00161 return S_OK; 00162 } 00163 00164 HRESULT 00165 WINAPI 00166 INetCfgComponent_fnGetId( 00167 INetCfgComponent * iface, 00168 LPWSTR * ppszwId) 00169 { 00170 LPWSTR szId; 00171 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00172 00173 if (This == NULL || ppszwId == NULL) 00174 return E_POINTER; 00175 00176 szId = CoTaskMemAlloc((wcslen(This->pItem->szId)+1) * sizeof(WCHAR)); 00177 if (!szId) 00178 return E_OUTOFMEMORY; 00179 00180 wcscpy(szId, This->pItem->szId); 00181 *ppszwId = szId; 00182 00183 return S_OK; 00184 } 00185 00186 HRESULT 00187 WINAPI 00188 INetCfgComponent_fnGetCharacteristics( 00189 INetCfgComponent * iface, 00190 DWORD * pdwCharacteristics) 00191 { 00192 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00193 00194 if (This == NULL || pdwCharacteristics == NULL) 00195 return E_POINTER; 00196 00197 *pdwCharacteristics = This->pItem->dwCharacteristics; 00198 00199 return S_OK; 00200 } 00201 00202 HRESULT 00203 WINAPI 00204 INetCfgComponent_fnGetInstanceGuid( 00205 INetCfgComponent * iface, 00206 GUID * pGuid) 00207 { 00208 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00209 00210 if (This == NULL || pGuid == NULL) 00211 return E_POINTER; 00212 00213 CopyMemory(pGuid, &This->pItem->InstanceId, sizeof(GUID)); 00214 return S_OK; 00215 } 00216 00217 HRESULT 00218 WINAPI 00219 INetCfgComponent_fnGetPnpDevNodeId( 00220 INetCfgComponent * iface, 00221 LPWSTR * ppszwDevNodeId) 00222 { 00223 LPWSTR szNode; 00224 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00225 00226 if (This == NULL || ppszwDevNodeId == NULL) 00227 return E_POINTER; 00228 00229 if (!IsEqualGUID(&GUID_DEVCLASS_NET, &This->pItem->ClassGUID)) 00230 return E_NOTIMPL; 00231 00232 szNode = CoTaskMemAlloc((wcslen(This->pItem->szNodeId)+1) * sizeof(WCHAR)); 00233 if (!szNode) 00234 return E_OUTOFMEMORY; 00235 00236 wcscpy(szNode, This->pItem->szNodeId); 00237 *ppszwDevNodeId = szNode; 00238 return S_OK; 00239 } 00240 00241 HRESULT 00242 WINAPI 00243 INetCfgComponent_fnGetClassGuid( 00244 INetCfgComponent * iface, 00245 GUID * pGuid) 00246 { 00247 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00248 00249 if (This == NULL || pGuid == NULL) 00250 return E_POINTER; 00251 00252 CopyMemory(pGuid, &This->pItem->ClassGUID, sizeof(GUID)); 00253 return S_OK; 00254 } 00255 00256 HRESULT 00257 WINAPI 00258 INetCfgComponent_fnGetBindName( 00259 INetCfgComponent * iface, 00260 LPWSTR * ppszwBindName) 00261 { 00262 LPWSTR szBind; 00263 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00264 00265 if (This == NULL || ppszwBindName == NULL) 00266 return E_POINTER; 00267 00268 szBind = CoTaskMemAlloc((wcslen(This->pItem->szBindName)+1) * sizeof(WCHAR)); 00269 if (!szBind) 00270 return E_OUTOFMEMORY; 00271 00272 wcscpy(szBind, This->pItem->szBindName); 00273 *ppszwBindName = szBind; 00274 00275 return S_OK; 00276 } 00277 00278 HRESULT 00279 WINAPI 00280 INetCfgComponent_fnGetDeviceStatus( 00281 INetCfgComponent * iface, 00282 ULONG * pStatus) 00283 { 00284 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00285 00286 if (This == NULL || pStatus == NULL) 00287 return E_POINTER; 00288 00289 if (!IsEqualGUID(&GUID_DEVCLASS_NET, &This->pItem->ClassGUID)) 00290 return E_UNEXPECTED; 00291 00292 *pStatus = This->pItem->Status; 00293 00294 return S_OK; 00295 } 00296 00297 HRESULT 00298 WINAPI 00299 INetCfgComponent_fnOpenParamKey( 00300 INetCfgComponent * iface, 00301 HKEY * phkey) 00302 { 00303 WCHAR szBuffer[200] = L"SYSTEM\\CurrentControlSet\\Services\\"; 00304 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00305 00306 if (This == NULL || phkey == NULL) 00307 return E_POINTER; 00308 00309 wcscat(szBuffer, This->pItem->szBindName); 00310 wcscat(szBuffer, L"\\Parameters"); 00311 00312 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szBuffer, 0, KEY_READ | KEY_WRITE, phkey) == ERROR_SUCCESS) 00313 return S_OK; 00314 else 00315 return E_FAIL; 00316 } 00317 00318 00319 HRESULT 00320 CreateNotificationObject( 00321 INetCfgComponentImpl * This, 00322 INetCfgComponent * iface, 00323 IUnknown *pUnk) 00324 { 00325 WCHAR szName[150]; 00326 HKEY hKey; 00327 DWORD dwSize, dwType; 00328 GUID CLSID_NotifyObject; 00329 LPOLESTR pStr; 00330 INetCfgComponentPropertyUi * pNCCPU; 00331 INetCfgComponentControl * pNCCC; 00332 HRESULT hr; 00333 LONG lRet; 00334 CLSID ClassGUID; 00335 //CLSID InstanceGUID; 00336 00337 wcscpy(szName,L"SYSTEM\\CurrentControlSet\\Control\\Network\\"); 00338 00339 /* get the Class GUID */ 00340 hr = INetCfgComponent_GetClassGuid(iface, &ClassGUID); 00341 if (FAILED(hr)) 00342 return hr; 00343 00344 hr = StringFromCLSID(&ClassGUID, &pStr); 00345 if (FAILED(hr)) 00346 return hr; 00347 00348 wcscat(szName, pStr); 00349 CoTaskMemFree(pStr); 00350 wcscat(szName, L"\\"); 00351 00352 /* get the Instance GUID */ 00353 #if 0 00354 hr = INetCfgComponent_GetInstanceGuid(iface, &InstanceGUID); 00355 if (FAILED(hr)) 00356 return hr; 00357 00358 hr = StringFromCLSID(&InstanceGUID, &pStr); 00359 if (FAILED(hr)) 00360 return hr; 00361 00362 wcscat(szName, pStr); 00363 CoTaskMemFree(pStr); 00364 #else 00365 // HACK HACK HACK HACK HACK 00366 wcscat(szName, L"{RandomProtocolGUID_TCPIP}"); 00367 #endif 00368 00369 wcscat(szName, L"\\NDI"); 00370 00371 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hKey) != ERROR_SUCCESS) 00372 return E_FAIL; 00373 00374 dwSize = sizeof(szName); 00375 lRet = RegQueryValueExW(hKey, L"ClsID", NULL, &dwType, (LPBYTE)szName, &dwSize); 00376 RegCloseKey(hKey); 00377 00378 if (lRet != ERROR_SUCCESS && dwType != REG_SZ) 00379 return E_FAIL; 00380 00381 hr = CLSIDFromString(szName, &CLSID_NotifyObject); 00382 if (FAILED(hr)) 00383 return E_FAIL; 00384 00385 hr = CoCreateInstance(&CLSID_NotifyObject, NULL, CLSCTX_INPROC_SERVER, &IID_INetCfgComponentPropertyUi, (LPVOID*)&pNCCPU); 00386 if (FAILED(hr)) 00387 return E_FAIL; 00388 00389 hr = INetCfgComponentPropertyUi_QueryInterface(pNCCPU, &IID_INetCfgComponentControl, (LPVOID*)&pNCCC); 00390 if (FAILED(hr)) 00391 { 00392 INetCfgComponentPropertyUi_Release(pNCCPU); 00393 return hr; 00394 } 00395 00396 hr = INetCfgComponentPropertyUi_QueryPropertyUi(pNCCPU, pUnk); 00397 if (FAILED(hr)) 00398 { 00399 INetCfgComponentPropertyUi_Release(pNCCPU); 00400 return hr; 00401 } 00402 00403 hr = INetCfgComponentControl_Initialize(pNCCC, iface, This->pNCfg, FALSE); 00404 if (FAILED(hr)) 00405 { 00406 INetCfgComponentControl_Release(pNCCC); 00407 INetCfgComponentPropertyUi_Release(pNCCPU); 00408 return hr; 00409 } 00410 00411 hr = INetCfgComponentPropertyUi_SetContext(pNCCPU, pUnk); 00412 if (FAILED(hr)) 00413 { 00414 INetCfgComponentPropertyUi_Release(pNCCPU); 00415 return hr; 00416 } 00417 This->pProperty = pNCCPU; 00418 This->pItem->pNCCC = pNCCC; 00419 00420 return S_OK; 00421 } 00422 00423 HRESULT 00424 WINAPI 00425 INetCfgComponent_fnRaisePropertyUi( 00426 INetCfgComponent * iface, 00427 IN HWND hwndParent, 00428 IN DWORD dwFlags, 00429 IN IUnknown *pUnk) 00430 { 00431 HRESULT hr; 00432 DWORD dwDefPages; 00433 UINT Pages; 00434 PROPSHEETHEADERW pinfo; 00435 HPROPSHEETPAGE * hppages; 00436 INT_PTR iResult; 00437 INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; 00438 00439 if (!This->pProperty) 00440 { 00441 hr = CreateNotificationObject(This,iface, pUnk); 00442 if (FAILED(hr)) 00443 return hr; 00444 } 00445 00446 if (dwFlags == NCRP_QUERY_PROPERTY_UI) 00447 return S_OK; 00448 00449 dwDefPages = 0; 00450 Pages = 0; 00451 00452 hr = INetCfgComponentPropertyUi_MergePropPages(This->pProperty, &dwDefPages, (BYTE**)&hppages, &Pages, hwndParent, NULL); 00453 if (FAILED(hr) || !Pages) 00454 { 00455 return hr; 00456 } 00457 ZeroMemory(&pinfo, sizeof(PROPSHEETHEADERW)); 00458 pinfo.dwSize = sizeof(PROPSHEETHEADERW); 00459 pinfo.dwFlags = PSH_NOCONTEXTHELP | PSH_PROPTITLE | PSH_NOAPPLYNOW; 00460 pinfo.u3.phpage = hppages; 00461 pinfo.hwndParent = hwndParent; 00462 pinfo.nPages = Pages; 00463 pinfo.pszCaption = This->pItem->szDisplayName; 00464 00465 iResult = PropertySheetW(&pinfo); 00466 CoTaskMemFree(hppages); 00467 if (iResult > 0) 00468 { 00469 /* indicate that settings should be stored */ 00470 This->pItem->bChanged = TRUE; 00471 return S_OK; 00472 } 00473 return S_FALSE; 00474 } 00475 static const INetCfgComponentVtbl vt_NetCfgComponent = 00476 { 00477 INetCfgComponent_fnQueryInterface, 00478 INetCfgComponent_fnAddRef, 00479 INetCfgComponent_fnRelease, 00480 INetCfgComponent_fnGetDisplayName, 00481 INetCfgComponent_fnSetDisplayName, 00482 INetCfgComponent_fnGetHelpText, 00483 INetCfgComponent_fnGetId, 00484 INetCfgComponent_fnGetCharacteristics, 00485 INetCfgComponent_fnGetInstanceGuid, 00486 INetCfgComponent_fnGetPnpDevNodeId, 00487 INetCfgComponent_fnGetClassGuid, 00488 INetCfgComponent_fnGetBindName, 00489 INetCfgComponent_fnGetDeviceStatus, 00490 INetCfgComponent_fnOpenParamKey, 00491 INetCfgComponent_fnRaisePropertyUi 00492 }; 00493 00494 HRESULT 00495 WINAPI 00496 INetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, NetCfgComponentItem * pItem, INetCfg * pNCfg) 00497 { 00498 INetCfgComponentImpl *This; 00499 00500 if (!ppv) 00501 return E_POINTER; 00502 00503 This = (INetCfgComponentImpl *) CoTaskMemAlloc(sizeof (INetCfgComponentImpl)); 00504 if (!This) 00505 return E_OUTOFMEMORY; 00506 00507 This->ref = 1; 00508 This->lpVtbl = (const INetCfgComponent*)&vt_NetCfgComponent; 00509 This->pProperty = NULL; 00510 This->pItem = pItem; 00511 This->pNCfg = pNCfg; 00512 00513 if (!SUCCEEDED (INetCfgComponent_QueryInterface ((INetCfgComponent*)This, riid, ppv))) 00514 { 00515 INetCfgComponent_Release((INetCfg*)This); 00516 return E_NOINTERFACE; 00517 } 00518 00519 INetCfgComponent_Release((INetCfgComponent*)This); 00520 return S_OK; 00521 } 00522 00523 00524 /*************************************************************** 00525 * IEnumNetCfgComponent 00526 */ 00527 00528 HRESULT 00529 WINAPI 00530 IEnumNetCfgComponent_fnQueryInterface( 00531 IEnumNetCfgComponent * iface, 00532 REFIID iid, 00533 LPVOID * ppvObj) 00534 { 00535 IEnumNetCfgComponentImpl * This = (IEnumNetCfgComponentImpl*)iface; 00536 *ppvObj = NULL; 00537 00538 if (IsEqualIID (iid, &IID_IUnknown) || 00539 IsEqualIID (iid, &IID_IEnumNetCfgComponent)) 00540 { 00541 *ppvObj = This; 00542 INetCfg_AddRef(iface); 00543 return S_OK; 00544 } 00545 00546 return E_NOINTERFACE; 00547 } 00548 00549 00550 ULONG 00551 WINAPI 00552 IEnumNetCfgComponent_fnAddRef( 00553 IEnumNetCfgComponent * iface) 00554 { 00555 IEnumNetCfgComponentImpl * This = (IEnumNetCfgComponentImpl*)iface; 00556 ULONG refCount = InterlockedIncrement(&This->ref); 00557 00558 return refCount; 00559 } 00560 00561 ULONG 00562 WINAPI 00563 IEnumNetCfgComponent_fnRelease( 00564 IEnumNetCfgComponent * iface) 00565 { 00566 IEnumNetCfgComponentImpl * This = (IEnumNetCfgComponentImpl*)iface; 00567 ULONG refCount = InterlockedDecrement(&This->ref); 00568 00569 return refCount; 00570 } 00571 00572 HRESULT 00573 WINAPI 00574 IEnumNetCfgComponent_fnNext( 00575 IEnumNetCfgComponent * iface, 00576 ULONG celt, 00577 INetCfgComponent **rgelt, 00578 ULONG *pceltFetched) 00579 { 00580 HRESULT hr; 00581 IEnumNetCfgComponentImpl * This = (IEnumNetCfgComponentImpl*)iface; 00582 00583 if (!iface || !rgelt) 00584 return E_POINTER; 00585 00586 if (celt != 1) 00587 return E_INVALIDARG; 00588 00589 if (!This->pCurrent) 00590 return S_FALSE; 00591 00592 hr = INetCfgComponent_Constructor (NULL, &IID_INetCfgComponent, (LPVOID*)rgelt, This->pCurrent, This->pNCfg); 00593 if (SUCCEEDED(hr)) 00594 { 00595 This->pCurrent = This->pCurrent->pNext; 00596 if (pceltFetched) 00597 *pceltFetched = 1; 00598 } 00599 return hr; 00600 } 00601 00602 HRESULT 00603 WINAPI 00604 IEnumNetCfgComponent_fnSkip( 00605 IEnumNetCfgComponent * iface, 00606 ULONG celt) 00607 { 00608 IEnumNetCfgComponentImpl * This = (IEnumNetCfgComponentImpl*)iface; 00609 00610 if (!This->pCurrent) 00611 return S_FALSE; 00612 00613 while(celt-- > 0 && This->pCurrent) 00614 This->pCurrent = This->pCurrent->pNext; 00615 00616 if (!celt) 00617 return S_OK; 00618 else 00619 return S_FALSE; 00620 } 00621 00622 HRESULT 00623 WINAPI 00624 IEnumNetCfgComponent_fnReset( 00625 IEnumNetCfgComponent * iface) 00626 { 00627 IEnumNetCfgComponentImpl * This = (IEnumNetCfgComponentImpl*)iface; 00628 00629 This->pCurrent = This->pHead; 00630 return S_OK; 00631 } 00632 00633 HRESULT 00634 WINAPI 00635 IEnumNetCfgComponent_fnClone( 00636 IEnumNetCfgComponent * iface, 00637 IEnumNetCfgComponent **ppenum) 00638 { 00639 return E_NOTIMPL; 00640 } 00641 00642 static const IEnumNetCfgComponentVtbl vt_EnumNetCfgComponent = 00643 { 00644 IEnumNetCfgComponent_fnQueryInterface, 00645 IEnumNetCfgComponent_fnAddRef, 00646 IEnumNetCfgComponent_fnRelease, 00647 IEnumNetCfgComponent_fnNext, 00648 IEnumNetCfgComponent_fnSkip, 00649 IEnumNetCfgComponent_fnReset, 00650 IEnumNetCfgComponent_fnClone 00651 }; 00652 00653 HRESULT 00654 WINAPI 00655 IEnumNetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, NetCfgComponentItem * pItem, INetCfg * pNCfg) 00656 { 00657 IEnumNetCfgComponentImpl *This; 00658 00659 if (!ppv) 00660 return E_POINTER; 00661 00662 This = (IEnumNetCfgComponentImpl *) CoTaskMemAlloc(sizeof (IEnumNetCfgComponentImpl)); 00663 if (!This) 00664 return E_OUTOFMEMORY; 00665 00666 This->ref = 1; 00667 This->lpVtbl = (const IEnumNetCfgComponent*)&vt_EnumNetCfgComponent; 00668 This->pCurrent = pItem; 00669 This->pHead = pItem; 00670 This->pNCfg = pNCfg; 00671 00672 if (!SUCCEEDED (IEnumNetCfgComponent_QueryInterface ((INetCfgComponent*)This, riid, ppv))) 00673 { 00674 IEnumNetCfgComponent_Release((INetCfg*)This); 00675 return E_NOINTERFACE; 00676 } 00677 00678 IEnumNetCfgComponent_Release((IEnumNetCfgComponent*)This); 00679 return S_OK; 00680 } 00681 00682 Generated on Sun May 27 2012 04:25:28 for ReactOS by
1.7.6.1
|