Discussion:
HOWTO show tcp/ip properties using INetCfgComponent::RaisePropertyUi
(too old to reply)
sergei
2005-03-31 07:25:57 UTC
Permalink
Hi everybody.

I'm trying to show the TCP/IP properties dialog from the user mode
application. I'm using network configuration interfaces and
INetCfgComponent::RaisePropertyUi pops up a message box: "In order to
configure TCP/IP, you must install and enable a network adapter card."

Here is the code:

void InvokeTCPIPProperties(HWND hWndParent)
{
CComPtr<INetCfg> NetCfg;
CComQIPtr<INetCfgLock> NetCfgLock;
CComPtr<INetCfgComponent> NetCfgComponent;
HRESULT hr = S_OK;
LPWSTR ppszwrClient = NULL;

hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_SERVER,
IID_INetCfg, (LPVOID*)&NetCfg);

NetCfgLock = NetCfg;
hr = NetCfgLock->AcquireWriteLock(5, _T("MY CLIENT"),
&ppszwrClient);
hr = NetCfg->Initialize(NULL);

hr = NetCfg->FindComponent(NETCFG_TRANS_CID_MS_TCPIP,
&NetCfgComponent);

CLSID notifyObjectClsid = GUID_NULL;
CLSIDFromString(L"{A907657F-6FDF-11D0-8EFB-00C04FD912B2}",
&notifyObjectClsid); //Microsoft TCP/IP Configuration Notify Object

CComPtr<INetCfgComponentControl> spControl;
hr = CoCreateInstance(notifyObjectClsid, NULL, CLSCTX_SERVER,
IID_INetCfgComponentControl, (LPVOID*)&spControl);

hr = spControl->Initialize(NetCfgComponent, NetCfg, FALSE);

hr = NetCfgComponent->RaisePropertyUi(hWndParent,
NCRP_SHOW_PROPERTY_UI, spControl);

hr = NetCfg->Apply();
hr = NetCfg->Uninitialize();
hr = NetCfgLock->ReleaseWriteLock();
}

All functions return S_OK except RaisePropertyUi that returns
0x80070491 (There was no match for the specified key in the index).

What I'm doing wrong?

Another question is how to get the CLSID of the notify object. I'm
using a guid found it in the registry that definitely is not a
legal/right way. (Maybe the problem is here?)

Any help greatly appreciated.

Sergey
Eugene Gershnik
2005-03-31 07:50:00 UTC
Permalink
Post by sergei
hr = NetCfg->FindComponent(NETCFG_TRANS_CID_MS_TCPIP,
&NetCfgComponent);
[...]
Post by sergei
hr = spControl->Initialize(NetCfgComponent, NetCfg, FALSE);
[...]
Post by sergei
What I'm doing wrong?
Try to pass a specific adapter as "owning" component. TCP/IP properties do
not exist by themselves but are properties of an adapter.

--
Eugene
sergei
2005-04-04 08:13:05 UTC
Permalink
Eugene

thanks for your reply! Your advice did not solve the problem, but it
gave me some clue. After many experiments I've had my code to work.

The key is the third argument of the RaisePropertyUi function. The
object exposing passed IUnknown must implement the
INetLanConnectionUiInfo interface that gives the context in which to
display a network component's property sheet.

The code looks like this:

CComPtr<INetCfg> NetCfg;
CComQIPtr<INetCfgLock> NetCfgLock;
CComPtr<INetCfgComponent> NetCfgComponent;
HRESULT hr = S_OK;
LPWSTR ppszwrClient = NULL;

CComObject<CNetLanConnectionUi>* pNetLanConnectionUiObj = NULL;
hr = CComObject<CNetLanConnectionUi>::CreateInstance(&pNetLanConnectionUiObj);
CComPtr<IUnknown> spNetLanConnectionUi(pNetLanConnectionUiObj);

hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_SERVER,
IID_INetCfg, (LPVOID*)&NetCfg);

NetCfgLock = NetCfg;
hr = NetCfgLock->AcquireWriteLock(5, _T("MY CLIENT"),
&ppszwrClient);
hr = NetCfg->Initialize(NULL);

hr = NetCfg->FindComponent(NETCFG_TRANS_CID_MS_TCPIP,
&NetCfgComponent);

hr = NetCfgComponent->RaisePropertyUi(hWnd, NCRP_SHOW_PROPERTY_UI,
spNetLanConnectionUi);

hr = NetCfg->Apply();
hr = NetCfg->Uninitialize();
hr = NetCfgLock->ReleaseWriteLock();

CNetLanConnectionUi is my class that implements
INetLanConnectionUiInfo. GetDeviceGuid returns the GUID of an adapter
for which to display a property sheet.
Eugene Gershnik
2005-04-04 09:38:12 UTC
Permalink
Post by Eugene Gershnik
Eugene
thanks for your reply! Your advice did not solve the problem, but it
gave me some clue. After many experiments I've had my code to work.
Glad to hear! Also take a look at this thread where MS guy presents
something more elaborate

http://groups-beta.google.com/group/microsoft.public.development.device.drivers/browse_frm/thread/cd854d398f9f14a6

--
Eugene
chan hor ming
2005-12-21 11:37:32 UTC
Permalink
side question.
How can we configure network load balancing properties without the UI
properties?

Can we use the similar code to configure network load balancing parameters
without raising the UI on the screen?

Loading...