from
http://bit.ly/f7xeF0 (very long link to a google groups topic)
Stephan, et al,
The attached sample code uses the Shell APIs and will pop up the network
adapter Wireless Networks properties or Wireless Connections diaplog
depending on the value of ci.lpVerb (szShowWirelessProperties
"wzcproperties" or szShowWirelessConnect 0x0018), see code fragment below.
These values may change at any time and this sample is provided "as is".
ConnectionGUID will have to be changed to the GUID for your adapter. This
is the same GUID as the NetCfgInstanceId for the adapter.
Bryan S. Burgin
bbur...@microsoft.com
This posting is provided "AS IS" with no warranties, and confers no rights.
// ShellExecuteSample.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <shellapi.h>
#include <iostream.h>
#include <objbase.h>
#include <shlobj.h>
#include <wtypes.h>
// {7007ACC7-3202-11D1-AAD2-00805FC1270E}
const GUID CLSID_NetworkConnections = { 0x7007ACC7, 0x3202, 0x11D1, { 0xAA,
0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E } };
// Change this connection GUID to the GUID of the Wireless Network Device.
LPWSTR ConnectionGUID = L"::{C07F7206-6DF1-4537-9890-D71C981BF952}";
// The '18' below may appear like a magic number, but it's really not. If
you were to
// call IContextMenu->QueryContextMenu, and look for the Cmd ID of 'Show
Available Wireless Networks'
// you'll see it to be 18. The value is constant.
LPCSTR szShowWirelessConnect = (LPCSTR)0x0018;
LPCSTR szShowWirelessProperties = "wzcproperties";
int main(int argc, char* argv[])
{
CoInitialize(NULL);
IShellFolder *pShellFolder;
HRESULT hr = CoCreateInstance(CLSID_NetworkConnections, NULL,
CLSCTX_INPROC_SERVER,
IID_IShellFolder, reinterpret_cast<LPVOID
*>(&pShellFolder) );
if (SUCCEEDED(hr))
{
LPITEMIDLIST pidl;
hr = pShellFolder->ParseDisplayName(NULL, NULL, ConnectionGUID,
NULL, &pidl, NULL);
if (SUCCEEDED(hr))
{
LPCITEMIDLIST apidl[] = { pidl };
IContextMenu* pContextMenu;
hr = pShellFolder->GetUIObjectOf(NULL, 1, apidl,
IID_IContextMenu, NULL, reinterpret_cast<LPVOID *>(&pContextMenu));
if (SUCCEEDED(hr))
{
CMINVOKECOMMANDINFO ci;
ZeroMemory(&ci, sizeof(CMINVOKECOMMANDINFO));
// Change this line to show either szShowWirelessProperties
or szShowWirelessConnect
// ci.lpVerb = szShowWirelessProperties;
ci.lpVerb = szShowWirelessConnect;
hr = pContextMenu->InvokeCommand(&ci);
if (SUCCEEDED(hr))
{
cout << "Done - spinning message loop\n";
// Spin a windows message loop in order to give the
dialog chance to process commands.
// Of course to do it here is totally wrong - this
should be as part of a parent window's windowproc
// otherwise this app will never terminate. However,
this is just for illustration.
BOOL bRet;
MSG msg;
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
pContextMenu->Release();
}
}
pShellFolder->Release();
// Free the PIDL using the shell's allocator
IMalloc* pShellMalloc;
hr = SHGetMalloc(&pShellMalloc);
if (SUCCEEDED(hr))
{
pShellMalloc->Free(pidl);
}
}
if (FAILED(hr))
{
cout << "Could not open wireless dialog due to error " << hr;
}
else
{
cout << "Success";
}
CoUninitialize();
return 0;
Note: there were some hard breaks in the C&P, so the highlighting is wrong in places
