From 401bef3301857303be81bf21fc684d77baa3973c Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Tue, 9 Sep 2008 14:29:25 +0000 Subject: [PATCH] - Implement INetCfgComponent_RaisePropertyUi svn path=/trunk/; revision=36084 --- reactos/dll/win32/netcfgx/inetcfgcomp_iface.c | 149 +++++++++++++++++- reactos/dll/win32/netcfgx/netcfg_iface.c | 19 +-- reactos/dll/win32/netcfgx/precomp.h | 5 +- 3 files changed, 158 insertions(+), 15 deletions(-) diff --git a/reactos/dll/win32/netcfgx/inetcfgcomp_iface.c b/reactos/dll/win32/netcfgx/inetcfgcomp_iface.c index 6a72419c52e..4b8baab94d8 100644 --- a/reactos/dll/win32/netcfgx/inetcfgcomp_iface.c +++ b/reactos/dll/win32/netcfgx/inetcfgcomp_iface.c @@ -6,6 +6,8 @@ typedef struct const INetCfgComponent * lpVtbl; LONG ref; NetCfgComponentItem * pItem; + INetCfgComponentPropertyUi * pProperty; + INetCfg * pNCfg; }INetCfgComponentImpl; typedef struct @@ -14,6 +16,7 @@ typedef struct LONG ref; NetCfgComponentItem * pCurrent; NetCfgComponentItem * pHead; + INetCfg * pNCfg; }IEnumNetCfgComponentImpl; @@ -312,6 +315,103 @@ INetCfgComponent_fnOpenParamKey( return E_FAIL; } + +HRESULT +CreateNotificationObject( + INetCfgComponentImpl * This, + INetCfgComponent * iface, + IUnknown *pUnk, + INetCfgComponentPropertyUi ** pOut) +{ + WCHAR szName[150]; + HKEY hKey; + DWORD dwSize, dwType; + GUID CLSID_NotifyObject; + LPOLESTR pStr; + INetCfgComponentPropertyUi * pNCCPU; + INetCfgComponentControl * pNCCC; + HRESULT hr; + LONG lRet; + CLSID ClassGUID, InstanceGUID; + + wcscpy(szName,L"SYSTEM\\CurrentControlSet\\Control\\Network\\"); + + /* get the Class GUID */ + hr = INetCfgComponent_GetClassGuid(iface, &ClassGUID); + if (FAILED(hr)) + return hr; + + hr = StringFromCLSID(&ClassGUID, &pStr); + if (FAILED(hr)) + return hr; + + wcscat(szName, pStr); + CoTaskMemFree(pStr); + wcscat(szName, L"\\"); + + /* get the Class GUID */ + hr = INetCfgComponent_GetInstanceGuid(iface, &InstanceGUID); + if (FAILED(hr)) + return hr; + + hr = StringFromCLSID(&InstanceGUID, &pStr); + if (FAILED(hr)) + return hr; + + wcscat(szName, pStr); + CoTaskMemFree(pStr); + wcscat(szName, L"\\NDI"); + + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hKey) != ERROR_SUCCESS) + return E_FAIL; + + dwSize = sizeof(szName); + lRet = RegQueryValueExW(hKey, L"ClsID", NULL, &dwType, (LPBYTE)szName, &dwSize); + RegCloseKey(hKey); + + if (lRet != ERROR_SUCCESS && dwType != REG_SZ) + return E_FAIL; + + hr = CLSIDFromString(szName, &CLSID_NotifyObject); + if (FAILED(hr)) + return E_FAIL; + + hr = CoCreateInstance(&CLSID_NotifyObject, NULL, CLSCTX_INPROC_SERVER, &IID_INetCfgComponentPropertyUi, (LPVOID*)&pNCCPU); + if (FAILED(hr)) + return E_FAIL; + + hr = INetCfgComponentPropertyUi_QueryInterface(pNCCPU, &IID_INetCfgComponentControl, (LPVOID*)&pNCCC); + if (FAILED(hr)) + { + INetCfgComponentPropertyUi_Release(pNCCPU); + return hr; + } + + hr = INetCfgComponentPropertyUi_QueryPropertyUi(pNCCPU, pUnk); + if (FAILED(hr)) + { + INetCfgComponentPropertyUi_Release(pNCCPU); + return hr; + } + + hr = INetCfgComponentControl_Initialize(pNCCC, iface, This->pNCfg, FALSE); + if (FAILED(hr)) + { + INetCfgComponentControl_Release(pNCCC); + INetCfgComponentPropertyUi_Release(pNCCPU); + return hr; + } + + hr = INetCfgComponentPropertyUi_SetContext(pNCCPU, pUnk); + if (FAILED(hr)) + { + INetCfgComponentPropertyUi_Release(pNCCPU); + return hr; + } + *pOut = pNCCPU; + return S_OK; +} + HRESULT STDCALL INetCfgComponent_fnRaisePropertyUi( @@ -320,8 +420,46 @@ INetCfgComponent_fnRaisePropertyUi( IN DWORD dwFlags, IN IUnknown *pUnk) { + HRESULT hr; + DWORD dwDefPages; + UINT Pages; + PROPSHEETHEADERW pinfo; + HPROPSHEETPAGE * hppages; + INT_PTR iResult; + INetCfgComponentImpl * This = (INetCfgComponentImpl*)iface; - return E_NOTIMPL; + if (!This->pProperty) + { + hr = CreateNotificationObject(This,iface, pUnk, &This->pProperty); + if (FAILED(hr)) + return hr; + } + + dwDefPages = 1; + hr = INetCfgComponentPropertyUi_MergePropPages(This->pProperty, &dwDefPages, (BYTE**)&hppages, &Pages, hwndParent, NULL); + if (FAILED(hr)) + { + return hr; + } + ZeroMemory(&pinfo, sizeof(PROPSHEETHEADERW)); + pinfo.dwSize = sizeof(PROPSHEETHEADERW); + pinfo.dwFlags = PSH_NOCONTEXTHELP | PSH_PROPTITLE | PSH_NOAPPLYNOW; + pinfo.u3.phpage = hppages; + pinfo.hwndParent = hwndParent; + pinfo.pszCaption = This->pItem->szDisplayName; + + iResult = PropertySheetW(&pinfo); + CoTaskMemFree(hppages); + if (iResult < 0) + { + INetCfgComponentPropertyUi_CancelProperties(This->pProperty); + return E_ABORT; + } + else + { + INetCfgComponentPropertyUi_ApplyProperties(This->pProperty); + return S_OK; + } } static const INetCfgComponentVtbl vt_NetCfgComponent = { @@ -344,7 +482,7 @@ static const INetCfgComponentVtbl vt_NetCfgComponent = HRESULT STDCALL -INetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, NetCfgComponentItem * pItem) +INetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, NetCfgComponentItem * pItem, INetCfg * pNCfg) { INetCfgComponentImpl *This; @@ -357,7 +495,9 @@ INetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, N This->ref = 1; This->lpVtbl = (const INetCfgComponent*)&vt_NetCfgComponent; + This->pProperty = NULL; This->pItem = pItem; + This->pNCfg = pNCfg; if (!SUCCEEDED (INetCfgComponent_QueryInterface ((INetCfgComponent*)This, riid, ppv))) { @@ -441,7 +581,7 @@ IEnumNetCfgComponent_fnNext( if (!This->pCurrent) return S_FALSE; - hr = INetCfgComponent_Constructor (NULL, &IID_INetCfgComponent, (LPVOID*)rgelt, This->pCurrent); + hr = INetCfgComponent_Constructor (NULL, &IID_INetCfgComponent, (LPVOID*)rgelt, This->pCurrent, This->pNCfg); if (SUCCEEDED(hr)) { This->pCurrent = This->pCurrent->pNext; @@ -504,7 +644,7 @@ static const IEnumNetCfgComponentVtbl vt_EnumNetCfgComponent = HRESULT STDCALL -IEnumNetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, NetCfgComponentItem * pItem) +IEnumNetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, NetCfgComponentItem * pItem, INetCfg * pNCfg) { IEnumNetCfgComponentImpl *This; @@ -519,6 +659,7 @@ IEnumNetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * pp This->lpVtbl = (const IEnumNetCfgComponent*)&vt_EnumNetCfgComponent; This->pCurrent = pItem; This->pHead = pItem; + This->pNCfg = pNCfg; if (!SUCCEEDED (IEnumNetCfgComponent_QueryInterface ((INetCfgComponent*)This, riid, ppv))) { diff --git a/reactos/dll/win32/netcfgx/netcfg_iface.c b/reactos/dll/win32/netcfgx/netcfg_iface.c index baed12b5cc7..fc5bce3d8f3 100644 --- a/reactos/dll/win32/netcfgx/netcfg_iface.c +++ b/reactos/dll/win32/netcfgx/netcfg_iface.c @@ -425,13 +425,14 @@ HRESULT FindNetworkComponent( NetCfgComponentItem * pHead, LPCWSTR pszwComponentId, - INetCfgComponent **pComponent) + INetCfgComponent **pComponent, + INetCfg * iface) { while(pHead) { if (!wcsicmp(pHead->szId, pszwComponentId)) { - return INetCfgComponent_Constructor(NULL, &IID_INetCfgComponent, (LPVOID*)pComponent, pHead); + return INetCfgComponent_Constructor(NULL, &IID_INetCfgComponent, (LPVOID*)pComponent, pHead, iface); } pHead = pHead->pNext; } @@ -586,13 +587,13 @@ INetCfg_fnEnumComponents( return NETCFG_E_NOT_INITIALIZED; if (IsEqualGUID(&GUID_DEVCLASS_NET, pguidClass)) - return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pNet); + return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pNet, iface); else if (IsEqualGUID(&GUID_DEVCLASS_NETCLIENT, pguidClass)) - return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pClient); + return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pClient, iface); else if (IsEqualGUID(&GUID_DEVCLASS_NETSERVICE, pguidClass)) - return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pService); + return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pService, iface); else if (IsEqualGUID(&GUID_DEVCLASS_NETTRANS, pguidClass)) - return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pProtocol); + return IEnumNetCfgComponent_Constructor (NULL, &IID_IEnumNetCfgComponent, (LPVOID*)ppenumComponent, This->pProtocol, iface); else return E_NOINTERFACE; } @@ -611,15 +612,15 @@ INetCfg_fnFindComponent( if (!This->bInitialized) return NETCFG_E_NOT_INITIALIZED; - hr = FindNetworkComponent(This->pClient, pszwComponentId, pComponent); + hr = FindNetworkComponent(This->pClient, pszwComponentId, pComponent, iface); if (hr == S_OK) return hr; - hr = FindNetworkComponent(This->pService, pszwComponentId, pComponent); + hr = FindNetworkComponent(This->pService, pszwComponentId, pComponent, iface); if (hr == S_OK) return hr; - hr = FindNetworkComponent(This->pProtocol, pszwComponentId, pComponent); + hr = FindNetworkComponent(This->pProtocol, pszwComponentId, pComponent, iface); if (hr == S_OK) return hr; diff --git a/reactos/dll/win32/netcfgx/precomp.h b/reactos/dll/win32/netcfgx/precomp.h index 66e06a61a5a..916650c7e28 100644 --- a/reactos/dll/win32/netcfgx/precomp.h +++ b/reactos/dll/win32/netcfgx/precomp.h @@ -11,6 +11,7 @@ #include #include #include +#include typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject); typedef struct { @@ -43,7 +44,7 @@ IClassFactory * IClassFactory_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcR extern HINSTANCE netcfgx_hInstance; /* inetcfgcomp_iface.c */ -HRESULT STDCALL INetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, NetCfgComponentItem * pItem); -HRESULT STDCALL IEnumNetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, NetCfgComponentItem * pItem); +HRESULT STDCALL INetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, NetCfgComponentItem * pItem,INetCfg * iface); +HRESULT STDCALL IEnumNetCfgComponent_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv, NetCfgComponentItem * pItem, INetCfg * iface); #endif