diff options
| author | Dave Wilson <[email protected]> | 2015-03-17 19:50:07 -0700 |
|---|---|---|
| committer | Dave Wilson <[email protected]> | 2015-03-17 19:50:07 -0700 |
| commit | 97cf5197cf5b882b2c689d8dc2b555f2edf8f418 (patch) | |
| tree | 46f3701832d70b420eb0fc0eb93261f9da45db3f /network/config/bindview | |
| parent | ef1905bf1e8825bb31120dfb27e0daf3154d859a (diff) | |
Initial publish
Diffstat (limited to 'network/config/bindview')
| -rw-r--r-- | network/config/bindview/BINDING.CPP | 827 | ||||
| -rw-r--r-- | network/config/bindview/BINDVIEW.CPP | 2336 | ||||
| -rw-r--r-- | network/config/bindview/BINDVIEW.H | 250 | ||||
| -rw-r--r-- | network/config/bindview/BINDVIEW.ICO | bin | 0 -> 766 bytes | |||
| -rw-r--r-- | network/config/bindview/BindView.rc | 194 | ||||
| -rw-r--r-- | network/config/bindview/Component.cpp | 897 | ||||
| -rw-r--r-- | network/config/bindview/NetCfgAPI.cpp | 878 | ||||
| -rw-r--r-- | network/config/bindview/NetCfgAPI.h | 92 | ||||
| -rw-r--r-- | network/config/bindview/RESOURCE.H | 43 | ||||
| -rw-r--r-- | network/config/bindview/ReadMe.md | 7 | ||||
| -rw-r--r-- | network/config/bindview/bindview.htm | 345 | ||||
| -rw-r--r-- | network/config/bindview/bindview.sln | 28 | ||||
| -rw-r--r-- | network/config/bindview/bindview.vcxproj | 211 | ||||
| -rw-r--r-- | network/config/bindview/bindview.vcxproj.Filters | 36 |
14 files changed, 6144 insertions, 0 deletions
diff --git a/network/config/bindview/BINDING.CPP b/network/config/bindview/BINDING.CPP new file mode 100644 index 00000000..b3771004 --- /dev/null +++ b/network/config/bindview/BINDING.CPP @@ -0,0 +1,827 @@ +//+--------------------------------------------------------------------------- +// +// Microsoft Windows +// Copyright (C) Microsoft Corporation, 2001. +// +// File: B I N D I N G . C P P +// +// Contents: Functions to illustrate +// o How to enumerate binding paths. +// o How to enumerate binding interfaces. +// o How to enable/disable bindings. +// +// Notes: +// +// Author: Alok Sinha 15-May-01 +// +//---------------------------------------------------------------------------- + +#include "bindview.h" + +// +// Function: WriteBindings +// +// Purpose: Write bindings to specified file. +// +// Arguments: +// fp [in] File handle. +// +// Returns: None. +// +// Notes: +// + +VOID WriteBindings (FILE *fp) +{ + INetCfg *pnc; + IEnumNetCfgComponent *pencc; + INetCfgComponent *pncc; + LPWSTR lpszApp; + HRESULT hr; + UINT i; + + + hr = HrGetINetCfg( FALSE, + APP_NAME, + &pnc, + &lpszApp ); + + if ( hr == S_OK ) { + + for (i=CLIENTS_SELECTED; i <= PROTOCOLS_SELECTED; ++i) { + + fwprintf( fp, L"--- Bindings of %s ---\n", lpszNetClass[i] ); + + // + // Get Component Enumerator Interface. + // + + hr = HrGetComponentEnum( pnc, + pguidNetClass[i], + &pencc ); + if ( hr == S_OK ) { + + hr = HrGetFirstComponent( pencc, &pncc ); + + while( hr == S_OK ) { + + // + // Write bindings of the component. + // + + WriteBindingPath( fp, + pncc ); + ReleaseRef( pncc ); + + fwprintf( fp, L"\n" ); + + hr = HrGetNextComponent( pencc, &pncc ); + } + + fwprintf( fp, L"\n" ); + + // + // S_FALSE merely indicates that there are no more components. + // + + if ( hr == S_FALSE ) { + hr = S_OK; + } + + ReleaseRef( pencc ); + } + else { + ErrMsg( hr, + L"Couldn't get the component enumerator interface." ); + } + } + + HrReleaseINetCfg( pnc, FALSE ); + } + else { + if ( (hr == NETCFG_E_NO_WRITE_LOCK) && lpszApp ) { + ErrMsg( hr, + L"%s currently holds the lock, try later.", + lpszApp ); + + CoTaskMemFree( lpszApp ); + } + else { + ErrMsg( hr, + L"Couldn't get the notify object interface." ); + } + } + + return; +} + +// +// Function: WriteBindingPath +// +// Purpose: Write binding paths of a component. +// +// Arguments: +// fp [in] File handle. +// pncc [in] Network component. +// +// Returns: None. +// +// Notes: +// + +VOID WriteBindingPath (FILE *fp, + INetCfgComponent *pncc) +{ + IEnumNetCfgBindingPath *pencbp; + INetCfgBindingPath *pncbp; + LPWSTR lpszName; + HRESULT hr; + + // + // Write the first component's name. + // + + hr = pncc->GetDisplayName( &lpszName ); + + if ( hr == S_OK ) { + fwprintf( fp, L"\n%s", lpszName ); + } + else { + ErrMsg( hr, + L"Unable to get the display name of a component, " + L" some binding paths will not be written." ); + + return; + } + + // + // Get binding path enumerator. + // + + hr = HrGetBindingPathEnum( pncc, + EBP_BELOW, + &pencbp ); + if ( hr == S_OK ) { + + hr = HrGetFirstBindingPath( pencbp, + &pncbp ); + + while( hr == S_OK ) { + + // + // Write interfaces of the binding path. + // + + WriteInterfaces( fp, + pncbp ); + + ReleaseRef( pncbp ); + + hr = HrGetNextBindingPath( pencbp, + &pncbp ); + if ( hr == S_OK ) { + fwprintf( fp, L"\n%s", lpszName ); + } + } + + ReleaseRef( pencbp ); + } + else { + ErrMsg( hr, + L"Couldn't get the binding path enumerator of %s. " + L"Its binding paths will not be written.", + lpszName ); + } + + CoTaskMemFree( lpszName ); + return; +} + +// +// Function: WriteInterfaces +// +// Purpose: Write bindings to specified file. +// +// Arguments: +// fp [in] File handle. +// pncbp [in] Binding path. +// +// Returns: None. +// +// Notes: +// + +VOID WriteInterfaces (FILE *fp, + INetCfgBindingPath *pncbp) +{ + IEnumNetCfgBindingInterface *pencbi; + INetCfgBindingInterface *pncbi; + INetCfgComponent *pnccLower; + LPWSTR lpszName; + HRESULT hr; + + hr = HrGetBindingInterfaceEnum( pncbp, + &pencbi ); + + if ( hr == S_OK ) { + + hr = HrGetFirstBindingInterface( pencbi, + &pncbi ); + + // + // Write lower component of each interface. + // + + while( hr == S_OK ) { + + hr = pncbi->GetLowerComponent ( &pnccLower ); + + if ( hr == S_OK ) { + + hr = pnccLower->GetDisplayName( &lpszName ); + if ( hr == S_OK ) { + fwprintf( fp, L"-->%s", lpszName ); + CoTaskMemFree( lpszName ); + } + } + + ReleaseRef( pnccLower ); + ReleaseRef( pncbi ); + + hr = HrGetNextBindingInterface( pencbi, + &pncbi ); + } + + ReleaseRef( pencbi ); + } + else { + ErrMsg( hr, + L"Couldn't get the binding interface enumerator." + L"The binding interfaces will not be shown." ); + } + + return; +} + +// +// Function: EnumNetBindings +// +// Purpose: Enumerate components and their bindings. +// +// Arguments: +// hwndTree [in] Tree handle. +// uiTypeSelected [in] Type of network component selected. +// +// Returns: TRUE on success. +// +// Notes: +// + +BOOL EnumNetBindings (HWND hwndTree, + UINT uiTypeSelected) +{ + INetCfg *pnc; + IEnumNetCfgComponent *pencc; + INetCfgComponent *pncc; + LPWSTR lpszApp; + HTREEITEM hTreeItem; + HRESULT hr; + + + hr = HrGetINetCfg( FALSE, + APP_NAME, + &pnc, + &lpszApp ); + + if ( hr == S_OK ) { + + // + // Get Component Enumerator Interface. + // + + hr = HrGetComponentEnum( pnc, + pguidNetClass[uiTypeSelected], + &pencc ); + if ( hr == S_OK ) { + + hr = HrGetFirstComponent( pencc, &pncc ); + + while( hr == S_OK ) { + + // + // Add the component's name to the tree. + // + + hTreeItem = AddToTree( hwndTree, + TVI_ROOT, + pncc ); + if ( hTreeItem ) { + + // + // Enumerate bindings. + // + + ListBindings( pncc, + hwndTree, + hTreeItem ); + } + + ReleaseRef( pncc ); + + hr = HrGetNextComponent( pencc, &pncc ); + } + + // + // S_FALSE merely indicates that there are no more components. + // + + if ( hr == S_FALSE ) { + hr = S_OK; + } + + ReleaseRef( pencc ); + } + else { + ErrMsg( hr, + L"Couldn't get the component enumerator interface." ); + } + + HrReleaseINetCfg( pnc, FALSE ); + } + else { + if ( (hr == NETCFG_E_NO_WRITE_LOCK) && lpszApp ) { + ErrMsg( hr, + L"%s currently holds the lock, try later.", + lpszApp ); + + CoTaskMemFree( lpszApp ); + } + else { + ErrMsg( hr, + L"Couldn't get the notify object interface." ); + } + } + + return hr == S_OK; +} + +// +// Function: ListBindings +// +// Purpose: Enumerate bindings of network components. +// +// Arguments: +// pncc [in] Network component. +// hwndTree [in] Tree handle. +// hTreeItemRoot [in] Parent item. +// +// Returns: None. +// +// Notes: +// + +VOID ListBindings (INetCfgComponent *pncc, + HWND hwndTree, + HTREEITEM hTreeItemRoot) +{ + IEnumNetCfgBindingPath *pencbp; + INetCfgBindingPath *pncbp; + HTREEITEM hTreeItem; + ULONG ulIndex; + HRESULT hr; + + hr = HrGetBindingPathEnum( pncc, + EBP_BELOW, + &pencbp ); + if ( hr == S_OK ) { + + hr = HrGetFirstBindingPath( pencbp, + &pncbp ); + + ulIndex = 1; + + while( hr == S_OK ) { + + // + // Add an item for the binding path. + // + + hTreeItem = AddBindNameToTree( pncbp, + hwndTree, + hTreeItemRoot, + ulIndex ); + + if ( hTreeItem ) { + + // + // Enumerate interfaces. + // + + ListInterfaces( pncbp, + hwndTree, + hTreeItem ); + } + + ReleaseRef( pncbp ); + + hr = HrGetNextBindingPath( pencbp, + &pncbp ); + + ulIndex++; + } + + ReleaseRef( pencbp ); + } + else { + LPWSTR lpszName; + + if ( pncc->GetDisplayName(&lpszName) == S_OK ) { + + ErrMsg( hr, + L"Couldn't get the binding path enumerator of %s. " + L"Its binding paths will not be shown.", + lpszName ); + + CoTaskMemFree( lpszName ); + } + else { + ErrMsg( hr, + L"Couldn't get the binding path enumerator of a " + L"network component. The binding paths will not " + L"be shown." ); + } + } + + return; +} + +// +// Function: ListInterfaces +// +// Purpose: Enumerate interfaces of a binding path. +// +// Arguments: +// pncbp [in] Binding path. +// hwndTree [in] Tree handle. +// hTreeItemRoot [in] Parent item. +// +// Returns: None. +// +// Notes: +// + +VOID ListInterfaces (INetCfgBindingPath *pncbp, + HWND hwndTree, + HTREEITEM hTreeItemRoot) +{ + IEnumNetCfgBindingInterface *pencbi; + INetCfgBindingInterface *pncbi; + INetCfgComponent *pnccBound; + HTREEITEM hTreeItem; + HRESULT hr; + + hr = HrGetBindingInterfaceEnum( pncbp, + &pencbi ); + + if ( hr == S_OK ) { + + hr = HrGetFirstBindingInterface( pencbi, + &pncbi ); + hTreeItem = hTreeItemRoot; + + while( (hr == S_OK) && hTreeItem ) { + + // + // Add lower component of every interface to the tree. + // + + pncbi->GetLowerComponent( &pnccBound ); + + hTreeItem = AddToTree( hwndTree, + hTreeItem, + pnccBound ); + + ReleaseRef( pnccBound ); + ReleaseRef( pncbi ); + + hr = HrGetNextBindingInterface( pencbi, + &pncbi ); + } + + // + // If hr is S_OK then, the loop terminated due to error in adding + // the binding path to the tree and pncbi has a reference to an + // interface. + // + + if ( hr == S_OK ) { + + ReleaseRef( pncbi ); + } + + ReleaseRef( pencbi ); + } + else { + ErrMsg( hr, + L"Couldn't get the binding interface enumerator." + L"The binding interfaces will not be shown." ); + } + + return; +} + +// +// Function: HandleBindingPathOperation +// +// Purpose: +// +// Arguments: +// hwndOwner [in] Owner window. +// ulSelection [in] Option selected. +// hItem [in] Item selected. +// lParam [in] lParam of the item. +// +// Returns: None. +// +// Notes: +// + +VOID HandleBindingPathOperation (HWND hwndOwner, + ULONG ulSelection, + HTREEITEM hItem, + LPARAM lParam) +{ + switch( ulSelection ) { + + case IDI_ENABLE: + case IDI_DISABLE: + + // + // Enable/disable binding path. + // + + EnableBindingPath( hwndOwner, + hItem, + (LPWSTR)lParam, + ulSelection == IDI_ENABLE ); + } + + return; +} + +// +// Function: EnableBindingPath +// +// Purpose: Enable/disable binding path. +// +// Arguments: +// hwndOwner [in] Owner window. +// hItem [in] Item handle of the binding path. +// lpszPathToken [in] Path token of the binding path. +// fEnable [in] if TRUE, enable, otherwise disable. +// +// Returns: None. +// +// Notes: +// + +VOID +EnableBindingPath ( + HWND hwndOwner, + HTREEITEM hItem, + _In_ LPWSTR lpszPathToken, + BOOL fEnable) +{ + INetCfg *pnc; + INetCfgBindingPath *pncbp; + LPWSTR lpszInfId; + LPWSTR lpszApp; + HRESULT hr; + + // + // Get PnpID of the owner component. + // + + lpszInfId = GetComponentId( hwndOwner, + hItem ); + + if ( lpszInfId ) { + + hr = HrGetINetCfg( TRUE, + APP_NAME, + &pnc, + &lpszApp ); + + if ( hr == S_OK ) { + + // + // Find the binding path reference. + // + + pncbp = FindBindingPath( pnc, + lpszInfId, + lpszPathToken ); + + if ( pncbp ) { + + // + // Enable/disable. + // + + hr = pncbp->Enable( fEnable ); + + if ( hr == S_OK ) { + hr = pnc->Apply(); + + if ( hr == S_OK ) { + + // + // Refreshe the state of the item representing the + // binding path. + // + + RefreshItemState( hwndOwner, + hItem, + fEnable ); + } + else { + ErrMsg( hr, + L"Failed to apply changes to the binding path." ); + } + } + else { + if ( fEnable ) { + ErrMsg( hr, + L"Failed to enable the binding path." ); + } + else { + ErrMsg( hr, + L"Failed to disable the binding path." ); + } + } + + ReleaseRef( pncbp ); + } + + HrReleaseINetCfg( pnc, + TRUE ); + } + else { + if ( (hr == NETCFG_E_NO_WRITE_LOCK) && lpszApp ) { + ErrMsg( hr, + L"%s currently holds the lock, try later.", + lpszApp ); + + CoTaskMemFree( lpszApp ); + } + else { + ErrMsg( hr, + L"Couldn't get the notify object interface." ); + } + } + } + else { + ErrMsg( HRESULT_FROM_WIN32(GetLastError()), + L"Couldn't determine the owner of the binding path." ); + } + + return; +} + +// +// Function: GetComponentId +// +// Purpose: Find the PnpID of a network component. +// +// Arguments: +// hwndTree [in] Tree handle. +// hItem [in] Item handle of the binding path. +// +// Returns: PnpID of the network component. +// +// Notes: +// + +LPWSTR GetComponentId (HWND hwndTree, + HTREEITEM hItem) +{ + LPWSTR lpszInfId; + HTREEITEM hTreeItemParent; + TVITEMW tvItem; + + lpszInfId = NULL; + + // + // Get the item handle of the owner component. + // + + hTreeItemParent = TreeView_GetParent( hwndTree, + hItem ); + if ( hTreeItemParent ) { + + // + // Get lParam of the owner component. lParam is the PnpID. + // + + ZeroMemory( &tvItem, + sizeof(TVITEMW) ); + + tvItem.hItem = hTreeItemParent; + tvItem.mask = TVIF_PARAM; + + if ( TreeView_GetItem(hwndTree, + &tvItem) ) { + + lpszInfId = (LPWSTR)tvItem.lParam; + } + } + + return lpszInfId; +} + +// +// Function: WriteBindings +// +// Purpose: Find the binding path with a give path token. +// +// Arguments: +// pnc [in] INetCfg reference. +// lpszInfId [in] PnpID of the network component. +// lpszPathTokenSelected [in] Path token of the binding path to search. +// +// Returns: Reference to the binding path on success, otherwise NULL. +// +// Notes: +// + +INetCfgBindingPath * +FindBindingPath ( + INetCfg *pnc, + _In_ LPWSTR lpszInfId, + _In_ LPWSTR lpszPathTokenSelected) +{ + INetCfgComponent *pncc = NULL; + IEnumNetCfgBindingPath *pencbp = NULL; + INetCfgBindingPath *pncbp = NULL; + LPWSTR lpszPathToken; + HRESULT hr; + BOOL fFound; + + + fFound = FALSE; + + // + // Get the component reference. + // + + hr = pnc->FindComponent( lpszInfId, + &pncc ); + + if ( hr == S_OK ) { + + hr = HrGetBindingPathEnum( pncc, + EBP_BELOW, + &pencbp ); + if ( hr == S_OK ) { + + hr = HrGetFirstBindingPath( pencbp, + &pncbp ); + + // Enumerate each binding path and find the one + // whose path token matches the specified one. + // + + while ( !fFound && (hr == S_OK) ) { + + hr = pncbp->GetPathToken( &lpszPathToken ); + + if ( hr == S_OK ) { + fFound = !wcscmp( lpszPathToken, + lpszPathTokenSelected ); + + CoTaskMemFree( lpszPathToken ); + } + + if ( !fFound ) { + ReleaseRef( pncbp ); + + hr = HrGetNextBindingPath( pencbp, + &pncbp ); + } + } + + ReleaseRef( pencbp ); + } + else { + ErrMsg( hr, + L"Couldn't get the binding path enumerator interface." ); + } + } + else { + ErrMsg( hr, + L"Couldn't get an interface pointer to %s.", + lpszInfId ); + } + + return (fFound) ? pncbp : NULL; +} diff --git a/network/config/bindview/BINDVIEW.CPP b/network/config/bindview/BINDVIEW.CPP new file mode 100644 index 00000000..4231f7c4 --- /dev/null +++ b/network/config/bindview/BINDVIEW.CPP @@ -0,0 +1,2336 @@ +//+--------------------------------------------------------------------------- +// +// Microsoft Windows +// Copyright (C) Microsoft Corporation, 2001. +// +// File: B I N D V I E W . C P P +// +// Contents: +// +// Notes: +// +// Author: Alok Sinha 15-Amy-01 +// +//---------------------------------------------------------------------------- + + +#include "BindView.h" + +//---------------------------------------------------------------------------- +// Globals +// + +// +// Image list for devices of various setup class. +// + +SP_CLASSIMAGELIST_DATA ClassImageListData; + +HINSTANCE hInstance; +HMENU hMainMenu; +HMENU hComponentSubMenu; +HMENU hBindingPathSubMenu; + +// +// Network components whose bindings are enumerated. +// + +LPWSTR lpszNetClass[] = { + L"All Clients", + L"All Services", + L"All Protocols" + }; + +// +// GUIDs of network components. +// + +const GUID *pguidNetClass [] = { + &GUID_DEVCLASS_NETCLIENT, + &GUID_DEVCLASS_NETSERVICE, + &GUID_DEVCLASS_NETTRANS, + &GUID_DEVCLASS_NET + }; + +// +// Program entry point. +// + +int APIENTRY +WinMain ( + _In_ HINSTANCE hInst, + _In_opt_ HINSTANCE hPrevInstance, + _In_ LPSTR lpCmdLine, + _In_ int nCmdShow ) +{ + UNREFERENCED_PARAMETER(hPrevInstance); + UNREFERENCED_PARAMETER(lpCmdLine); + UNREFERENCED_PARAMETER(nCmdShow); + + // + // Make sure common control DLL is loaded. + // + + hInstance = hInst; + + InitCommonControls(); + + if ( DialogBoxW(hInst, + MAKEINTRESOURCEW(IDD_MAIN), + NULL, + MainDlgProc) == -1 ) { + + ErrMsg( HRESULT_FROM_WIN32(GetLastError()), + L"Failed to create the main dialog box, exiting..." ); + } + + return 0; +} + +// +// WndProc for the main dialog box. +// + +INT_PTR CALLBACK MainDlgProc (HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) +{ + HWND hwndBindingTree; + HICON hIcon; + + switch (uMsg) { + + case WM_INITDIALOG: + + hIcon = LoadIcon( hInstance, + MAKEINTRESOURCE(IDI_BINDVIEW) ); + + if ( !hIcon ) { + ErrMsg( HRESULT_FROM_WIN32(GetLastError()), + L"Couldn't load the program icon, exiting..." ); + + return FALSE; + } + + SetClassLongPtr( hwndDlg, + GCLP_HICON, + (LONG_PTR)hIcon ); + + hMainMenu = LoadMenu( hInstance, + MAKEINTRESOURCE(IDM_OPTIONS) ); + + if ( !hMainMenu ) { + + ErrMsg( HRESULT_FROM_WIN32(GetLastError()), + L"Couldn't load the program menu, exiting..." ); + + return FALSE; + } + + hComponentSubMenu = GetSubMenu( hMainMenu, + 0 ); + + hBindingPathSubMenu = GetSubMenu( hMainMenu, + 1 ); + + if ( !hComponentSubMenu || !hBindingPathSubMenu ) { + + ErrMsg( HRESULT_FROM_WIN32(GetLastError()), + L"Couldn't load the program menu, exiting..." ); + + DestroyMenu( hMainMenu ); + return FALSE; + } + + // + // Add the network components types whose bindings are shown. + // + + UpdateComponentTypeList( GetDlgItem(hwndDlg, + IDL_COMPONENT_TYPES) ); + + // + // Load and associate the image list of all device classes with + // tree. + // + + hwndBindingTree = GetDlgItem( hwndDlg, + IDT_BINDINGS ); + + ZeroMemory( &ClassImageListData, sizeof(SP_CLASSIMAGELIST_DATA) ); + ClassImageListData.cbSize = sizeof(SP_CLASSIMAGELIST_DATA); + + if ( SetupDiGetClassImageList(&ClassImageListData) == TRUE ) { + + TreeView_SetImageList( hwndBindingTree, + ClassImageListData.ImageList, + LVSIL_NORMAL ); + } + else { + + // + // In case, we failed to load the image list, abort. + // + + ErrMsg( HRESULT_FROM_WIN32(GetLastError()), + L"Couldn't load the image list of " + L"device classes, exiting..." ); + + DestroyMenu( hMainMenu ); + return FALSE; + } + + // + // Enumerate the bindings of the network component selected by default. + // + + EnumNetBindings( hwndBindingTree, + DEFAULT_COMPONENT_SELECTED ); + + return TRUE; // Tell Windows to continue creating the dialog box. + + case WM_COMMAND: + + switch( LOWORD(wParam) ) { + + case IDL_COMPONENT_TYPES: + + if ( HIWORD(wParam) == CBN_SELCHANGE ) { + + // + // User has selected a new network component type. + // + + RefreshAll( hwndDlg ); + } + + break; + + case IDB_EXPAND_ALL: + case IDB_COLLAPSE_ALL: + + if ( HIWORD(wParam) == BN_CLICKED ) { + + HTREEITEM hItem; + // + // Expand/Collapse the entire tree. + // + + hwndBindingTree = GetDlgItem( hwndDlg, + IDT_BINDINGS ); + + hItem = TreeView_GetSelection( hwndBindingTree ); + + ExpandCollapseAll( hwndBindingTree, + TVI_ROOT, + (LOWORD(wParam) == IDB_EXPAND_ALL) ? + TVE_EXPAND : TVE_COLLAPSE ); + + TreeView_SelectSetFirstVisible( hwndBindingTree, + hItem ); + } + + break; + + case IDB_SAVE: + + if ( HIWORD(wParam) == BN_CLICKED ) { + + // + // Save the binding information to a file. + // + + WCHAR lpszFile[MAX_PATH+1]; + + if ( GetFileName(hwndDlg, + L"Text files (*.txt)\0*.txt\0", + L"Select a file name", + OFN_DONTADDTORECENT | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT, + lpszFile, + L"txt", + TRUE) ) { + + DumpBindings( lpszFile ); + } + } + + break; + + case IDB_INSTALL: + + if ( HIWORD(wParam) == BN_CLICKED ) { + + // + // Install a network component. + // + + if ( (BOOL)DialogBoxW(hInstance, + MAKEINTRESOURCEW(IDD_INSTALL), + hwndDlg, + InstallDlg) == TRUE ) { + + RefreshAll( hwndDlg ); + } + } + + break; + + case IDB_UNINSTALL: + + if ( HIWORD(wParam) == BN_CLICKED ) { + + // + // Uninstall a network component. + // + + if ( (BOOL)DialogBoxW(hInstance, + MAKEINTRESOURCEW(IDD_UNINSTALL), + hwndDlg, + UninstallDlg) == TRUE ) { + + RefreshAll( hwndDlg ); + } + } + } + + break; + + case WM_NOTIFY: + { + LPNMHDR lpnm; + + lpnm = (LPNMHDR)lParam; + + if ( (lpnm->idFrom == IDT_BINDINGS) && + (lpnm->code == NM_RCLICK) ) { + + // + // A network component or a binding path is selected + // with a right-click. + // + + ProcessRightClick( lpnm ); + + // + // Tell Windows that the right-click has been handled + // us. + // + + return TRUE; + } + } + break; + + case WM_SYSCOMMAND: + + if ( (0xFFF0 & wParam) == SC_CLOSE ) { + + // + // Before exiting, make sure to delete the image list + // and the buffers associated with each item in the tree. + // + + SetupDiDestroyClassImageList( &ClassImageListData ); + + ReleaseMemory( GetDlgItem(hwndDlg, IDT_BINDINGS), + TVI_ROOT ); + + DestroyMenu( hMainMenu ); + EndDialog( hwndDlg, 0 ); + } + } + + return FALSE; +} + +// +// WndProc of the dialog box for binding/unbinding components. +// + +INT_PTR CALLBACK BindComponentDlg (HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) +{ + LPBIND_UNBIND_INFO lpBindUnbind; + + switch (uMsg) { + + case WM_INITDIALOG: + { + DWORD dwCount; + + // + // Save the lParam which is an index to the selected network + // component. + // + + SetWindowLongPtr( hwndDlg, + DWLP_USER, + (LONG_PTR)lParam ); + + lpBindUnbind = (LPBIND_UNBIND_INFO)lParam; + + // + // fBindTo is TRUE when the user wants to bind the selected + // component to other components. So, we list the components + // that are not bound and can bind. + // + // + // fBindTo is FALSE when the user wants to unbind the selected + // component from other components. So, we list the components + // that are bound to it. + // + // + // ListCompToBindUnbind returns number of components added to + // the list. Keep track of it. If it zero then, we don't want to + // show this dialog box. + // + + dwCount = ListCompToBindUnbind( + lpBindUnbind->lpszInfId, + ADAPTERS_SELECTED, + GetDlgItem(hwndDlg, IDT_COMPONENT_LIST), + lpBindUnbind->fBindTo == FALSE ); + + dwCount += ListCompToBindUnbind( + lpBindUnbind->lpszInfId, + CLIENTS_SELECTED, + GetDlgItem(hwndDlg, IDT_COMPONENT_LIST), + lpBindUnbind->fBindTo == FALSE ); + + dwCount += ListCompToBindUnbind( + lpBindUnbind->lpszInfId, + SERVICES_SELECTED, + GetDlgItem(hwndDlg, IDT_COMPONENT_LIST), + lpBindUnbind->fBindTo == FALSE ); + + dwCount += ListCompToBindUnbind( + lpBindUnbind->lpszInfId, + PROTOCOLS_SELECTED, + GetDlgItem(hwndDlg, IDT_COMPONENT_LIST), + lpBindUnbind->fBindTo == FALSE ); + + if ( dwCount > 0 ) { + + // + // Since the same dialog box is used for unbind operation, + // we need to update the text on the button to reflect that + // it is a bind operation. + // + + if ( lpBindUnbind->fBindTo == FALSE ) { + + SetWindowTextW( hwndDlg, + L"Unbind From Network Components" ); + + SetWindowTextW( GetDlgItem(hwndDlg, IDB_BIND_UNBIND), + L"Unbind" ); + + SetWindowTextW( GetDlgItem(hwndDlg, IDG_COMPONENT_LIST), + L"Select components to unbind from" ); + } + } + else { + if ( lpBindUnbind->fBindTo == TRUE ) { + ErrMsg( 0, + L"There no network components that can " + L"bind to the selected component." ); + } + else { + ErrMsg( 0, + L"There no network components that are " + L"bound to the selected component." ); + } + + PostMessage( hwndDlg, WM_NO_COMPONENTS, 0, 0 ); + } + + return TRUE; + } + + case WM_NO_COMPONENTS: + EndDialog( hwndDlg, 0 ); + break; + + case WM_COMMAND: + + if ( (LOWORD(wParam) == IDB_CLOSE) && + (HIWORD(wParam) == BN_CLICKED) ) { + + // + // Before deleting the list in the tree, free the buffer + // associated with each item. The buffer holds the + // INF Id of network components. + // + + ReleaseMemory( GetDlgItem(hwndDlg, IDT_COMPONENT_LIST), + TVI_ROOT ); + + EndDialog( hwndDlg, 0 ); + } + else { + + // + // User wants to bind/unbind. + // + + if ( (LOWORD(wParam) == IDB_BIND_UNBIND) && + (HIWORD(wParam) == BN_CLICKED) ) { + + + + lpBindUnbind = (LPBIND_UNBIND_INFO)GetWindowLongPtr( hwndDlg, + DWLP_USER ); + + if ( BindUnbind(lpBindUnbind->lpszInfId, + GetDlgItem(hwndDlg, IDT_COMPONENT_LIST), + lpBindUnbind->fBindTo) ) { + + RefreshBindings( hwndDlg, + lpBindUnbind->lpszInfId ); + } + + ReleaseMemory( GetDlgItem(hwndDlg, IDT_COMPONENT_LIST), + TVI_ROOT ); + EndDialog( hwndDlg, 0 ); + } + } + break; + + case WM_SYSCOMMAND: + + if ( (0xFFF0 & wParam) == SC_CLOSE ) { + + // + // Before deleting the list in the tree, free the buffer + // associated with each item. The buffer holds the + // INF Id of network components. + // + + ReleaseMemory( GetDlgItem(hwndDlg, IDT_COMPONENT_LIST), + TVI_ROOT ); + + EndDialog( hwndDlg, 0 ); + } + } + + return FALSE; +} + +// +//WndProc of the dialog box for installing network components. +// + +INT_PTR CALLBACK InstallDlg (HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) +{ + switch (uMsg) { + + case WM_INITDIALOG: + { + HWND hwndTree; + + // + // List types of network components e.g. client, + // protocol and service. + // + + hwndTree = GetDlgItem( hwndDlg, + IDT_COMPONENT_LIST ); + + TreeView_SetImageList( hwndTree, + ClassImageListData.ImageList, + LVSIL_NORMAL ); + + // + // Insert and select client by default. + // + + TreeView_Select( hwndTree, + InsertItem(hwndTree, + CLIENTS_SELECTED), + TVGN_CARET ); + + InsertItem( hwndTree, + SERVICES_SELECTED ); + + InsertItem( hwndTree, + PROTOCOLS_SELECTED ); + + // + // Initialize it to FALSE. It will be set to TRUE when + // at least one component is installed. + // + + SetWindowLongPtr( hwndDlg, + DWLP_USER, + (LONG_PTR)FALSE ); + return TRUE; + } + + case WM_COMMAND: + + switch( LOWORD(wParam) ) { + + case IDB_INSTALL: + + // + // Install from Windows system directory. + // + + if ( HIWORD(wParam) == BN_CLICKED ) { + + InstallSelectedComponentType( hwndDlg, NULL ); + } + break; + + case IDB_BROWSE: + + // + // User wants to specify an INF file for the network + // to install. + // + if ( HIWORD(wParam) == BN_CLICKED ) { + + WCHAR lpszInfFile[MAX_PATH+1]; + + if ( GetFileName(hwndDlg, + L"INF files (*.inf)\0*.inf\0", + L"Select the INF file of the network component to install", + OFN_DONTADDTORECENT | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST, + lpszInfFile, + NULL, + FALSE) ) { + + InstallSelectedComponentType( hwndDlg, + lpszInfFile ); + } + } + break; + + case IDB_CLOSE: + + if ( HIWORD(wParam) == BN_CLICKED ) { + + // + // Return the value of DWLP_USER to indicate whether one or + // more components have been installed. Accordingly, the + // the list will be refreshed. + // + + EndDialog( hwndDlg, + GetWindowLongPtr(hwndDlg, DWLP_USER) ); + } + } + break; + + case WM_NOTIFY: + { + LPNMHDR lpnm; + + lpnm = (LPNMHDR)lParam; + + if ( (lpnm->idFrom == IDT_COMPONENT_LIST) && + (lpnm->code == NM_DBLCLK) ) { + + // + // On double-click, install from Windows system directory. + // + + InstallSelectedComponentType( hwndDlg, NULL ); + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); + return TRUE; + } + } + break; + + case WM_SYSCOMMAND: + + if ( (0xFFF0 & wParam) == SC_CLOSE ) { + + // + // Return the value of DWLP_USER to indicate whether one or + // more components have been installed. Accordingly, the + // the list will be refreshed. + // + + EndDialog( hwndDlg, + GetWindowLongPtr(hwndDlg, DWLP_USER) ); + } + } + + return FALSE; +} + +// +// WndProc of the dialog box for uninstalling a network component. +// + +INT_PTR CALLBACK UninstallDlg (HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) +{ + HWND hwndTree; + + switch (uMsg) { + + case WM_INITDIALOG: + + hwndTree = GetDlgItem( hwndDlg, + IDT_COMPONENT_LIST ); + TreeView_SetImageList( hwndTree, + ClassImageListData.ImageList, + LVSIL_NORMAL ); + + // + // List all the components currently installed. + // + + ListInstalledComponents( hwndTree, + &GUID_DEVCLASS_NETCLIENT); + ListInstalledComponents( hwndTree, + &GUID_DEVCLASS_NETSERVICE ); + ListInstalledComponents( hwndTree, + &GUID_DEVCLASS_NETTRANS ); + + // + // Initialize it to FALSE. It will be set to TRUE when + // at least one component is installed. + // + + SetWindowLongPtr( hwndDlg, + DWLP_USER, + (LONG_PTR)FALSE ); + return TRUE; + + case WM_COMMAND: + + switch( LOWORD(wParam) ) { + + case IDB_REMOVE: + + if ( HIWORD(wParam) == BN_CLICKED ) { + + // + // Uninstall the selected component. + // + + UninstallSelectedComponent( hwndDlg ); + + } + break; + + case IDB_CLOSE: + + if ( HIWORD(wParam) == BN_CLICKED ) { + + hwndTree = GetDlgItem( hwndDlg, + IDT_COMPONENT_LIST ); + ReleaseMemory( hwndTree, + TVI_ROOT ); + + // + // Return the value of DWLP_USER to indicate whether one or + // more components have been installed. Accordingly, the + // the list will be refreshed. + // + + EndDialog( hwndDlg, + GetWindowLongPtr(hwndDlg, DWLP_USER) ); + } + } + + break; + + case WM_NOTIFY: + { + LPNMHDR lpnm; + + lpnm = (LPNMHDR)lParam; + + if ( (lpnm->idFrom == IDT_COMPONENT_LIST) && + (lpnm->code == NM_DBLCLK) ) { + + UninstallSelectedComponent( hwndDlg ); + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); + return TRUE; + } + } + break; + + case WM_SYSCOMMAND: + + if ( (0xFFF0 & wParam) == SC_CLOSE ) { + + hwndTree = GetDlgItem( hwndDlg, + IDT_COMPONENT_LIST ); + ReleaseMemory( hwndTree, + TVI_ROOT ); + + // + // Return the value of DWLP_USER to indicate whether one or + // more components have been installed. Accordingly, the + // the list will be refreshed. + // + + EndDialog( hwndDlg, + GetWindowLongPtr(hwndDlg, DWLP_USER) ); + } + } + + return FALSE; +} + +//+--------------------------------------------------------------------------- +// +// Function: DumpBindings +// +// Purpose: Write the binding information. +// +// Arguments: +// lpszFile [in] Name of the file in which to write. +// +// Returns: None +// +// Notes: +// + +VOID +DumpBindings ( + _In_ LPWSTR lpszFile) +{ + FILE *fp; + errno_t err; + + err = _wfopen_s( &fp, + lpszFile, + L"w" ); + + if ( err != 0 || fp == NULL ) { + + ErrMsg( 0, + L"Unable to open %s.", + lpszFile ); + } + else { + WriteBindings( fp ); + + fclose( fp ); + } + + return; +} + +// +// Function: InstallSelectedComponentType +// +// Purpose: Install a network component. +// +// Arguments: +// hwndDlg [in] Handle to Install dialog box. +// lpszInfFile [in] Inf file of the network component. +// +// Returns: None +// +// Notes: +// If lpszInfFile is NULL, network components are installed from the +// system directory. +// + +VOID +InstallSelectedComponentType ( + HWND hwndDlg, + _In_opt_ LPWSTR lpszInfFile) +{ + HWND hwndTree = NULL; + HTREEITEM hItem = NULL; + LPARAM lParam; + HCURSOR hPrevCursor = NULL; + HCURSOR hWaitCursor = NULL; + HWND hwndFocus = NULL; + DWORD dwType; + BOOL fEnable; + HRESULT hr; + + hwndTree = GetDlgItem( hwndDlg, + IDT_COMPONENT_LIST ); + + // + // Find out the type of component selected. + // + + hItem = TreeView_GetSelection( hwndTree ); + + if ( hItem ) { + if ( GetItemInfo( hwndTree, + hItem, + &lParam, + &dwType, + &fEnable) ) { + + // + // Disable the install dialog controls. + // + + hwndFocus = GetFocus(); + + hWaitCursor = LoadCursor( NULL, + IDC_WAIT ); + if ( hWaitCursor ) { + hPrevCursor = SetCursor( hWaitCursor ); + } + + EnableWindow( hwndTree, FALSE ); + EnableWindow( GetDlgItem(hwndDlg,IDB_INSTALL), + FALSE ); + EnableWindow( GetDlgItem(hwndDlg,IDB_BROWSE), + FALSE ); + EnableWindow( GetDlgItem(hwndDlg,IDB_CLOSE), + FALSE ); + + if ( lpszInfFile ) { + + LPWSTR lpszPnpID; + + // + // Inf file name specified, install the network component + // from this file. + // + + hr = GetPnpID( lpszInfFile, &lpszPnpID ); + + if ( hr == S_OK ) { + + hr = InstallSpecifiedComponent( lpszInfFile, + lpszPnpID, + pguidNetClass[(UINT)lParam] ); + + CoTaskMemFree( lpszPnpID ); + } + else { + ErrMsg( hr, + L"Error reading the INF file %s.", + lpszInfFile ); + } + } + else { + + // + // Install from system directory. + // + + hr = InstallComponent( hwndTree, + pguidNetClass[(UINT)lParam] ); + } + + if ( hWaitCursor ) { + SetCursor( hPrevCursor ); + } + + switch( hr ) { + + case S_OK: + MessageBoxW( + hwndDlg, + L"Component installed successfully.", + L"Network Component Installation", + MB_OK | MB_ICONINFORMATION ); + SetWindowLongPtr( hwndDlg, + DWLP_USER, + (LONG_PTR)TRUE ); + break; + + case NETCFG_S_REBOOT: + MessageBoxW( + hwndDlg, + L"Component installed successfully: " + L"Reboot required.", + L"Network Component Installation", + MB_OK | MB_ICONINFORMATION ); + SetWindowLongPtr( hwndDlg, + DWLP_USER, + (LONG_PTR)TRUE ); + + } + + // + // Enable the install dialog controls. + // + + EnableWindow( hwndTree, TRUE ); + EnableWindow( GetDlgItem(hwndDlg,IDB_INSTALL), + TRUE ); + EnableWindow( GetDlgItem(hwndDlg,IDB_BROWSE), + TRUE ); + EnableWindow( GetDlgItem(hwndDlg,IDB_CLOSE), + TRUE ); + + SetFocus( hwndFocus ); + } + } + + return; +} + +// +// Function: GetPnpID +// +// Purpose: Retrieve PnpID from an inf file. +// +// Arguments: +// lpszInfFile [in] Inf file to search. +// lppszPnpID [out] PnpID found. +// +// Returns: TRUE on success. +// +// Notes: +// + +HRESULT +GetPnpID ( + _In_ LPWSTR lpszInfFile, + _Outptr_ LPWSTR *lppszPnpID) +{ + HINF hInf; + LPWSTR lpszModelSection; + HRESULT hr; + + *lppszPnpID = NULL; + + hInf = SetupOpenInfFileW( lpszInfFile, + NULL, + INF_STYLE_WIN4, + NULL ); + + if ( hInf == INVALID_HANDLE_VALUE ) + { + + return HRESULT_FROM_WIN32(GetLastError()); + } + + // + // Read the Model section name from Manufacturer section. + // + + hr = GetKeyValue( hInf, + L"Manufacturer", + NULL, + 1, + &lpszModelSection ); + + if ( SUCCEEDED(hr) ) + { + + // + // Read PnpID from the Model section. + // + + hr = GetKeyValue( hInf, + lpszModelSection, + NULL, + 2, + lppszPnpID ); + + CoTaskMemFree( lpszModelSection ); + } + + SetupCloseInfFile( hInf ); + + return hr; +} + +// +// Function: GetKeyValue +// +// Purpose: Retrieve the value of a key from the inf file. +// +// Arguments: +// hInf [in] Inf file handle. +// lpszSection [in] Section name. +// lpszKey [in] Key name. +// dwIndex [in] Key index. +// lppszValue [out] Key value. +// +// Returns: S_OK on success, otherwise and error code. +// +// Notes: +// + +HRESULT +GetKeyValue ( + HINF hInf, + _In_ LPCWSTR lpszSection, + _In_opt_ LPCWSTR lpszKey, + DWORD dwIndex, + _Outptr_ LPWSTR *lppszValue) +{ + INFCONTEXT infCtx; + __range(0, 512) DWORD dwSizeNeeded; + HRESULT hr; + + *lppszValue = NULL; + + if ( SetupFindFirstLineW(hInf, + lpszSection, + lpszKey, + &infCtx) == FALSE ) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + + if ( SetupGetStringFieldW(&infCtx, + dwIndex, + NULL, + 0, + &dwSizeNeeded) ) + { + *lppszValue = (LPWSTR)CoTaskMemAlloc( sizeof(WCHAR) * dwSizeNeeded ); + + if ( !*lppszValue ) + { + return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); + } + + if ( SetupGetStringFieldW(&infCtx, + dwIndex, + *lppszValue, + dwSizeNeeded, + NULL) == FALSE ) + { + + hr = HRESULT_FROM_WIN32(GetLastError()); + + CoTaskMemFree( *lppszValue ); + *lppszValue = NULL; + } + else + { + hr = S_OK; + } + } + else + { + DWORD dwErr = GetLastError(); + hr = HRESULT_FROM_WIN32(dwErr); + } + + return hr; +} + +// +// Function: UninstallSelectedComponent +// +// Purpose: Uninstall the selected network component. +// +// Arguments: +// hwndDlg [in] Window handle of the uninstall dialog box. +// +// Returns: TRUE on success. +// +// Notes: +// + +VOID UninstallSelectedComponent (HWND hwndDlg) +{ + HWND hwndTree = NULL; + HTREEITEM hItem = NULL; + LPARAM lParam; + HCURSOR hPrevCursor = NULL; + HCURSOR hWaitCursor = NULL; + DWORD dwType; + BOOL fEnable; + HRESULT hr; + + hwndTree = GetDlgItem( hwndDlg, + IDT_COMPONENT_LIST ); + + // + // Get the selected item to get its lParam which is the + // PnpID of the network component. + // + + hItem = TreeView_GetSelection( hwndTree ); + + if ( hItem ) { + if ( GetItemInfo( hwndTree, + hItem, + &lParam, + &dwType, + &fEnable) ) { + + hWaitCursor = LoadCursor( NULL, + IDC_WAIT ); + if ( hWaitCursor ) { + hPrevCursor = SetCursor( hWaitCursor ); + } + + EnableWindow( hwndTree, FALSE ); + EnableWindow( GetDlgItem(hwndDlg,IDB_REMOVE), + FALSE ); + EnableWindow( GetDlgItem(hwndDlg,IDB_CLOSE), + FALSE ); + + // + // Uninstall the selected component. + // + + hr = UninstallComponent( (LPWSTR)lParam ); + + + if ( hWaitCursor ) { + SetCursor( hPrevCursor ); + } + + switch( hr ) { + + case S_OK: + MessageBoxW( + hwndDlg, + L"Uninstallation successful.", + L"Network Component Uninstallation", + MB_OK | MB_ICONINFORMATION ); + + CoTaskMemFree( (LPVOID)lParam ); + TreeView_DeleteItem( hwndTree, + hItem ); + + SetWindowLongPtr( hwndDlg, + DWLP_USER, + (LONG_PTR)TRUE ); + break; + + case NETCFG_S_REBOOT: + MessageBoxW( + hwndDlg, + L"Uninstallation successful: " + L"Reboot required.", + L"Network Component Uninstallation", + MB_OK | MB_ICONINFORMATION ); + + CoTaskMemFree( (LPVOID)lParam ); + TreeView_DeleteItem( hwndTree, + hItem ); + + SetWindowLongPtr( hwndDlg, + DWLP_USER, + (LONG_PTR)TRUE ); + } + + EnableWindow( hwndTree, TRUE ); + EnableWindow( GetDlgItem(hwndDlg,IDB_REMOVE), + TRUE ); + EnableWindow( GetDlgItem(hwndDlg,IDB_CLOSE), + TRUE ); + } + } + + return; +} + +// +// Function: ExpandCollapseAll +// +// Purpose: Expand or collapse a tree. +// +// Arguments: +// hwndTree [in] Window handle of the tree. +// hTreeItem [in] Handle of root item. +// uiFlag [in] Flag indicating whether to expand or collapse. +// +// Returns: None. +// +// Notes: +// + +VOID ExpandCollapseAll (HWND hwndTree, + HTREEITEM hTreeItem, + UINT uiFlag) +{ + HTREEITEM hItemChild; + + hItemChild = TreeView_GetChild( hwndTree, + hTreeItem ); + + if ( hItemChild ) { + + // + // If the root has one or more children, expand/collapse the root. + // + + TreeView_Expand( hwndTree, + hTreeItem, + uiFlag ); + } + + while ( hItemChild ) { + + // + // Expand/collapse all the children. + // + + ExpandCollapseAll( hwndTree, + hItemChild, + uiFlag ); + + // + // Expand/collapse all the siblings. + // + + hItemChild = TreeView_GetNextSibling( hwndTree, + hItemChild ); + } + + return; +} + +// +// Function: GetFileName +// +// Purpose: Prompt for a filename. +// +// Arguments: +// hwndDlg [in] Window handle of the parent. +// lpszFilter [in] See documentation for GetOpenFileName. +// lpszTitle [in] See documentation for GetOpenFileName. +// dwFlags [in] See documentation for GetOpenFileName. +// lpszFile [out] See documentation for GetOpenFileName. +// Supplied buffer must be at least MAX_PATH+1 WCHARS +// +// Returns: See documentation for GetOpenFileName. +// +// Notes: +// + +BOOL +GetFileName ( + HWND hwndDlg, + _In_opt_ LPWSTR lpszFilter, + _In_ LPWSTR lpszTitle, + DWORD dwFlags, + _Out_writes_(MAX_PATH+1) LPWSTR lpszFile, + _In_opt_ LPWSTR lpszDefExt, + BOOL fSave) +{ + OPENFILENAMEW ofn; + + lpszFile[0] = NULL; + + ZeroMemory( &ofn, sizeof(OPENFILENAMEW) ); + ofn.lStructSize = sizeof(OPENFILENAMEW); + ofn.hwndOwner = hwndDlg; + ofn.lpstrFilter = lpszFilter; + ofn.lpstrFile = lpszFile; + ofn.lpstrDefExt = lpszDefExt; + ofn.nMaxFile = MAX_PATH+1; + ofn.lpstrTitle = lpszTitle; + ofn.Flags = dwFlags; + + if ( fSave ) + { + return GetSaveFileName( &ofn ); + } + else + { + return GetOpenFileName( &ofn ); + } +} + +// +// Function: ProcessRightClick +// +// Purpose: Handle righ mouse button click. +// +// Arguments: +// lpnm [in] LPNMHDR info +// +// Returns: None. +// +// Notes: +// + +VOID ProcessRightClick (LPNMHDR lpnm) +{ + HTREEITEM hItemSelected; + LPARAM lParam; + DWORD dwItemType; + BOOL fEnabled; + + // + // Determine the item on which user clicked the right mouse button. + // + + hItemSelected = TreeView_GetDropHilight( lpnm->hwndFrom ); + + if ( !hItemSelected ) { + hItemSelected = TreeView_GetSelection( lpnm->hwndFrom ); + } + else { + + // + // User has right-clicked an unselected item, make that a selected + // item. + // + + TreeView_Select( lpnm->hwndFrom, + hItemSelected, + TVGN_CARET ); + } + + if ( hItemSelected ) { + + // + // Get the lParam of the selected node in the tree which points to inf id or + // pathtoken name depending on if the node represents a network component or + // a binding path. + // + + if ( GetItemInfo(lpnm->hwndFrom, + hItemSelected, + &lParam, + &dwItemType, + &fEnabled) ) { + + if ( dwItemType & ITEM_NET_COMPONENTS ) { + + // + // Show the shortcut menu of operations for a network component. + // + + ShowComponentMenu( lpnm->hwndFrom, + hItemSelected, + lParam); + } + else { + if ( dwItemType & ITEM_NET_BINDINGS ) { + + // + // Show the shortcut menu of operations for a binding path. + // + + ShowBindingPathMenu( lpnm->hwndFrom, + hItemSelected, + lParam, + fEnabled ); + } + } + } + } + + return; +} + +// +// Function: ShowComponentMenu +// +// Purpose: Show shortcut menu of options for a network component. +// +// Arguments: +// hwndOwner [in] Owner window. +// hItem [in] Selected item representing a network component. +// lParam [in] PnpID of the network component. +// +// Returns: None. +// +// Notes: +// + +VOID ShowComponentMenu (HWND hwndOwner, + HTREEITEM hItem, + LPARAM lParam) +{ + ULONG ulSelection; + POINT pt; + + GetCursorPos( &pt ); + ulSelection = (ULONG)TrackPopupMenu( hComponentSubMenu, + TPM_RIGHTALIGN | TPM_BOTTOMALIGN | + TPM_NONOTIFY | TPM_RETURNCMD | + TPM_RIGHTBUTTON, + pt.x, + pt.y, + 0, + hwndOwner, + NULL ); + + if ( ulSelection ) { + + // + // Do the selected action. + // + + HandleComponentOperation( hwndOwner, + ulSelection, + hItem, + lParam ); + } + + return; +} + +// +// Function: ShowBindingPathMenu +// +// Purpose: Show shortcut menu of options for a network component. +// +// Arguments: +// hwndOwner [in] Owner window. +// hItem [in] Selected item representing a binding path. +// lParam [in] PnpID of the network component. +// fEnabled [in] TRUE when the path is enabled. +// +// Returns: None. +// +// Notes: +// + + +VOID ShowBindingPathMenu (HWND hwndOwner, + HTREEITEM hItem, + LPARAM lParam, + BOOL fEnabled) +{ + MENUITEMINFOW menuItemInfo; + ULONG ulSelection; + POINT pt; + + // + // Build the shortcut menu depending on whether path is + // disabled or enabled. + // + + ZeroMemory( &menuItemInfo, + sizeof(MENUITEMINFOW) ); + + menuItemInfo.cbSize = sizeof( MENUITEMINFOW ); + menuItemInfo.fMask = MIIM_TYPE | MIIM_ID; + menuItemInfo.fType = MFT_STRING; + menuItemInfo.fState = MFS_ENABLED; + + if ( fEnabled ) { + menuItemInfo.dwTypeData = MENUITEM_DISABLE; + menuItemInfo.wID = IDI_DISABLE; + } + else { + menuItemInfo.dwTypeData = MENUITEM_ENABLE; + menuItemInfo.wID = IDI_ENABLE; + } + + SetMenuItemInfoW( hBindingPathSubMenu, + 0, + TRUE, + &menuItemInfo ); + + GetCursorPos( &pt ); + ulSelection = (ULONG)TrackPopupMenu( hBindingPathSubMenu, + TPM_RIGHTALIGN | TPM_BOTTOMALIGN | + TPM_NONOTIFY | TPM_RETURNCMD | + TPM_RIGHTBUTTON, + pt.x, + pt.y, + 0, + hwndOwner, + NULL ); + + if ( ulSelection ) { + + // + // Do the selected action. + // + + HandleBindingPathOperation( hwndOwner, + ulSelection, + hItem, + lParam ); + } + + return; +} + +// +// Function: GetItemInfo +// +// Purpose: Returns information about an item. +// +// Arguments: +// hwndTree [in] Window handle of the tree. +// hItem [in] Item handle. +// lParam [out] lParam +// lpdwItemType [out] Type, binding path or network component. +// fEnabled [out] TRUE if the binding path or component is enabled. +// +// Returns: TRUE on sucess. +// +// Notes: +// + +BOOL GetItemInfo (HWND hwndTree, + HTREEITEM hItem, + LPARAM *lParam, + LPDWORD lpdwItemType, + BOOL *fEnabled) +{ + TVITEMW tvItem; + int iImage; + BOOL fSuccess; + + + fSuccess = FALSE; + + // + // Get item's information. + // + + ZeroMemory( &tvItem, + sizeof(TVITEMW) ); + tvItem.hItem = hItem; + tvItem.mask = TVIF_PARAM | TVIF_IMAGE | TVIF_STATE; + tvItem.stateMask = TVIS_OVERLAYMASK ; + + if ( TreeView_GetItem(hwndTree, + &tvItem) ) { + + *lParam = tvItem.lParam; + + if ( SetupDiGetClassImageIndex(&ClassImageListData, + &GUID_DEVCLASS_SYSTEM, + &iImage) ) { + + // + // Is it a binding path? + // + + if ( tvItem.iImage == iImage ) { + *lpdwItemType = ITEM_NET_BINDINGS; + + *fEnabled = !(TVIS_OVERLAYMASK & tvItem.state); + + fSuccess = TRUE; + } + else { + + // + // Item is a network component. + // + + if ( SetupDiGetClassImageIndex(&ClassImageListData, + &GUID_DEVCLASS_NET, + &iImage) ) { + + if ( tvItem.iImage == iImage ) { + *lpdwItemType = ITEM_NET_ADAPTERS; + } + else { + *lpdwItemType = ITEM_NET_COMPONENTS; + } + + *fEnabled = !(TVIS_OVERLAYMASK & tvItem.state); + + fSuccess = TRUE; + } + else { + ErrMsg( HRESULT_FROM_WIN32(GetLastError()), + L"Couldn't load the images of network adapters." ); + } + } + } + else { + ErrMsg( HRESULT_FROM_WIN32(GetLastError()), + L"Couldn't load the images of system devices." ); + } + } + + return fSuccess; +} + +// +// Function: AddBindNameToTree +// +// Purpose: Adds an item representing the binding path. +// +// Arguments: +// pncbp [in] Binding path to add. +// hwndTree [in] Tree handle. +// hParent [in] Parent item. +// ulIndex [in] Index of the binding path. +// +// Returns: Handle of the item added on success, otherwise NULL. +// +// Notes: +// + +HTREEITEM AddBindNameToTree (INetCfgBindingPath *pncbp, + HWND hwndTree, + HTREEITEM hParent, + ULONG ulIndex) +{ + WCHAR lpszBindName[40]; + LPWSTR lpszPathToken; + HTREEITEM hTreeItem; + TV_INSERTSTRUCTW tvInsertStruc; + HRESULT hr; + + hTreeItem = NULL; + + // + // Store the path token as lParam. + // + + hr = pncbp->GetPathToken( &lpszPathToken ); + + if ( hr == S_OK ) { + + StringCchPrintfW (lpszBindName, + celems(lpszBindName), + L"Binding Path %d", + ulIndex ); + + ZeroMemory( + &tvInsertStruc, + sizeof(TV_INSERTSTRUCTW) ); + + tvInsertStruc.hParent = hParent; + + tvInsertStruc.hInsertAfter = TVI_LAST; + + tvInsertStruc.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | + TVIF_SELECTEDIMAGE | TVIF_STATE; + + tvInsertStruc.item.pszText = lpszBindName; + + SetupDiGetClassImageIndex( &ClassImageListData, + &GUID_DEVCLASS_SYSTEM, + &tvInsertStruc.item.iImage ); + + tvInsertStruc.item.iSelectedImage = tvInsertStruc.item.iImage; + + tvInsertStruc.item.stateMask = TVIS_OVERLAYMASK; + + if ( pncbp->IsEnabled() == S_FALSE ) { + tvInsertStruc.item.state = INDEXTOOVERLAYMASK( + IDI_DISABLED_OVL - IDI_CLASSICON_OVERLAYFIRST + 1); + } + + tvInsertStruc.item.lParam = (LPARAM)lpszPathToken; + + hTreeItem = TreeView_InsertItem( hwndTree, + &tvInsertStruc ); + + if ( !hTreeItem ) { + ErrMsg( hr, + L"Couldn't add the binding path %d to the list." + L" The binding path will not be shown.", ulIndex ); + + CoTaskMemFree( lpszPathToken ); + } + } + else { + ErrMsg( hr, + L"Couldn't get the PathToken of the binding path %d." + L" The binding path will not be shown.", ulIndex ); + } + + return hTreeItem; +} + +// +// Function: AddToTree +// +// Purpose: Adds an item representing the network component. +// +// Arguments: +// hwndTree [in] Tree handle. +// hParent [in] Parent item. +// pncc [in] Network component. +// +// Returns: Handle of the item added on success, otherwise NULL. +// +// Notes: +// + +HTREEITEM AddToTree (HWND hwndTree, + HTREEITEM hParent, + INetCfgComponent *pncc) +{ + return AddToTreeEx( hwndTree, + hParent, + pncc, + FALSE ); +} + +// +// Function: AddToTree +// +// Purpose: Adds an item representing the network component. +// +// Arguments: +// hwndTree [in] Tree handle. +// hParent [in] Parent item. +// pncc [in] Network component. +// fUsePnpId [in] if TRUE, pnp device instance id is used to indentify the component, otherwise inf id. +// +// Returns: Handle of the item added on success, otherwise NULL. +// +// Notes: +// + +HTREEITEM AddToTreeEx (HWND hwndTree, + HTREEITEM hParent, + INetCfgComponent *pncc, + BOOL fUsePnpId) +{ + LPWSTR lpszItemName; + LPWSTR lpszId; + GUID guidClass; + BOOL fEnabled; + ULONG ulStatus; + HTREEITEM hTreeItem; + TV_INSERTSTRUCTW tvInsertStruc; + HRESULT hr; + + hTreeItem = NULL; + + hr = pncc->GetDisplayName( &lpszItemName ); + + if ( hr == S_OK ) { + + // + // Get the inf id or pnp instance id of the network component. We store it at lParam + // and use it later to retrieve its interface pointer. + // + + if ( fUsePnpId ) + { + hr = pncc->GetPnpDevNodeId( &lpszId ); + } + else + { + hr = pncc->GetId( &lpszId ); + } + + if ( hr == S_OK ) { + + // + // If it is a network adapter then, find out if it enabled/disabled. + // + + hr = pncc->GetClassGuid( &guidClass ); + + if ( hr == S_OK ) { + if ( IsEqualGUID(guidClass, GUID_DEVCLASS_NET) ) { + hr = pncc->GetDeviceStatus( &ulStatus ); + fEnabled = ulStatus == 0; + } + else { + fEnabled = TRUE; + } + } + else { + + // + // We can't get the status, so assume that it is disabled. + // + + fEnabled = FALSE; + } + + ZeroMemory( + &tvInsertStruc, + sizeof(TV_INSERTSTRUCTW) ); + + tvInsertStruc.hParent = hParent; + + tvInsertStruc.hInsertAfter = TVI_LAST; + + tvInsertStruc.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | + TVIF_SELECTEDIMAGE | TVIF_STATE; + + tvInsertStruc.item.pszText = lpszItemName; + + SetupDiGetClassImageIndex( &ClassImageListData, + &guidClass, + &tvInsertStruc.item.iImage ); + + tvInsertStruc.item.iSelectedImage = tvInsertStruc.item.iImage; + + tvInsertStruc.item.stateMask = TVIS_OVERLAYMASK; + + if ( fEnabled == FALSE ) { + tvInsertStruc.item.state = INDEXTOOVERLAYMASK( + IDI_DISABLED_OVL - IDI_CLASSICON_OVERLAYFIRST + 1); + } + + tvInsertStruc.item.lParam = (LPARAM)lpszId; + + hTreeItem = TreeView_InsertItem( hwndTree, + &tvInsertStruc ); + if ( !hTreeItem ) { + ErrMsg( hr, + L"Failed to add %s to the list.", + lpszItemName ); + + CoTaskMemFree( lpszId ); + } + } + else { + ErrMsg( hr, + L"Couldn't get the inf id of %s." + L" It will not be added to the list.", + lpszItemName ); + } + + CoTaskMemFree( lpszItemName ); + } + else { + ErrMsg( hr, + L"Couldn't get the display name of a network component." + L" It will not be added to the list." ); + } + + return hTreeItem; +} + +// +// Function: RefreshAll +// +// Purpose: Refreshes the main dialog box. +// +// Arguments: +// hwndDlg [in] Dialog box handle. +// +// Returns: None. +// +// Notes: +// + +VOID RefreshAll (HWND hwndDlg) +{ + HWND hwndTypeList; + INT iSelected; + + // + // Find the selected network component type. + // + + hwndTypeList = GetDlgItem( hwndDlg, + IDL_COMPONENT_TYPES ); + + iSelected = (int)SendMessage( hwndTypeList, + CB_GETCURSEL, + 0, + 0 ); + + if ( iSelected != CB_ERR ) { + + // + // Before deleting the list in the tree, free the buffer + // associated with each item. The buffer holds either the + // INF Id or the pathtoken depending on whether it is a + // network component or a binding path. + // + + ReleaseMemory( GetDlgItem(hwndDlg, IDT_BINDINGS), + TVI_ROOT ); + + TreeView_DeleteItem ( + GetDlgItem(hwndDlg, IDT_BINDINGS), + TVI_ROOT ); + + // + // Repopulate the tree with the selected network compnent + // type. + // + + EnumNetBindings( GetDlgItem(hwndDlg, IDT_BINDINGS), + (UINT)iSelected ); + + } + + return; +} + +// +// Function: RefreshItemState +// +// Purpose: Refreshes the specified item. +// +// Arguments: +// hwndTree [in] Dialog box handle. +// hItem [in] Item to refresh. +// fEnable [in] TRUE if component is enabled. +// +// Returns: None. +// +// Notes: +// + +VOID RefreshItemState (HWND hwndTree, + HTREEITEM hItem, + BOOL fEnable) +{ + TVITEMW tvItem; + + ZeroMemory( &tvItem, + sizeof(TVITEMW) ); + + tvItem.hItem = hItem; + tvItem.mask = TVIF_STATE; + tvItem.stateMask = TVIS_OVERLAYMASK; + + if ( fEnable ) + tvItem.state = INDEXTOOVERLAYMASK( 0 ); + else + tvItem.state = INDEXTOOVERLAYMASK( + IDI_DISABLED_OVL - IDI_CLASSICON_OVERLAYFIRST + 1); + TreeView_SetItem( hwndTree, + &tvItem ); + return; +} + +// +// Function: RefreshBindings +// +// Purpose: Refreshes bindings of a specific component. +// +// Arguments: +// hwndBindUnBindDlg [in] Dialog box handle. +// lpszInfId [in] PnpID of the component whose bindings changed. +// +// Returns: None. +// +// Notes: +// + +VOID +RefreshBindings ( + HWND hwndBindUnBindDlg, + _In_ LPWSTR lpszInfId) +{ + INetCfg *pnc; + INetCfgComponent *pncc; + HWND hwndParent; + HWND hwndTree; + HTREEITEM hItem; + HRESULT hr; + + + hwndParent = GetParent( hwndBindUnBindDlg ); + hwndTree = GetDlgItem( hwndParent, + IDT_BINDINGS ); + + hItem = TreeView_GetSelection( hwndTree ); + + hr = HrGetINetCfg( FALSE, + APP_NAME, + &pnc, + NULL ); + + if ( hr == S_OK ) { + + hr = pnc->FindComponent( lpszInfId, + &pncc ); + + if ( hr == S_OK ) { + + // + // Delete all the children. + // + + ReleaseMemory( hwndTree, + hItem ); + + DeleteChildren( hwndTree, + hItem ); + + ListBindings( pncc, + hwndTree, + hItem ); + + ReleaseRef( pncc ); + } + + HrReleaseINetCfg( pnc, + FALSE ); + } + + return; +} + +// +// Function: ReleaseMemory +// +// Purpose: Free memory associated with each item in the tree. +// +// Arguments: +// hwndTree [in] Tree handle. +// hTreeItem [in] Root item. +// +// Returns: None. +// +// Notes: +// +// Each node of the tree represents a network component or a binding path. +// At each node, lParam points to an allocated buffer wherein we store the +// inf id if it is a network component or pathtoken name if it is a binding +// path. +// +// + +VOID ReleaseMemory (HWND hwndTree, + HTREEITEM hTreeItem) +{ + HTREEITEM hItemChild; + TVITEMW tvItem; + + hItemChild = TreeView_GetChild( hwndTree, + hTreeItem ); + + while ( hItemChild ) { + + ZeroMemory( + &tvItem, + sizeof(TVITEMW) ); + + tvItem.hItem = hItemChild; + tvItem.mask = TVIF_PARAM; + + TreeView_GetItem( hwndTree, + &tvItem ); + + // + // It should never be NULL but just in case... + // + + if ( tvItem.lParam ) { + CoTaskMemFree( (LPVOID)tvItem.lParam ); + + } + + ReleaseMemory( hwndTree, hItemChild ); + + hItemChild = TreeView_GetNextSibling( hwndTree, + hItemChild ); + } + + return; +} + +// +// Function: DeleteChildren +// +// Purpose: Delete childen of a specific item. +// +// Arguments: +// hwndTree [in] Tree handle. +// hTreeItem [in] Parent item. +// +// Returns: None. +// +// Notes: +// + +VOID DeleteChildren (HWND hwndTree, + HTREEITEM hTreeItem) +{ + HTREEITEM hItemChild; + HTREEITEM hItemSibling; + + hItemChild = TreeView_GetChild( hwndTree, + hTreeItem ); + + while ( hItemChild ) { + + DeleteChildren( hwndTree, + hItemChild ); + + hItemSibling = TreeView_GetNextSibling( hwndTree, + hItemChild ); + TreeView_DeleteItem( hwndTree, + hItemChild ); + + hItemChild = hItemSibling; + } + + return; +} + +// +// Function: InsertItem +// +// Purpose: Insert text for each network component type. +// +// Arguments: +// hwndTree [in] Tree handle. +// uiType [in] Item type, protocol, client, service. +// +// Returns: Item handle on success, otherwise NULL. +// +// Notes: +// + +HTREEITEM InsertItem (HWND hwndTree, + UINT uiType) +{ + TV_INSERTSTRUCTW tvInsertStruc; + + ZeroMemory( + &tvInsertStruc, + sizeof(TV_INSERTSTRUCTW) ); + + tvInsertStruc.hParent = TVI_ROOT; + + tvInsertStruc.hInsertAfter = TVI_LAST; + + tvInsertStruc.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | + TVIF_SELECTEDIMAGE; + + + switch( uiType ) { + + case CLIENTS_SELECTED: + tvInsertStruc.item.pszText = L"Client"; + break; + + case SERVICES_SELECTED: + tvInsertStruc.item.pszText = L"Service"; + break; + + default: + tvInsertStruc.item.pszText = L"Protocol"; + break; + } + + SetupDiGetClassImageIndex( &ClassImageListData, + pguidNetClass[uiType], + &tvInsertStruc.item.iImage ); + + tvInsertStruc.item.iSelectedImage = tvInsertStruc.item.iImage; + + tvInsertStruc.item.lParam = (LPARAM)uiType; + + return TreeView_InsertItem( hwndTree, + &tvInsertStruc ); + +} + +// +// Function: UpdateComponentTypeList +// +// Purpose: Insert text for each network component type. +// +// Arguments: +// hwndTypeList [in] ListView handle. +// +// Returns: TRUE on success. +// +// Notes: +// + +BOOL UpdateComponentTypeList (HWND hwndTypeList) +{ + UINT i; + + for (i=0; i < 3; ++i) { + SendMessage( hwndTypeList, + CB_ADDSTRING, + (WPARAM)0, + (LPARAM)lpszNetClass[i] ); + } + + SendMessage( hwndTypeList, + CB_SETCURSEL, + (WPARAM)DEFAULT_COMPONENT_SELECTED, + (LPARAM)0 ); + return TRUE; +} + +// +// Function: ErrMsg +// +// Purpose: Insert text for each network component type. +// +// Arguments: +// hr [in] Error code. +// +// Returns: None. +// +// Notes: +// + +VOID ErrMsg (HRESULT hr, + LPCWSTR lpFmt, + ...) +{ + + LPWSTR lpSysMsg = NULL; + WCHAR buf[400]; + size_t offset; + va_list vArgList; + + + if ( hr != 0 ) { + StringCchPrintfW ( buf, + celems(buf), + L"Error %#lx: ", + hr ); + } + else { + buf[0] = 0; + } + + offset = wcslen( buf ); + + va_start( vArgList, + lpFmt ); + StringCchVPrintfW ( buf+offset, + celems(buf) - offset, + lpFmt, + vArgList ); + + va_end( vArgList ); + + if ( hr != 0 ) { + FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + hr, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPWSTR)&lpSysMsg, + 0, + NULL ); + if ( lpSysMsg ) { + + offset = wcslen( buf ); + + StringCchPrintfW ( buf+offset, + celems(buf) - offset, + L"\n\nPossible cause:\n\n" ); + + offset = wcslen( buf ); + + StringCchCatW ( buf+offset, + celems(buf) - offset, + lpSysMsg ); + + LocalFree( (HLOCAL)lpSysMsg ); + } + + MessageBoxW( NULL, + buf, + L"Error", + MB_ICONERROR | MB_OK ); + } + else { + MessageBoxW( NULL, + buf, + L"BindView", + MB_ICONINFORMATION | MB_OK ); + } + + return; +} diff --git a/network/config/bindview/BINDVIEW.H b/network/config/bindview/BINDVIEW.H new file mode 100644 index 00000000..2753b753 --- /dev/null +++ b/network/config/bindview/BINDVIEW.H @@ -0,0 +1,250 @@ +//+--------------------------------------------------------------------------- +// +// Microsoft Windows +// Copyright (C) Microsoft Corporation, 2001. +// +// File: B I N D V I E W . H +// +// Contents: Function Prototypes +// +// Notes: +// +// Author: Alok Sinha 15-May-01 +// +//---------------------------------------------------------------------------- + +#ifndef _BINDVIEW_H_INCLUDED + +#define _BINDVIEW_H_INCLUDED + +#include <stdio.h> +#include <stdlib.h> +#include <windows.h> +#include <windowsx.h> +#include <wchar.h> +#include <commctrl.h> // For common controls, e.g. Tree +#include <commdlg.h> +#include <setupapi.h> +#include <devguid.h> + +#include "NetCfgAPI.h" +#include "resource.h" +#include <strsafe.h> + +__user_code; // Annotation to specify PreFast analysis mode + +#define celems(_x) (sizeof(_x) / sizeof(_x[0])) + +#define ID_STATUS 100 +#define APP_NAME L"BindView" + +#define CLIENTS_SELECTED 0 +#define SERVICES_SELECTED 1 +#define PROTOCOLS_SELECTED 2 +#define ADAPTERS_SELECTED 3 + +#define ITEM_NET_COMPONENTS 1 +#define ITEM_NET_BINDINGS 2 +#define ITEM_NET_ADAPTERS 4 + +#define DEFAULT_COMPONENT_SELECTED CLIENTS_SELECTED + +#define WM_NO_COMPONENTS WM_USER+1 + +#define MENUITEM_ENABLE L"Enable" +#define MENUITEM_DISABLE L"Disable" + +extern HINSTANCE hInstance; +extern const GUID *pguidNetClass []; +extern LPWSTR lpszNetClass []; + +typedef struct _BIND_UNBIND_INFO { + LPWSTR lpszInfId; + BOOL fBindTo; +} BIND_UNBIND_INFO, *LPBIND_UNBIND_INFO; + +// +// Functions defined in bindview.cpp +// + +INT_PTR CALLBACK MainDlgProc (HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam); + +INT_PTR CALLBACK BindComponentDlg (HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam); + +INT_PTR CALLBACK InstallDlg (HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam); + +INT_PTR CALLBACK UninstallDlg (HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam); + +VOID DumpBindings ( _In_ LPWSTR lpszFile); + +VOID InstallSelectedComponentType (HWND hwndDlg, + _In_opt_ LPWSTR lpszInfFile); + +HRESULT GetPnpID ( _In_ LPWSTR lpszInfFile, + _Outptr_ LPWSTR *lppszPnpID); + +HRESULT GetKeyValue (HINF hInf, + _In_ LPCWSTR lpszSection, + _In_opt_ LPCWSTR lpszKey, + DWORD dwIndex, + _Outptr_ LPWSTR *lppszValue); + +VOID UninstallSelectedComponent (HWND hwndDlg); + +VOID ExpandCollapseAll (HWND hwndTree, + HTREEITEM hTreeItem, + UINT uiFlag); + +BOOL GetFileName (HWND hwndDlg, + _In_opt_ LPWSTR lpszFilter, + _In_ LPWSTR lpszTitle, + DWORD dwFlags, + _Out_writes_(MAX_PATH+1) LPWSTR lpszFile, + _In_opt_ LPWSTR lpszDefExt, + BOOL fSave); + +VOID ProcessRightClick (LPNMHDR lpnm); + +VOID ShowComponentMenu (HWND hwndOwner, + HTREEITEM hItem, + LPARAM lParam); + +VOID ShowBindingPathMenu (HWND hwndOwner, + HTREEITEM hItem, + LPARAM lParam, + BOOL fEnabled); + +BOOL GetItemInfo (HWND hwndTree, + HTREEITEM hItem, + LPARAM *lParam, + LPDWORD lpdwItemType, + BOOL *fEnabled); + +HTREEITEM AddBindNameToTree (INetCfgBindingPath *pncbp, + HWND hwndTree, + HTREEITEM hParent, + ULONG ulIndex); + +HTREEITEM AddToTree (HWND hwndTree, + HTREEITEM hParent, + INetCfgComponent *pncc); + +HTREEITEM AddToTreeEx (HWND hwndTree, + HTREEITEM hParent, + INetCfgComponent *pncc, + BOOL fUsePnpId); + +VOID RefreshAll (HWND hwndDlg); + +VOID RefreshItemState (HWND hwndTree, + HTREEITEM hItem, + BOOL fEnable); + +VOID RefreshBindings (HWND hwndTree, + _In_ LPWSTR lpszInfId); + +VOID ReleaseMemory (HWND hwndTree, + HTREEITEM hTreeItem); + + +VOID DeleteChildren (HWND hwndTree, + HTREEITEM hTreeItem); + +HTREEITEM InsertItem (HWND hwndTree, + UINT uiType); + +BOOL UpdateComponentTypeList (HWND hwndTypeList); + + +VOID ErrMsg (HRESULT hr, + LPCWSTR lpFmt, + ...); + +// +// Functions defined in component.cpp +// + +VOID HandleComponentOperation (HWND hwndOwner, + ULONG ulSelection, + HTREEITEM hItem, + LPARAM lParam); + +VOID BindUnbindComponents( HWND hwndOwner, + HTREEITEM hItem, + _In_ LPWSTR lpszInfId, + BOOL fBindTo); + +HRESULT InstallComponent (HWND hwndDlg, + const GUID *pguidClass); + +HRESULT InstallSpecifiedComponent ( _In_ LPWSTR lpszInfFile, + _In_ LPWSTR lpszPnpID, + const GUID *pguidClass); + +DWORD ListCompToBindUnbind ( _In_ LPWSTR lpszInfId, + UINT uiType, + HWND hwndTree, + BOOL fBound); + +BOOL BindUnbind ( _In_ LPWSTR lpszInfId, + HWND hwndTree, + BOOL fBind); + +VOID ListInstalledComponents (HWND hwndTree, + const GUID *pguidClass); + +HRESULT UninstallComponent ( _In_ LPWSTR lpszInfId); + +// +// Functions defined in binding.cpp +// + +VOID WriteBindings (FILE *fp); + +VOID WriteBindingPath (FILE *fp, + INetCfgComponent *pncc); + +VOID WriteInterfaces (FILE *fp, + INetCfgBindingPath *pncbp); + +BOOL EnumNetBindings (HWND hwndTree, + UINT uiTypeSelected); + +VOID ListBindings (INetCfgComponent *pncc, + HWND hwndTree, + HTREEITEM hTreeItemRoot); + +VOID ListInterfaces (INetCfgBindingPath *pncbp, + HWND hwndTree, + HTREEITEM hTreeItemRoot); + +VOID HandleBindingPathOperation (HWND hwndOwner, + ULONG ulSelection, + HTREEITEM hItem, + LPARAM lParam); + +VOID EnableBindingPath (HWND hwndOwner, + HTREEITEM hItem, + _In_ LPWSTR lpszTokenPath, + BOOL fEnable); + +LPWSTR GetComponentId (HWND hwndTree, + HTREEITEM hItem); + +INetCfgBindingPath *FindBindingPath (INetCfg *pnc, + _In_ LPWSTR lpszInfId, + _In_ LPWSTR lpszPathTokenSelected); + +#endif diff --git a/network/config/bindview/BINDVIEW.ICO b/network/config/bindview/BINDVIEW.ICO Binary files differnew file mode 100644 index 00000000..47c1d817 --- /dev/null +++ b/network/config/bindview/BINDVIEW.ICO diff --git a/network/config/bindview/BindView.rc b/network/config/bindview/BindView.rc new file mode 100644 index 00000000..71d8f894 --- /dev/null +++ b/network/config/bindview/BindView.rc @@ -0,0 +1,194 @@ +//Microsoft Developer Studio generated resource script. +// + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#define APSTUDIO_HIDDEN_SYMBOLS +#include "windows.h" +#undef APSTUDIO_HIDDEN_SYMBOLS +#include "resource.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_MAIN DIALOGEX 0, 0, 400, 215 +STYLE DS_SETFOREGROUND | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | + WS_CAPTION | WS_SYSMENU +CAPTION "Network Bindings" +FONT 8, "MS Shell Dlg" +BEGIN + CONTROL "Tree1",IDT_BINDINGS,"SysTreeView32",TVS_HASBUTTONS | + TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS | + TVS_INFOTIP | WS_BORDER | WS_TABSTOP,7,28,385,148, + WS_EX_CLIENTEDGE + PUSHBUTTON "Install...",IDB_INSTALL,8,185,53,16 + PUSHBUTTON "Collapse All",IDB_COLLAPSE_ALL,265,185,53,16 + PUSHBUTTON "Expand All",IDB_EXPAND_ALL,177,185,53,16 + PUSHBUTTON "Uninstall...",IDB_UNINSTALL,91,185,53,16 + COMBOBOX IDL_COMPONENT_TYPES,109,7,146,61,CBS_DROPDOWNLIST | + CBS_DISABLENOSCROLL | WS_VSCROLL | WS_GROUP | WS_TABSTOP + CONTROL "Show Bindings For",IDS_COMPONENT,"Static", + SS_LEFTNOWORDWRAP | SS_CENTERIMAGE | WS_GROUP,43,11,60,8 + PUSHBUTTON "Save Bindings",IDB_SAVE,339,185,53,16 +END + +IDD_BIND_UNBIND DIALOG DISCARDABLE 0, 0, 269, 140 +STYLE DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Bind To Network Features" +FONT 8, "MS Shell Dlg" +BEGIN + CONTROL "Tree3",IDT_COMPONENT_LIST,"SysTreeView32", + TVS_CHECKBOXES | TVS_INFOTIP | TVS_FULLROWSELECT | + WS_BORDER | WS_GROUP | WS_TABSTOP,16,24,236,82 + DEFPUSHBUTTON "Bind",IDB_BIND_UNBIND,19,120,50,14 + DEFPUSHBUTTON "Close",IDB_CLOSE,201,119,50,14,WS_GROUP + GROUPBOX "Select features to bind to",IDG_COMPONENT_LIST,7,7, + 253,107,WS_GROUP +END + +IDD_INSTALL DIALOG DISCARDABLE 0, 0, 234, 95 +STYLE DS_MODALFRAME | DS_SETFOREGROUND | DS_CENTER | WS_POPUP | WS_VISIBLE | + WS_CAPTION | WS_SYSMENU +CAPTION "Select Network Feature Type" +FONT 8, "MS Shell Dlg" +BEGIN + CONTROL "Tree1",IDT_COMPONENT_LIST,"SysTreeView32", + TVS_SHOWSELALWAYS | TVS_FULLROWSELECT | TVS_NOSCROLL | + WS_BORDER | WS_GROUP | WS_TABSTOP,13,20,207,36 + DEFPUSHBUTTON "Install",IDB_INSTALL,17,73,50,14 + PUSHBUTTON "Browse...",IDB_BROWSE,92,73,50,14 + PUSHBUTTON "Close",IDB_CLOSE,173,72,50,14 + GROUPBOX "Select type of feature to install",IDG_COMPONENT_LIST, + 7,7,221,57 +END + +IDD_UNINSTALL DIALOG DISCARDABLE 0, 0, 258, 141 +STYLE DS_MODALFRAME | DS_SETFOREGROUND | DS_CENTER | WS_POPUP | WS_VISIBLE | + WS_CAPTION | WS_SYSMENU +CAPTION "Uninstall Network Feature" +FONT 8, "MS Shell Dlg" +BEGIN + CONTROL "Tree1",IDT_COMPONENT_LIST,"SysTreeView32", + TVS_SHOWSELALWAYS | TVS_FULLROWSELECT | WS_BORDER | + WS_GROUP | WS_TABSTOP,25,28,207,76 + DEFPUSHBUTTON "Remove",IDB_REMOVE,33,120,50,14 + PUSHBUTTON "Close",IDB_CLOSE,171,120,50,14 + GROUPBOX "Select feature to uninstall",IDG_COMPONENT_LIST,15,15, + 227,97 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Menu +// + +IDM_OPTIONS MENU DISCARDABLE +BEGIN + POPUP "Features" + BEGIN + MENUITEM "Bind To...", IDI_BIND_TO + MENUITEM "Unbind From...", IDI_UNBIND_FROM + MENUITEM SEPARATOR + MENUITEM "Cancel", IDI_CANCEL + END + POPUP "Bindings" + BEGIN + MENUITEM "Enable", IDI_ENABLE + MENUITEM SEPARATOR + MENUITEM "Cancel", IDI_CANCEL + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_BINDVIEW ICON DISCARDABLE "bindview.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resrc1.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" + "#include ""windows.h""\r\n" + "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" + "#include ""resource.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO DISCARDABLE +BEGIN + IDD_MAIN, DIALOG + BEGIN + RIGHTMARGIN, 392 + HORZGUIDE, 201 + END + + IDD_INSTALL, DIALOG + BEGIN + HORZGUIDE, 73 + END +END +#endif // APSTUDIO_INVOKED + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/network/config/bindview/Component.cpp b/network/config/bindview/Component.cpp new file mode 100644 index 00000000..3f42b56b --- /dev/null +++ b/network/config/bindview/Component.cpp @@ -0,0 +1,897 @@ +//+--------------------------------------------------------------------------- +// +// Microsoft Windows +// Copyright (C) Microsoft Corporation, 2001. +// +// File: C O M P O N E N T . C P P +// +// Contents: Functions to illustrate +// o How to enumerate network components. +// o How to install protocols, clients and services. +// o How to uninstall protocols, clients and services. +// o How to bind/unbind network components. +// +// Notes: +// +// Author: Alok Sinha 15-May-01 +// +//---------------------------------------------------------------------------- + +#include "bindview.h" + +// +// Function: HandleComponentOperation +// +// Purpose: Do component specific functions. +// +// Arguments: +// hwndOwner [in] Owner window. +// ulSelection [in] Option selected. +// hItem [in] Item selected. +// lParam [in] lParam of the item. +// +// Returns: None. +// +// Notes: +// + +VOID HandleComponentOperation (HWND hwndOwner, + ULONG ulSelection, + HTREEITEM hItem, + LPARAM lParam) +{ + switch( ulSelection ) { + + case IDI_BIND_TO: + case IDI_UNBIND_FROM: + + // + // Bind/unbind components. + // + + BindUnbindComponents( hwndOwner, + hItem, + (LPWSTR)lParam, + ulSelection == IDI_BIND_TO ); + } + + return; +} + +// +// Function: BindUnbindComponents +// +// Purpose: Bind/unbind a network component. +// +// Arguments: +// hwndOwner [in] Owner window. +// hItem [in] Item handle of the network component. +// lpszInfId [in] PnpID of the network component. +// fBindTo [in] if TRUE, bind, otherwise unbind. +// +// Returns: None. +// +// Notes: +// + +VOID BindUnbindComponents( HWND hwndOwner, + HTREEITEM hItem, + _In_ LPWSTR lpszInfId, + BOOL fBindTo) +{ + UNREFERENCED_PARAMETER(hItem); + + BIND_UNBIND_INFO BindUnbind; + + BindUnbind.lpszInfId = lpszInfId; + BindUnbind.fBindTo = fBindTo; + + DialogBoxParam( hInstance, + MAKEINTRESOURCE(IDD_BIND_UNBIND), + hwndOwner, + BindComponentDlg, + (LPARAM)&BindUnbind ); + + return; +} + +// +// Function: InstallComponent +// +// Purpose: Install a network component. +// +// Arguments: +// hwndDlg [in] Owner window. +// pguidClass [in] Class GUID of type of network component to install. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT InstallComponent (HWND hwndDlg, + const GUID *pguidClass) +{ + INetCfg *pnc; + INetCfgClass *pncClass; + INetCfgClassSetup *pncClassSetup; + INetCfgComponent *pnccItem; + LPWSTR lpszApp; + OBO_TOKEN obo; + HRESULT hr; + + // + // Get INetCfg reference. + // + + hr = HrGetINetCfg( TRUE, + APP_NAME, + &pnc, + &lpszApp ); + + if ( hr == S_OK ) { + + // + // Get network component's class reference. + // + + hr = pnc->QueryNetCfgClass( pguidClass, + IID_INetCfgClass, + (PVOID *)&pncClass ); + + if ( hr == S_OK ) { + + // + // Get Setup class reference. + // + + hr = pncClass->QueryInterface( IID_INetCfgClassSetup, + (LPVOID *)&pncClassSetup ); + + if ( hr == S_OK ) { + + ZeroMemory( &obo, + sizeof(OBO_TOKEN) ); + + obo.Type = OBO_USER; + + // + // Let the network class installer prompt the user to select + // a network component to install. + // + + hr = pncClassSetup->SelectAndInstall( hwndDlg, + &obo, + &pnccItem ); + + if ( (hr == S_OK) || (hr == NETCFG_S_REBOOT) ) { + + hr = pnc->Apply(); + + if ( (hr != S_OK) && (hr != NETCFG_S_REBOOT) ) { + + ErrMsg( hr, + L"Couldn't apply the changes after" + L" installing the network component." ); + } + + } + else { + if ( hr != HRESULT_FROM_WIN32(ERROR_CANCELLED) ) { + ErrMsg( hr, + L"Couldn't install the network component." ); + } + } + + ReleaseRef( pncClassSetup ); + } + else { + ErrMsg( hr, + L"Couldn't get an interface to setup class." ); + } + + ReleaseRef( pncClass ); + } + else { + ErrMsg( hr, + L"Couldn't get a pointer to class interface." ); + } + + HrReleaseINetCfg( pnc, + TRUE ); + } + else { + if ( (hr == NETCFG_E_NO_WRITE_LOCK) && lpszApp ) { + ErrMsg( hr, + L"%s currently holds the lock, try later.", + lpszApp ); + + CoTaskMemFree( lpszApp ); + } + else { + ErrMsg( hr, + L"Couldn't the get notify object interface." ); + } + } + + return hr; +} + +// +// Function: InstallSpecifiedComponent +// +// Purpose: Install a network component from an INF file. +// +// Arguments: +// lpszInfFile [in] INF file. +// lpszPnpID [in] PnpID of the network component to install. +// pguidClass [in] Class GUID of the network component. +// +// Returns: None. +// +// Notes: +// + +HRESULT InstallSpecifiedComponent ( _In_ LPWSTR lpszInfFile, + _In_ LPWSTR lpszPnpID, + const GUID *pguidClass) +{ + INetCfg *pnc; + LPWSTR lpszApp; + HRESULT hr; + + hr = HrGetINetCfg( TRUE, + APP_NAME, + &pnc, + &lpszApp ); + + if ( hr == S_OK ) { + + // + // Install the network component. + // + + hr = HrInstallNetComponent( pnc, + lpszPnpID, + pguidClass, + lpszInfFile ); + if ( (hr == S_OK) || (hr == NETCFG_S_REBOOT) ) { + + hr = pnc->Apply(); + } + else { + if ( hr != HRESULT_FROM_WIN32(ERROR_CANCELLED) ) { + ErrMsg( hr, + L"Couldn't install the network component." ); + } + } + + HrReleaseINetCfg( pnc, + TRUE ); + } + else { + if ( (hr == NETCFG_E_NO_WRITE_LOCK) && lpszApp ) { + ErrMsg( hr, + L"%s currently holds the lock, try later.", + lpszApp ); + + CoTaskMemFree( lpszApp ); + } + else { + ErrMsg( hr, + L"Couldn't the get notify object interface." ); + } + } + + return hr; +} + +// +// Function: ListCompToBindUnbind +// +// Purpose: List all the components that are bound or bindable. +// +// Arguments: +// lpszInfId [in] PnpID of the network component. +// uiType [in] Type of network component. +// hwndTree [in] Tree handle in which to list. +// fBound [in] if TRUE, list components that are bound. +// +// Returns: Number of components listed. +// +// Notes: +// + +DWORD ListCompToBindUnbind ( _In_ LPWSTR lpszInfId, + UINT uiType, + HWND hwndTree, + BOOL fBound) +{ + INetCfg *pnc; + INetCfgComponent *pncc; + IEnumNetCfgComponent *pencc; + INetCfgComponentBindings *pnccb; + INetCfgComponent *pnccToBindUnbind; + LPWSTR lpszApp; + DWORD dwCount; + HRESULT hr; + + + dwCount = 0; + hr = HrGetINetCfg( TRUE, + APP_NAME, + &pnc, + &lpszApp ); + + if ( hr == S_OK ) { + + // + // Get a reference to the network component selected. + // + + hr = pnc->FindComponent( lpszInfId, + &pncc ); + + if ( hr == S_OK ) { + + // + // Get Component Enumerator Interface. + // + + hr = HrGetComponentEnum( pnc, + pguidNetClass[uiType], + &pencc ); + if ( hr == S_OK ) { + + hr = pncc->QueryInterface( IID_INetCfgComponentBindings, + (PVOID *)&pnccb ); + if ( hr == S_OK ) { + + hr = HrGetFirstComponent( pencc, &pnccToBindUnbind ); + + while( hr == S_OK ) { + + hr = pnccb->IsBoundTo( pnccToBindUnbind ); + + // + // fBound = TRUE ==> Want to list components that are + // bound. + // + + if ( fBound ) { + + if ( hr == S_OK ) { + if ( IsEqualIID( *pguidNetClass[uiType], GUID_DEVCLASS_NET) ) + { + AddToTreeEx( hwndTree, + TVI_ROOT, + pnccToBindUnbind, + TRUE ); + } + else + { + AddToTreeEx( hwndTree, + TVI_ROOT, + pnccToBindUnbind, + FALSE ); + } + + dwCount++; + } + } + else { + + // + // fBound = FALSE ==> Want to list components that + // are not bound but are bindable. + // + + if ( hr == S_FALSE ) { + + hr = pnccb->IsBindableTo( pnccToBindUnbind ); + + if ( hr == S_OK ) { + + if ( IsEqualIID( *pguidNetClass[uiType], GUID_DEVCLASS_NET) ) + { + AddToTreeEx( hwndTree, + TVI_ROOT, + pnccToBindUnbind, + TRUE ); + } + else + { + AddToTreeEx( hwndTree, + TVI_ROOT, + pnccToBindUnbind, + FALSE ); + } + + dwCount++; + } + } + } + + ReleaseRef( pnccToBindUnbind ); + + hr = HrGetNextComponent( pencc, &pnccToBindUnbind ); + } + + ReleaseRef( pnccb ); + } + else { + ErrMsg( hr, + L"Couldn't get the component binding interface " + L"of %s.", + lpszInfId ); + } + + ReleaseRef( pencc ); + } + else { + ErrMsg( hr, + L"Couldn't get the network component enumerator " + L"interface." ); + } + + ReleaseRef( pncc ); + + } + else { + ErrMsg( hr, + L"Couldn't get an interface pointer to %s.", + lpszInfId ); + } + + HrReleaseINetCfg( pnc, + TRUE ); + } + else { + if ( (hr == NETCFG_E_NO_WRITE_LOCK) && lpszApp ) { + ErrMsg( hr, + L"%s currently holds the lock, try later.", + lpszApp ); + + CoTaskMemFree( lpszApp ); + } + else { + ErrMsg( hr, + L"Couldn't get the notify object interface." ); + } + } + + return dwCount; +} + +// +// Function: BindUnbind +// +// Purpose: Bind/unbind a network component. +// +// Arguments: +// lpszInfId [in] PnpID of the network component to bind/unbind. +// hwndTree [in] Tree handle. +// fBind [in] if TRUE, bind, otherwise unbind. +// +// Returns: TRUE on success. +// +// Notes: +// + +BOOL BindUnbind ( _In_ LPWSTR lpszInfId, + HWND hwndTree, + BOOL fBind) +{ + INetCfg *pnc; + INetCfgComponent *pncc; + INetCfgComponentBindings *pnccb; + INetCfgComponent *pnccToBindUnbind; + LPWSTR lpszApp; + HTREEITEM hTreeItem; + TVITEMW tvItem; + HRESULT hr; + BOOL fChange; + + + hr = HrGetINetCfg( TRUE, + APP_NAME, + &pnc, + &lpszApp ); + + fChange = FALSE; + + if ( hr == S_OK ) { + + // + // Get a reference to the network component. + // + + hr = pnc->FindComponent( lpszInfId, + &pncc ); + if ( hr == S_OK ) { + + // + // Get a reference to the component's binding. + // + + hr = pncc->QueryInterface( IID_INetCfgComponentBindings, + (PVOID *)&pnccb ); + if ( hr == S_OK ) { + + // + // Start with the root item. + // + + hTreeItem = TreeView_GetRoot( hwndTree ); + + // + // Bind/unbind the network component with every component + // that is checked. + // + + while ( hTreeItem ) { + + ZeroMemory( &tvItem, + sizeof(TVITEMW) ); + + tvItem.hItem = hTreeItem; + tvItem.mask = TVIF_PARAM | TVIF_STATE; + tvItem.stateMask = TVIS_STATEIMAGEMASK; + + if ( TreeView_GetItem(hwndTree, + &tvItem) ) { + + // + // Is the network component selected? + // + + if ( (tvItem.state >> 12) == 2 ) { + + // + // Get a reference to the selected component. + // + // For adapters, lParam is pnp instance id. So, FindComponent will fail. In that case, search + // for a network adapter matching the pnp instance id. This will ensure that we get to the right + // network adapter in case there are multiple identical adapters in the system. + + hr = pnc->FindComponent( (LPWSTR)tvItem.lParam, + &pnccToBindUnbind ); + if ( hr != S_OK ) + { + hr = HrFindNetComponentByPnpId( pnc, + (LPWSTR)tvItem.lParam, + &pnccToBindUnbind ); + } + + if ( hr == S_OK ) { + + if ( fBind ) { + + // + // Bind the component to the selected component. + // + + hr = pnccb->BindTo( pnccToBindUnbind ); + + if ( !fChange ) { + fChange = hr == S_OK; + } + + if ( hr != S_OK ) { + ErrMsg( hr, + L"%s couldn't be bound to %s.", + lpszInfId, (LPWSTR)tvItem.lParam ); + } + } + else { + // + // Unbind the component from the selected component. + // + + hr = pnccb->UnbindFrom( pnccToBindUnbind ); + + if ( !fChange ) { + fChange = hr == S_OK; + } + + if ( hr != S_OK ) { + ErrMsg( hr, + L"%s couldn't be unbound from %s.", + lpszInfId, (LPWSTR)tvItem.lParam ); + } + } + + ReleaseRef( pnccToBindUnbind ); + } + else { + ErrMsg( hr, + L"Couldn't get an interface pointer to %s. " + L"%s will not be bound to it.", + (LPWSTR)tvItem.lParam, + lpszInfId ); + } + } + } + + // + // Get the next item. + // + + hTreeItem = TreeView_GetNextSibling( hwndTree, + hTreeItem ); + } + + ReleaseRef( pnccb ); + } + else { + ErrMsg( hr, + L"Couldn't get a binding interface of %s.", + lpszInfId ); + } + + ReleaseRef( pncc ); + } + else { + ErrMsg( hr, + L"Couldn't get an interface pointer to %s.", + lpszInfId ); + } + + // + // If one or more network components have been bound/unbound, + // apply the changes. + // + + if ( fChange ) { + hr = pnc->Apply(); + + fChange = hr == S_OK; + } + + HrReleaseINetCfg( pnc, + TRUE ); + } + else { + if ( (hr == NETCFG_E_NO_WRITE_LOCK) && lpszApp ) { + ErrMsg( hr, + L"%s currently holds the lock, try later.", + lpszApp ); + + CoTaskMemFree( lpszApp ); + } + else { + ErrMsg( hr, + L"Couldn't get the notify object interface." ); + } + } + + return fChange; +} + +// +// Function: ListInstalledComponents +// +// Purpose: List installed network components of specific class. +// +// Arguments: +// hwndTree [in] Tree handle in which to list. +// pguidClass [in] Class GUID of the network component class. +// +// Returns: None. +// +// Notes: +// + +VOID ListInstalledComponents (HWND hwndTree, + const GUID *pguidClass) +{ + INetCfg *pnc; + IEnumNetCfgComponent *pencc; + INetCfgComponent *pncc; + LPWSTR lpszApp; + HRESULT hr; + + + hr = HrGetINetCfg( FALSE, + APP_NAME, + &pnc, + &lpszApp ); + + if ( hr == S_OK ) { + + // + // Get Component Enumerator Interface. + // + + hr = HrGetComponentEnum( pnc, + pguidClass, + &pencc ); + if ( hr == S_OK ) { + + hr = HrGetFirstComponent( pencc, &pncc ); + + while( hr == S_OK ) { + + // + // Add an item to the tree for the network component. + // + + AddToTree( hwndTree, + TVI_ROOT, + pncc ); + + ReleaseRef( pncc ); + + hr = HrGetNextComponent( pencc, &pncc ); + } + + ReleaseRef( pencc ); + } + else { + ErrMsg( hr, + L"Failed to get the network component enumerator." ); + } + + HrReleaseINetCfg( pnc, FALSE ); + } + else { + if ( (hr == NETCFG_E_NO_WRITE_LOCK) && lpszApp ) { + ErrMsg( hr, + L"%s currently holds the lock, try later.", + lpszApp ); + + CoTaskMemFree( lpszApp ); + } + else { + ErrMsg( hr, + L"Couldn't get the notify object interface." ); + } + } + + return; +} + +// +// Function: UninstallComponent +// +// Purpose: Uninstall a network component. +// +// Arguments: +// lpszInfId [in] PnpID of the network component to uninstall. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT UninstallComponent ( _In_ LPWSTR lpszInfId) +{ + INetCfg *pnc; + INetCfgComponent *pncc; + INetCfgClass *pncClass; + INetCfgClassSetup *pncClassSetup; + LPWSTR lpszApp; + GUID guidClass; + OBO_TOKEN obo; + HRESULT hr; + + hr = HrGetINetCfg( TRUE, + APP_NAME, + &pnc, + &lpszApp ); + + if ( hr == S_OK ) { + + // + // Get a reference to the network component to uninstall. + // + + hr = pnc->FindComponent( lpszInfId, + &pncc ); + + if ( hr == S_OK ) { + + // + // Get the class GUID. + // + + hr = pncc->GetClassGuid( &guidClass ); + + if ( hr == S_OK ) { + + // + // Get a reference to component's class. + // + + hr = pnc->QueryNetCfgClass( &guidClass, + IID_INetCfgClass, + (PVOID *)&pncClass ); + if ( hr == S_OK ) { + + // + // Get the setup interface. + // + + hr = pncClass->QueryInterface( IID_INetCfgClassSetup, + (LPVOID *)&pncClassSetup ); + + if ( hr == S_OK ) { + + // + // Uninstall the component. + // + + ZeroMemory( &obo, + sizeof(OBO_TOKEN) ); + + obo.Type = OBO_USER; + + hr = pncClassSetup->DeInstall( pncc, + &obo, + NULL ); + if ( (hr == S_OK) || (hr == NETCFG_S_REBOOT) ) { + + hr = pnc->Apply(); + + if ( (hr != S_OK) && (hr != NETCFG_S_REBOOT) ) { + ErrMsg( hr, + L"Couldn't apply the changes after" + L" uninstalling %s.", + lpszInfId ); + } + } + else { + ErrMsg( hr, + L"Failed to uninstall %s.", + lpszInfId ); + } + + ReleaseRef( pncClassSetup ); + } + else { + ErrMsg( hr, + L"Couldn't get an interface to setup class." ); + } + + ReleaseRef( pncClass ); + } + else { + ErrMsg( hr, + L"Couldn't get a pointer to class interface " + L"of %s.", + lpszInfId ); + } + } + else { + ErrMsg( hr, + L"Couldn't get the class guid of %s.", + lpszInfId ); + } + + ReleaseRef( pncc ); + } + else { + ErrMsg( hr, + L"Couldn't get an interface pointer to %s.", + lpszInfId ); + } + + HrReleaseINetCfg( pnc, + TRUE ); + } + else { + if ( (hr == NETCFG_E_NO_WRITE_LOCK) && lpszApp ) { + ErrMsg( hr, + L"%s currently holds the lock, try later.", + lpszApp ); + + CoTaskMemFree( lpszApp ); + } + else { + ErrMsg( hr, + L"Couldn't get the notify object interface." ); + } + } + + return hr; +} diff --git a/network/config/bindview/NetCfgAPI.cpp b/network/config/bindview/NetCfgAPI.cpp new file mode 100644 index 00000000..5080bb41 --- /dev/null +++ b/network/config/bindview/NetCfgAPI.cpp @@ -0,0 +1,878 @@ +//+--------------------------------------------------------------------------- +// +// Microsoft Windows +// Copyright (C) Microsoft Corporation, 2001. +// +// File: N E T C F G A P I . C P P +// +// Contents: Functions to illustrate INetCfg API +// +// Notes: +// +// Author: Alok Sinha 15-May-01 +// +//---------------------------------------------------------------------------- + +#include "NetCfgAPI.h" + +// +// Function: HrGetINetCfg +// +// Purpose: Get a reference to INetCfg. +// +// Arguments: +// fGetWriteLock [in] If TRUE, Write lock.requested. +// lpszAppName [in] Application name requesting the reference. +// ppnc [out] Reference to INetCfg. +// lpszLockedBy [in] Optional. Application who holds the write lock. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrGetINetCfg (IN BOOL fGetWriteLock, + IN LPCWSTR lpszAppName, + OUT INetCfg** ppnc, + _Outptr_opt_result_maybenull_ LPWSTR *lpszLockedBy) +{ + INetCfg *pnc = NULL; + INetCfgLock *pncLock = NULL; + HRESULT hr = S_OK; + + // + // Initialize the output parameters. + // + + *ppnc = NULL; + + if ( lpszLockedBy ) + { + *lpszLockedBy = NULL; + } + // + // Initialize COM + // + + hr = CoInitialize( NULL ); + + if ( hr == S_OK ) { + + // + // Create the object implementing INetCfg. + // + + hr = CoCreateInstance( CLSID_CNetCfg, + NULL, CLSCTX_INPROC_SERVER, + IID_INetCfg, + (void**)&pnc ); + if ( hr == S_OK ) { + + if ( fGetWriteLock ) { + + // + // Get the locking reference + // + + hr = pnc->QueryInterface( IID_INetCfgLock, + (LPVOID *)&pncLock ); + if ( hr == S_OK ) { + + // + // Attempt to lock the INetCfg for read/write + // + + hr = pncLock->AcquireWriteLock( LOCK_TIME_OUT, + lpszAppName, + lpszLockedBy); + if (hr == S_FALSE ) { + hr = NETCFG_E_NO_WRITE_LOCK; + } + } + } + + if ( hr == S_OK ) { + + // + // Initialize the INetCfg object. + // + + hr = pnc->Initialize( NULL ); + + if ( hr == S_OK ) { + *ppnc = pnc; + pnc->AddRef(); + } + else { + + // + // Initialize failed, if obtained lock, release it + // + + if ( pncLock ) { + pncLock->ReleaseWriteLock(); + } + } + } + + ReleaseRef( pncLock ); + ReleaseRef( pnc ); + } + + // + // In case of error, uninitialize COM. + // + + if ( hr != S_OK ) { + CoUninitialize(); + } + } + + return hr; +} + +// +// Function: HrReleaseINetCfg +// +// Purpose: Get a reference to INetCfg. +// +// Arguments: +// pnc [in] Reference to INetCfg to release. +// fHasWriteLock [in] If TRUE, reference was held with write lock. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrReleaseINetCfg (IN INetCfg* pnc, + IN BOOL fHasWriteLock) +{ + INetCfgLock *pncLock = NULL; + HRESULT hr = S_OK; + + // + // Uninitialize INetCfg + // + + hr = pnc->Uninitialize(); + + // + // If write lock is present, unlock it + // + + if ( hr == S_OK && fHasWriteLock ) { + + // + // Get the locking reference + // + + hr = pnc->QueryInterface( IID_INetCfgLock, + (LPVOID *)&pncLock); + if ( hr == S_OK ) { + hr = pncLock->ReleaseWriteLock(); + ReleaseRef( pncLock ); + } + } + + ReleaseRef( pnc ); + + // + // Uninitialize COM. + // + + CoUninitialize(); + + return hr; +} + +// +// Function: HrInstallNetComponent +// +// Purpose: Install a network component(protocols, clients and services) +// given its INF file. +// +// Arguments: +// pnc [in] Reference to INetCfg. +// lpszComponentId [in] PnpID of the network component. +// pguidClass [in] Class GUID of the network component. +// lpszInfFullPath [in] INF file to install from. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrInstallNetComponent (IN INetCfg *pnc, + IN LPCWSTR lpszComponentId, + IN const GUID *pguidClass, + IN LPCWSTR lpszInfFullPath) +{ + DWORD dwError; + HRESULT hr = S_OK; + WCHAR* Drive = NULL; + WCHAR* Dir = NULL; + WCHAR* DirWithDrive = NULL; + + do + { + // + // If full path to INF has been specified, the INF + // needs to be copied using Setup API to ensure that any other files + // that the primary INF copies will be correctly found by Setup API + // + + if ( lpszInfFullPath ) { + + // + // Allocate memory to hold the strings + // + Drive = (WCHAR*)CoTaskMemAlloc(_MAX_DRIVE * sizeof(WCHAR)); + if (NULL == Drive) + { + hr = E_OUTOFMEMORY; + break; + } + ZeroMemory(Drive, _MAX_DRIVE * sizeof(WCHAR)); + + Dir = (WCHAR*)CoTaskMemAlloc(_MAX_DIR * sizeof(WCHAR)); + if (NULL == Dir) + { + hr = E_OUTOFMEMORY; + break; + } + ZeroMemory(Dir, _MAX_DRIVE * sizeof(WCHAR)); + + DirWithDrive = (WCHAR*)CoTaskMemAlloc((_MAX_DRIVE + _MAX_DIR) * sizeof(WCHAR)); + if (NULL == DirWithDrive) + { + hr = E_OUTOFMEMORY; + break; + } + ZeroMemory(DirWithDrive, (_MAX_DRIVE + _MAX_DIR) * sizeof(WCHAR)); + + // + // Get the path where the INF file is. + // + + _wsplitpath_s ( lpszInfFullPath, + Drive, + _MAX_DRIVE, + Dir, + _MAX_DIR, + NULL, + 0, + NULL, + 0); + + StringCchCopyW ( DirWithDrive, + _MAX_DRIVE + _MAX_DIR, + Drive ); + StringCchCatW ( DirWithDrive, + _MAX_DRIVE + _MAX_DIR, + Dir ); + + // + // Copy the INF file and other files referenced in the INF file. + // + + if ( !SetupCopyOEMInfW(lpszInfFullPath, + DirWithDrive, // Other files are in the + // same dir. as primary INF + SPOST_PATH, // First param is path to INF + 0, // Default copy style + NULL, // Name of the INF after + // it's copied to %windir%\inf + 0, // Max buf. size for the above + NULL, // Required size if non-null + NULL) ) { // Optionally get the filename + // part of Inf name after it is copied. + dwError = GetLastError(); + + hr = HRESULT_FROM_WIN32( dwError ); + } + } + + if ( S_OK == hr ) { + + // + // Install the network component. + // + + hr = HrInstallComponent( pnc, + lpszComponentId, + pguidClass ); + if ( hr == S_OK ) { + + // + // On success, apply the changes + // + + hr = pnc->Apply(); + } + } + + #pragma warning(disable:4127) /* Conditional expression is constant */ + } while (false); + + if (Drive != NULL) + { + CoTaskMemFree(Drive); + Drive = NULL; + } + if (Dir != NULL) + { + CoTaskMemFree(Dir); + Dir = NULL; + } + if (DirWithDrive != NULL) + { + CoTaskMemFree(DirWithDrive); + DirWithDrive = NULL; + } + + return hr; +} + +// +// Function: HrInstallComponent +// +// Purpose: Install a network component(protocols, clients and services) +// given its INF file. +// Arguments: +// pnc [in] Reference to INetCfg. +// lpszComponentId [in] PnpID of the network component. +// pguidClass [in] Class GUID of the network component. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrInstallComponent(IN INetCfg* pnc, + IN LPCWSTR szComponentId, + IN const GUID* pguidClass) +{ + INetCfgClassSetup *pncClassSetup = NULL; + INetCfgComponent *pncc = NULL; + OBO_TOKEN OboToken; + HRESULT hr = S_OK; + + // + // OBO_TOKEN specifies on whose behalf this + // component is being installed. + // Set it to OBO_USER so that szComponentId will be installed + // on behalf of the user. + // + + ZeroMemory( &OboToken, + sizeof(OboToken) ); + OboToken.Type = OBO_USER; + + // + // Get component's setup class reference. + // + + hr = pnc->QueryNetCfgClass ( pguidClass, + IID_INetCfgClassSetup, + (void**)&pncClassSetup ); + if ( hr == S_OK ) { + + hr = pncClassSetup->Install( szComponentId, + &OboToken, + 0, + 0, // Upgrade from build number. + NULL, // Answerfile name + NULL, // Answerfile section name + &pncc ); // Reference after the component + if ( S_OK == hr ) { // is installed. + + // + // we don't need to use pncc (INetCfgComponent), release it + // + + ReleaseRef( pncc ); + } + + ReleaseRef( pncClassSetup ); + } + + return hr; +} + +// +// Function: HrUninstallNetComponent +// +// Purpose: Uninstall a network component(protocols, clients and services). +// +// Arguments: +// pnc [in] Reference to INetCfg. +// szComponentId [in] PnpID of the network component to uninstall. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrUninstallNetComponent(IN INetCfg* pnc, + IN LPCWSTR szComponentId) +{ + INetCfgComponent *pncc = NULL; + INetCfgClass *pncClass = NULL; + INetCfgClassSetup *pncClassSetup = NULL; + OBO_TOKEN OboToken; + GUID guidClass; + HRESULT hr = S_OK; + + // + // OBO_TOKEN specifies on whose behalf this + // component is being installed. + // Set it to OBO_USER so that szComponentId will be installed + // on behalf of the user. + // + + ZeroMemory( &OboToken, + sizeof(OboToken) ); + OboToken.Type = OBO_USER; + + // + // Get the component's reference. + // + + hr = pnc->FindComponent( szComponentId, + &pncc ); + + if (S_OK == hr) { + + // + // Get the component's class GUID. + // + + hr = pncc->GetClassGuid( &guidClass ); + + if ( hr == S_OK ) { + + // + // Get component's class reference. + // + + hr = pnc->QueryNetCfgClass( &guidClass, + IID_INetCfgClass, + (void**)&pncClass ); + if ( hr == S_OK ) { + + // + // Get Setup reference. + // + + hr = pncClass->QueryInterface( IID_INetCfgClassSetup, + (void**)&pncClassSetup ); + if ( hr == S_OK ) { + + hr = pncClassSetup->DeInstall( pncc, + &OboToken, + NULL); + if ( hr == S_OK ) { + + // + // Apply the changes + // + + hr = pnc->Apply(); + } + + ReleaseRef( pncClassSetup ); + } + + ReleaseRef( pncClass ); + } + } + + ReleaseRef( pncc ); + } + + return hr; +} + +// +// Function: HrGetComponentEnum +// +// Purpose: Get network component enumerator reference. +// +// Arguments: +// pnc [in] Reference to INetCfg. +// pguidClass [in] Class GUID of the network component. +// ppencc [out] Enumerator reference. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrGetComponentEnum (INetCfg* pnc, + IN const GUID* pguidClass, + OUT IEnumNetCfgComponent **ppencc) +{ + INetCfgClass *pncclass; + HRESULT hr; + + *ppencc = NULL; + + // + // Get the class reference. + // + + hr = pnc->QueryNetCfgClass( pguidClass, + IID_INetCfgClass, + (PVOID *)&pncclass ); + + if ( hr == S_OK ) { + + // + // Get the enumerator reference. + // + + hr = pncclass->EnumComponents( ppencc ); + + // + // We don't need the class reference any more. + // + + ReleaseRef( pncclass ); + } + + return hr; +} + +// +// Function: HrGetFirstComponent +// +// Purpose: Enumerates the first network component. +// +// Arguments: +// pencc [in] Component enumerator reference. +// ppncc [out] Network component reference. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrGetFirstComponent (IN IEnumNetCfgComponent* pencc, + OUT INetCfgComponent **ppncc) +{ + HRESULT hr; + ULONG ulCount; + + *ppncc = NULL; + + pencc->Reset(); + + hr = pencc->Next( 1, + ppncc, + &ulCount ); + return hr; +} + +// +// Function: HrGetNextComponent +// +// Purpose: Enumerate the next network component. +// +// Arguments: +// pencc [in] Component enumerator reference. +// ppncc [out] Network component reference. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: The function behaves just like HrGetFirstComponent if +// it is called right after HrGetComponentEnum. +// +// + +HRESULT HrGetNextComponent (IN IEnumNetCfgComponent* pencc, + OUT INetCfgComponent **ppncc) +{ + HRESULT hr; + ULONG ulCount; + + *ppncc = NULL; + + hr = pencc->Next( 1, + ppncc, + &ulCount ); + return hr; +} + +// +// Function: HrFindNetComponentByPnpId +// +// Purpose: Get network adapter identified by a particular pnp device instance id. +// +// Arguments: +// pncc [in] Network component reference. +// lpszPnpDevNodeId [in] pnp device instance id. +// ppncc [out] pointer to network adapter reference. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrFindNetComponentByPnpId (IN INetCfg *pnc, + IN _In_ LPWSTR lpszPnpDevNodeId, + OUT INetCfgComponent **ppncc) +{ + IEnumNetCfgComponent *pencc; + LPWSTR pszPnpId; + HRESULT hr; + BOOL fFound; + + hr = HrGetComponentEnum( pnc, + &GUID_DEVCLASS_NET, + &pencc ); + if ( hr == S_OK ) { + + hr = HrGetFirstComponent( pencc, ppncc ); + fFound = FALSE; + while( hr == S_OK ) { + hr = (*ppncc)->GetPnpDevNodeId( &pszPnpId ); + if ( hr == S_OK ) { + fFound = wcscmp( pszPnpId, lpszPnpDevNodeId ) == 0; + CoTaskMemFree( pszPnpId ); + if ( fFound ) { + break; + } + } + else { + hr = S_OK; + } + + ReleaseRef( *ppncc ); + hr = HrGetNextComponent( pencc, ppncc ); + } + + ReleaseRef( pencc ); + } + + return hr; +} + +// +// Function: HrGetBindingPathEnum +// +// Purpose: Get network component's binding path enumerator reference. +// +// Arguments: +// pncc [in] Network component reference. +// dwBindingType [in] EBP_ABOVE or EBP_BELOW. +// ppencbp [out] Enumerator reference. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrGetBindingPathEnum (IN INetCfgComponent *pncc, + IN DWORD dwBindingType, + OUT IEnumNetCfgBindingPath **ppencbp) +{ + INetCfgComponentBindings *pnccb = NULL; + HRESULT hr; + + *ppencbp = NULL; + + // + // Get component's binding. + // + + hr = pncc->QueryInterface( IID_INetCfgComponentBindings, + (PVOID *)&pnccb ); + + if ( hr == S_OK ) { + + // + // Get binding path enumerator reference. + // + + hr = pnccb->EnumBindingPaths( dwBindingType, + ppencbp ); + + ReleaseRef( pnccb ); + } + + return hr; +} + +// +// Function: HrGetFirstBindingPath +// +// Purpose: Enumerates the first binding path. +// +// Arguments: +// pencc [in] Binding path enumerator reference. +// ppncc [out] Binding path reference. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrGetFirstBindingPath (IN IEnumNetCfgBindingPath *pencbp, + OUT INetCfgBindingPath **ppncbp) +{ + ULONG ulCount; + HRESULT hr; + + *ppncbp = NULL; + + pencbp->Reset(); + + hr = pencbp->Next( 1, + ppncbp, + &ulCount ); + + return hr; +} + +// +// Function: HrGetNextBindingPath +// +// Purpose: Enumerate the next binding path. +// +// Arguments: +// pencbp [in] Binding path enumerator reference. +// ppncbp [out] Binding path reference. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: The function behaves just like HrGetFirstBindingPath if +// it is called right after HrGetBindingPathEnum. +// +// + +HRESULT HrGetNextBindingPath (IN IEnumNetCfgBindingPath *pencbp, + OUT INetCfgBindingPath **ppncbp) +{ + ULONG ulCount; + HRESULT hr; + + *ppncbp = NULL; + + hr = pencbp->Next( 1, + ppncbp, + &ulCount ); + + return hr; +} + +// +// Function: HrGetBindingInterfaceEnum +// +// Purpose: Get binding interface enumerator reference. +// +// Arguments: +// pncbp [in] Binding path reference. +// ppencbp [out] Enumerator reference. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrGetBindingInterfaceEnum (IN INetCfgBindingPath *pncbp, + OUT IEnumNetCfgBindingInterface **ppencbi) +{ + HRESULT hr; + + *ppencbi = NULL; + + hr = pncbp->EnumBindingInterfaces( ppencbi ); + + return hr; +} + +// +// Function: HrGetFirstBindingInterface +// +// Purpose: Enumerates the first binding interface. +// +// Arguments: +// pencbi [in] Binding interface enumerator reference. +// ppncbi [out] Binding interface reference. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: +// + +HRESULT HrGetFirstBindingInterface (IN IEnumNetCfgBindingInterface *pencbi, + OUT INetCfgBindingInterface **ppncbi) +{ + ULONG ulCount; + HRESULT hr; + + *ppncbi = NULL; + + pencbi->Reset(); + + hr = pencbi->Next( 1, + ppncbi, + &ulCount ); + + return hr; +} + +// +// Function: HrGetNextBindingInterface +// +// Purpose: Enumerate the next binding interface. +// +// Arguments: +// pencbi [in] Binding interface enumerator reference. +// ppncbi [out] Binding interface reference. +// +// Returns: S_OK on success, otherwise an error code. +// +// Notes: The function behaves just like HrGetFirstBindingInterface if +// it is called right after HrGetBindingInterfaceEnum. +// +// + +HRESULT HrGetNextBindingInterface (IN IEnumNetCfgBindingInterface *pencbi, + OUT INetCfgBindingInterface **ppncbi) +{ + ULONG ulCount; + HRESULT hr; + + *ppncbi = NULL; + + hr = pencbi->Next( 1, + ppncbi, + &ulCount ); + + return hr; +} + +// +// Function: ReleaseRef +// +// Purpose: Release reference. +// +// Arguments: +// punk [in] IUnknown reference to release. +// +// Returns: Reference count. +// +// Notes: +// + +VOID ReleaseRef (IN IUnknown* punk) +{ + if ( punk ) { + punk->Release(); + } + + return; +} + diff --git a/network/config/bindview/NetCfgAPI.h b/network/config/bindview/NetCfgAPI.h new file mode 100644 index 00000000..b4d6f552 --- /dev/null +++ b/network/config/bindview/NetCfgAPI.h @@ -0,0 +1,92 @@ +//+--------------------------------------------------------------------------- +// +// Microsoft Windows +// Copyright (C) Microsoft Corporation, 2001. +// +// File: N E T C F G A P I . H +// +// Contents: Functions Prototypes +// +// Notes: +// +// Author: Alok Sinha 15-May-01 +// +//---------------------------------------------------------------------------- + +#ifndef _NETCFGAPI_H_INCLUDED + +#define _NETCFGAPI_H_INCLUDED + + +#include <stdio.h> +#include <stdlib.h> +#include <windows.h> +#include <wchar.h> +#include <netcfgx.h> +#include <netcfgn.h> +#include <setupapi.h> +#include <devguid.h> +#include <objbase.h> +#include <strsafe.h> + +#define celems(_x) (sizeof(_x) / sizeof(_x[0])) + +#define LOCK_TIME_OUT 5000 + +HRESULT HrGetINetCfg (IN BOOL fGetWriteLock, + IN LPCWSTR lpszAppName, + OUT INetCfg** ppnc, + _Outptr_opt_result_maybenull_ LPWSTR *lpszLockedBy); + +HRESULT HrReleaseINetCfg (INetCfg* pnc, + BOOL fHasWriteLock); + +HRESULT HrInstallNetComponent (IN INetCfg *pnc, + IN LPCWSTR szComponentId, + IN const GUID *pguildClass, + IN LPCWSTR lpszInfFullPath); + +HRESULT HrInstallComponent(IN INetCfg* pnc, + IN LPCWSTR szComponentId, + IN const GUID* pguidClass); + +HRESULT HrUninstallNetComponent(IN INetCfg* pnc, + IN LPCWSTR szComponentId); + +HRESULT HrGetComponentEnum (INetCfg* pnc, + IN const GUID* pguidClass, + IEnumNetCfgComponent **ppencc); + +HRESULT HrGetFirstComponent (IEnumNetCfgComponent* pencc, + INetCfgComponent **ppncc); + +HRESULT HrGetNextComponent (IEnumNetCfgComponent* pencc, + INetCfgComponent **ppncc); + +HRESULT HrFindNetComponentByPnpId (IN INetCfg *pnc, + IN _In_ LPWSTR lpszPnpDevNodeId, + OUT INetCfgComponent **ppncc); + +HRESULT HrGetBindingPathEnum (INetCfgComponent *pncc, + DWORD dwBindingType, + IEnumNetCfgBindingPath **ppencbp); + +HRESULT HrGetFirstBindingPath (IEnumNetCfgBindingPath *pencbp, + INetCfgBindingPath **ppncbp); + +HRESULT HrGetNextBindingPath (IEnumNetCfgBindingPath *pencbp, + INetCfgBindingPath **ppncbp); + +HRESULT HrGetBindingInterfaceEnum (INetCfgBindingPath *pncbp, + IEnumNetCfgBindingInterface **ppencbi); + +HRESULT HrGetFirstBindingInterface (IEnumNetCfgBindingInterface *pencbi, + INetCfgBindingInterface **ppncbi); + +HRESULT HrGetNextBindingInterface (IEnumNetCfgBindingInterface *pencbi, + INetCfgBindingInterface **ppncbi); + +VOID ReleaseRef (IUnknown* punk); + +#endif + diff --git a/network/config/bindview/RESOURCE.H b/network/config/bindview/RESOURCE.H new file mode 100644 index 00000000..3fb76696 --- /dev/null +++ b/network/config/bindview/RESOURCE.H @@ -0,0 +1,43 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by BindView.rc +// +#define IDD_MAIN 101 +#define IDM_OPTIONS 101 +#define IDI_BINDVIEW 105 +#define IDD_BIND_UNBIND 106 +#define IDD_INSTALL 107 +#define IDD_UNINSTALL 108 +#define IDT_BINDINGS 1000 +#define IDB_INSTALL 1001 +#define IDB_UNINSTALL 1002 +#define IDS_COMPONENT 1003 +#define IDL_COMPONENT_TYPES 1004 +#define IDB_EXPAND_ALL 1005 +#define IDB_COLLAPSE_ALL 1006 +#define IDB_BROWSE 1007 +#define IDS_ENABLE 1012 +#define IDE_OWNER 1013 +#define IDE_DEPTH 1014 +#define IDB_BIND_UNBIND 1016 +#define IDG_COMPONENT_LIST 1018 +#define IDB_CLOSE 1021 +#define IDB_REMOVE 1022 +#define IDT_COMPONENT_LIST 1024 +#define IDB_SAVE 1025 +#define IDI_ENABLE 40001 +#define IDI_UNBIND_FROM 40004 +#define IDI_BIND_TO 40005 +#define IDI_CANCEL 40006 +#define IDI_DISABLE 40007 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 109 +#define _APS_NEXT_COMMAND_VALUE 40008 +#define _APS_NEXT_CONTROL_VALUE 1028 +#define _APS_NEXT_SYMED_VALUE 102 +#endif +#endif diff --git a/network/config/bindview/ReadMe.md b/network/config/bindview/ReadMe.md new file mode 100644 index 00000000..01e1cd8d --- /dev/null +++ b/network/config/bindview/ReadMe.md @@ -0,0 +1,7 @@ +Bindview Network Configuration Utility +====================================== + +The Bindview sample demonstrates how to use INetCfg APIs to enumerate, install, uninstall, bind and unbind network components. + +For more information on the INetCfg interface, see [Network Configuration Interfaces](http://msdn.microsoft.com/en-us/library/windows/hardware/ff559080). + diff --git a/network/config/bindview/bindview.htm b/network/config/bindview/bindview.htm new file mode 100644 index 00000000..c28f6190 --- /dev/null +++ b/network/config/bindview/bindview.htm @@ -0,0 +1,345 @@ +<html xmlns:o="urn:schemas-microsoft-com:office:office" +xmlns:w="urn:schemas-microsoft-com:office:word" +xmlns="http://www.w3.org/TR/REC-html40"> + +<head> +<meta http-equiv=Content-Type content="text/html; charset=windows-1252"> +<meta name=ProgId content=Word.Document> +<meta name=Generator content="Microsoft Word 11"> +<meta name=Originator content="Microsoft Word 11"> +<link rel=File-List href="bindview_files/filelist.xml"> +<title>BINDVIEW: Network Configuration/Installation Sample</title> +<!--[if gte mso 9]><xml> + <w:WordDocument> + <w:SpellingState>Clean</w:SpellingState> + <w:GrammarState>Clean</w:GrammarState> + <w:ValidateAgainstSchemas/> + <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> + <w:IgnoreMixedContent>false</w:IgnoreMixedContent> + <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> + <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> + </w:WordDocument> +</xml><![endif]--><!--[if gte mso 9]><xml> + <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> + </w:LatentStyles> +</xml><![endif]--> +<style> +<!-- + /* Font Definitions */ + @font-face + {font-family:Verdana; + panose-1:2 11 6 4 3 5 4 4 2 4; + mso-font-charset:0; + mso-generic-font-family:swiss; + mso-font-pitch:variable; + mso-font-signature:536871559 0 0 0 415 0;} +@font-face + {font-family:"MS Sans Serif"; + panose-1:0 0 0 0 0 0 0 0 0 0; + mso-font-alt:"Times New Roman"; + mso-font-charset:0; + mso-generic-font-family:roman; + mso-font-format:other; + mso-font-pitch:auto; + mso-font-signature:0 0 0 0 0 0;} + /* Style Definitions */ + p.MsoNormal, li.MsoNormal, div.MsoNormal + {mso-style-parent:""; + margin:0in; + margin-bottom:.0001pt; + mso-pagination:widow-orphan; + font-size:12.0pt; + font-family:"Times New Roman"; + mso-fareast-font-family:"Times New Roman";} +h1 + {mso-style-next:Normal; + margin:0in; + margin-bottom:.0001pt; + mso-pagination:widow-orphan; + page-break-after:avoid; + mso-outline-level:1; + font-size:10.0pt; + font-family:Verdana; + mso-font-kerning:0pt; + font-weight:bold;} +h2 + {mso-margin-top-alt:auto; + margin-right:0in; + mso-margin-bottom-alt:auto; + margin-left:0in; + mso-pagination:widow-orphan; + mso-outline-level:2; + font-size:18.0pt; + font-family:"Times New Roman"; + font-weight:bold;} +h3 + {mso-margin-top-alt:auto; + margin-right:0in; + mso-margin-bottom-alt:auto; + margin-left:0in; + mso-pagination:widow-orphan; + mso-outline-level:3; + font-size:13.5pt; + font-family:"Times New Roman"; + font-weight:bold;} +h4 + {mso-margin-top-alt:auto; + margin-right:0in; + mso-margin-bottom-alt:auto; + margin-left:0in; + mso-pagination:widow-orphan; + mso-outline-level:4; + font-size:12.0pt; + font-family:"Times New Roman"; + font-weight:bold;} +a:link, span.MsoHyperlink + {color:blue; + text-decoration:underline; + text-underline:single;} +a:visited, span.MsoHyperlinkFollowed + {color:blue; + text-decoration:underline; + text-underline:single;} +p + {mso-margin-top-alt:auto; + margin-right:0in; + mso-margin-bottom-alt:auto; + margin-left:0in; + mso-pagination:widow-orphan; + font-size:12.0pt; + font-family:"Times New Roman"; + mso-fareast-font-family:"Times New Roman";} +pre + {margin:0in; + margin-bottom:.0001pt; + mso-pagination:widow-orphan; + tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; + font-size:10.0pt; + font-family:"Courier New"; + mso-fareast-font-family:"Courier New";} +span.SpellE + {mso-style-name:""; + mso-spl-e:yes;} +span.GramE + {mso-style-name:""; + mso-gram-e:yes;} +@page Section1 + {size:8.5in 11.0in; + margin:1.0in 1.25in 1.0in 1.25in; + mso-header-margin:.5in; + mso-footer-margin:.5in; + mso-paper-source:0;} +div.Section1 + {page:Section1;} + /* List Definitions */ + @list l0 + {mso-list-id:149904795; + mso-list-type:hybrid; + mso-list-template-ids:2069783722 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} +@list l0:level1 + {mso-level-number-format:bullet; + mso-level-text:\F0B7; + mso-level-tab-stop:.5in; + mso-level-number-position:left; + text-indent:-.25in; + font-family:Symbol;} +@list l0:level2 + {mso-level-number-format:bullet; + mso-level-text:o; + mso-level-tab-stop:1.0in; + mso-level-number-position:left; + text-indent:-.25in; + font-family:"Courier New";} +@list l0:level3 + {mso-level-tab-stop:1.5in; + mso-level-number-position:left; + text-indent:-.25in;} +@list l0:level4 + {mso-level-tab-stop:2.0in; + mso-level-number-position:left; + text-indent:-.25in;} +@list l0:level5 + {mso-level-tab-stop:2.5in; + mso-level-number-position:left; + text-indent:-.25in;} +@list l0:level6 + {mso-level-tab-stop:3.0in; + mso-level-number-position:left; + text-indent:-.25in;} +@list l0:level7 + {mso-level-tab-stop:3.5in; + mso-level-number-position:left; + text-indent:-.25in;} +@list l0:level8 + {mso-level-tab-stop:4.0in; + mso-level-number-position:left; + text-indent:-.25in;} +@list l0:level9 + {mso-level-tab-stop:4.5in; + mso-level-number-position:left; + text-indent:-.25in;} +@list l1 + {mso-list-id:1493059929; + mso-list-template-ids:703913330;} +@list l1:level1 + {mso-level-number-format:bullet; + mso-level-text:\F0B7; + mso-level-tab-stop:.5in; + mso-level-number-position:left; + text-indent:-.25in; + mso-ansi-font-size:10.0pt; + font-family:Symbol;} +@list l1:level2 + {mso-level-number-format:bullet; + mso-level-text:o; + mso-level-tab-stop:1.0in; + mso-level-number-position:left; + text-indent:-.25in; + mso-ansi-font-size:10.0pt; + font-family:"Courier New"; + mso-bidi-font-family:"Times New Roman";} +ol + {margin-bottom:0in;} +ul + {margin-bottom:0in;} +--> +</style> +<!--[if gte mso 10]> +<style> + /* Style Definitions */ + table.MsoNormalTable + {mso-style-name:"Table Normal"; + mso-tstyle-rowband-size:0; + mso-tstyle-colband-size:0; + mso-style-noshow:yes; + mso-style-parent:""; + mso-padding-alt:0in 5.4pt 0in 5.4pt; + mso-para-margin:0in; + mso-para-margin-bottom:.0001pt; + mso-pagination:widow-orphan; + font-size:10.0pt; + font-family:"Times New Roman"; + mso-ansi-language:#0400; + mso-fareast-language:#0400; + mso-bidi-language:#0400;} +</style> +<![endif]--> +</head> + +<body lang=EN-US link=blue vlink=blue style='tab-interval:.5in'> + +<div class=Section1> + +<h2><a name="_top"></a><span style='font-family:Verdana'>BINDVIEW: Network +Configuration/Installation Sample<o:p></o:p></span></h2> + +<h3><span style='font-family:Verdana'>SUMMARY<o:p></o:p></span></h3> + +<p><span style='font-size:10.0pt;font-family:Verdana'>This sample demonstrates +how to use <span class=SpellE>INetCfg</span> APIs to enumerate, install, +uninstall, bind and unbind network components.<o:p></o:p></span></p> + +<p><span style='font-size:10.0pt;font-family:Verdana'>The sample compiles +properly for 64-bit systems and builds properly with Microsoft� Visual C� 6.0. <o:p></o:p></span></p> + +<h3><span style='font-family:Verdana'>BUILDING THE SAMPLE<o:p></o:p></span></h3> + +<p><span style='font-size:10.0pt;font-family:Verdana'>To build the sample, <span +class=GramE>type <b>build</b></span>. This command produces the binary +bindview.exe.<o:p></o:p></span></p> + +<h3><span style='font-family:Verdana'>INSTALLING THE SAMPLE<o:p></o:p></span></h3> + +<p class=MsoNormal><span style='font-size:10.0pt;font-family:Verdana'>Copy the +binary bindview.exe to the directory from which you want to run the sample. <o:p></o:p></span></p> + +<h3><span style='font-family:Verdana'>RUNNING THE SAMPLE<o:p></o:p></span></h3> + +<p class=MsoNormal><span class=GramE><span style='font-size:10.0pt;font-family: +Verdana'>Type bindview.exe at the command prompt to run the program.</span></span><span +style='font-size:10.0pt;font-family:Verdana'> You can perform the following +operations.<o:p></o:p></span></p> + +<p class=MsoNormal><span style='font-size:10.0pt;font-family:Verdana'><o:p> </o:p></span></p> + +<ul style='margin-top:0in' type=disc> + <li class=MsoNormal style='mso-list:l0 level1 lfo3;tab-stops:list .5in'><span + style='font-size:10.0pt;font-family:Verdana'>Install a network protocol, + service or client component.<o:p></o:p></span></li> + <li class=MsoNormal style='mso-list:l0 level1 lfo3;tab-stops:list .5in'><span + style='font-size:10.0pt;font-family:Verdana'>Uninstall a network protocol, + service or client component.<o:p></o:p></span></li> + <li class=MsoNormal style='mso-list:l0 level1 lfo3;tab-stops:list .5in'><span + style='font-size:10.0pt;font-family:Verdana'>By clicking the right mouse + button on a network protocol, service or client, you can perform the + following operations.<o:p></o:p></span></li> + <ul style='margin-top:0in' type=circle> + <li class=MsoNormal style='mso-list:l0 level2 lfo3;tab-stops:list 1.0in'><span + style='font-size:10.0pt;font-family:Verdana'>Bind the network component + to another component.<o:p></o:p></span></li> + <li class=MsoNormal style='mso-list:l0 level2 lfo3;tab-stops:list 1.0in'><span + style='font-size:10.0pt;font-family:Verdana'>Unbind the network component + from another component that is bound to it.<o:p></o:p></span></li> + </ul> + <li class=MsoNormal style='mso-list:l0 level1 lfo3;tab-stops:list .5in'><span + style='font-size:10.0pt;font-family:Verdana'>By clicking the right mouse + button on a binding path, you can perform the following operations.<o:p></o:p></span></li> + <ul style='margin-top:0in' type=circle> + <li class=MsoNormal style='mso-list:l0 level2 lfo3;tab-stops:list 1.0in'><span + style='font-size:10.0pt;font-family:Verdana'>Disable the binding path if + it is enabled.<o:p></o:p></span></li> + <li class=MsoNormal style='mso-list:l0 level2 lfo3;tab-stops:list 1.0in'><span + style='font-size:10.0pt;font-family:Verdana'>Enable the binding path if + it is disabled.<o:p></o:p></span></li> + </ul> + <li class=MsoNormal style='mso-list:l0 level1 lfo3;tab-stops:list .5in'><span + style='font-size:10.0pt;font-family:Verdana'>Save the binding information + to a file.<o:p></o:p></span></li> +</ul> + +<h3><span style='font-family:Verdana'>CODE TOUR<o:p></o:p></span></h3> + +<h4><span style='font-family:Verdana'>File Manifest<o:p></o:p></span></h4> + +<pre><u>File<span style='mso-tab-count:2'>���������� </span>Description<o:p></o:p></u></pre><pre><span +style='text-transform:uppercase'>BINDVIEW.CPP</span><span style='mso-tab-count: +1'>�� </span>Contains <span class=SpellE>WinMain</span> and dialog box related functions.</pre><pre><span +style='text-transform:uppercase'>NetCfgAPI.cpp</span><span style='mso-tab-count: +1'>� </span>Contains <span class=SpellE>INetCfg</span> functions.</pre><pre>BINDING.CPP<span +style='mso-tab-count:1'>��� </span>Contains binding path related functions. </pre><pre><span +style='text-transform:uppercase'>Component.cpp</span><span style='mso-tab-count: +1'>� </span>Contains network component related functions.</pre><pre><span +class=GramE>RESOURCE.H<span style='mso-tab-count:1'>���� </span>Resource header.</span></pre><pre>BINDVIEW.H<span +style='mso-tab-count:1'>���� </span>Contains function prototypes.</pre><pre><span +style='text-transform:uppercase'>NetCfgAPI.h</span><span style='mso-tab-count: +1'>��� </span>Contains function prototypes for <span class=SpellE>NetCfgAPI.cpp</span></pre><pre><span +style='text-transform:uppercase'>BindView.rc</span><span style='mso-tab-count: +1'>��� </span>Resources for <span class=SpellE>Bindview</span></pre><pre><span +class=GramE><span style='text-transform:uppercase'>BindView.ico</span><span +style='mso-tab-count:1'>�� </span>Icon for the sample.</span></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre> + +<p align=center style='text-align:center;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt'><a +href="#_top"><span style='font-size:10.0pt;font-family:Verdana'>Top of page</span></a><span +style='font-size:10.0pt;font-family:Verdana'> <o:p></o:p></span></p> + +<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=624 + style='width:6.5in;mso-cellspacing:0in;mso-padding-alt:0in 0in 0in 0in'> + <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes; + height:1.5pt'> + <td style='background:aqua;padding:.75pt .75pt .75pt .75pt;height:1.5pt'> + <p class=MsoNormal><o:p> </o:p></p> + </td> + </tr> +</table> + +<p style='tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt'><span +style='font-size:7.5pt;font-family:"MS Sans Serif"'>� 2004</span><span +style='font-size:10.0pt;font-family:Verdana'> </span><span style='font-size: +7.5pt;font-family:"MS Sans Serif"'>Microsoft Corporation </span><span +style='font-size:10.0pt;font-family:Verdana'><o:p></o:p></span></p> + +</div> + +</body> + +</html> diff --git a/network/config/bindview/bindview.sln b/network/config/bindview/bindview.sln new file mode 100644 index 00000000..021f4efb --- /dev/null +++ b/network/config/bindview/bindview.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0 +MinimumVisualStudioVersion = 12.0 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bindview", "bindview.vcxproj", "{C8EC04C0-EF77-4CD4-8072-F7F8A9125822}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C8EC04C0-EF77-4CD4-8072-F7F8A9125822}.Debug|Win32.ActiveCfg = Debug|Win32 + {C8EC04C0-EF77-4CD4-8072-F7F8A9125822}.Debug|Win32.Build.0 = Debug|Win32 + {C8EC04C0-EF77-4CD4-8072-F7F8A9125822}.Release|Win32.ActiveCfg = Release|Win32 + {C8EC04C0-EF77-4CD4-8072-F7F8A9125822}.Release|Win32.Build.0 = Release|Win32 + {C8EC04C0-EF77-4CD4-8072-F7F8A9125822}.Debug|x64.ActiveCfg = Debug|x64 + {C8EC04C0-EF77-4CD4-8072-F7F8A9125822}.Debug|x64.Build.0 = Debug|x64 + {C8EC04C0-EF77-4CD4-8072-F7F8A9125822}.Release|x64.ActiveCfg = Release|x64 + {C8EC04C0-EF77-4CD4-8072-F7F8A9125822}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/network/config/bindview/bindview.vcxproj b/network/config/bindview/bindview.vcxproj new file mode 100644 index 00000000..767d2a89 --- /dev/null +++ b/network/config/bindview/bindview.vcxproj @@ -0,0 +1,211 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{C8EC04C0-EF77-4CD4-8072-F7F8A9125822}</ProjectGuid> + <RootNamespace>$(MSBuildProjectName)</RootNamespace> + <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> + <Platform Condition="'$(Platform)' == ''">Win32</Platform> + <SampleGuid>{224CF8FD-5538-4B7E-81AF-44805B4722EA}</SampleGuid> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <TargetVersion>Windows10</TargetVersion> + <UseDebugLibraries>False</UseDebugLibraries> + <DriverTargetPlatform>Desktop</DriverTargetPlatform> + <DriverType /> + <PlatformToolset>WindowsApplicationForDrivers10.0</PlatformToolset> + <ConfigurationType>Application</ConfigurationType> + </PropertyGroup> + <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <TargetVersion>Windows10</TargetVersion> + <UseDebugLibraries>True</UseDebugLibraries> + <DriverTargetPlatform>Desktop</DriverTargetPlatform> + <DriverType /> + <PlatformToolset>WindowsApplicationForDrivers10.0</PlatformToolset> + <ConfigurationType>Application</ConfigurationType> + </PropertyGroup> + <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <TargetVersion>Windows10</TargetVersion> + <UseDebugLibraries>False</UseDebugLibraries> + <DriverTargetPlatform>Desktop</DriverTargetPlatform> + <DriverType /> + <PlatformToolset>WindowsApplicationForDrivers10.0</PlatformToolset> + <ConfigurationType>Application</ConfigurationType> + </PropertyGroup> + <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <TargetVersion>Windows10</TargetVersion> + <UseDebugLibraries>True</UseDebugLibraries> + <DriverTargetPlatform>Desktop</DriverTargetPlatform> + <DriverType /> + <PlatformToolset>WindowsApplicationForDrivers10.0</PlatformToolset> + <ConfigurationType>Application</ConfigurationType> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <PropertyGroup> + <OutDir>$(IntDir)</OutDir> + </PropertyGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> + </ImportGroup> + <ItemGroup Label="WrappedTaskItems" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <TargetName>bindview</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <TargetName>bindview</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <TargetName>bindview</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <TargetName>bindview</TargetName> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <TreatWarningAsError>true</TreatWarningAsError> + <WarningLevel>Level4</WarningLevel> + <DisableSpecificWarnings>%(DisableSpecificWarnings);4127</DisableSpecificWarnings> + <RuntimeLibrary Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary> + <RuntimeLibrary Condition="'$(UseDebugLibraries)'=='true'">MultiThreadedDebug</RuntimeLibrary> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + <ExceptionHandling> + </ExceptionHandling> + </ClCompile> + <Midl> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + </Midl> + <ResourceCompile> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <AdditionalOptions>%(AdditionalOptions) -N</AdditionalOptions> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + </ResourceCompile> + <Link> + <AdditionalDependencies>%(AdditionalDependencies);ole32.lib;oleaut32.lib;comctl32.lib;comdlg32.lib;setupapi.lib;user32.lib;kernel32.lib;gdi32.lib;uuid.lib</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <TreatWarningAsError>true</TreatWarningAsError> + <WarningLevel>Level4</WarningLevel> + <DisableSpecificWarnings>%(DisableSpecificWarnings);4127</DisableSpecificWarnings> + <RuntimeLibrary Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary> + <RuntimeLibrary Condition="'$(UseDebugLibraries)'=='true'">MultiThreadedDebug</RuntimeLibrary> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + <ExceptionHandling> + </ExceptionHandling> + </ClCompile> + <Midl> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + </Midl> + <ResourceCompile> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <AdditionalOptions>%(AdditionalOptions) -N</AdditionalOptions> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + </ResourceCompile> + <Link> + <AdditionalDependencies>%(AdditionalDependencies);ole32.lib;oleaut32.lib;comctl32.lib;comdlg32.lib;setupapi.lib;user32.lib;kernel32.lib;gdi32.lib;uuid.lib</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <TreatWarningAsError>true</TreatWarningAsError> + <WarningLevel>Level4</WarningLevel> + <DisableSpecificWarnings>%(DisableSpecificWarnings);4127</DisableSpecificWarnings> + <RuntimeLibrary Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary> + <RuntimeLibrary Condition="'$(UseDebugLibraries)'=='true'">MultiThreadedDebug</RuntimeLibrary> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + <ExceptionHandling> + </ExceptionHandling> + </ClCompile> + <Midl> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + </Midl> + <ResourceCompile> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <AdditionalOptions>%(AdditionalOptions) -N</AdditionalOptions> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + </ResourceCompile> + <Link> + <AdditionalDependencies>%(AdditionalDependencies);ole32.lib;oleaut32.lib;comctl32.lib;comdlg32.lib;setupapi.lib;user32.lib;kernel32.lib;gdi32.lib;uuid.lib</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <TreatWarningAsError>true</TreatWarningAsError> + <WarningLevel>Level4</WarningLevel> + <DisableSpecificWarnings>%(DisableSpecificWarnings);4127</DisableSpecificWarnings> + <RuntimeLibrary Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary> + <RuntimeLibrary Condition="'$(UseDebugLibraries)'=='true'">MultiThreadedDebug</RuntimeLibrary> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + <ExceptionHandling> + </ExceptionHandling> + </ClCompile> + <Midl> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + </Midl> + <ResourceCompile> + <PreprocessorDefinitions>%(PreprocessorDefinitions);WIN32;UNICODE;_UNICODE</PreprocessorDefinitions> + <AdditionalOptions>%(AdditionalOptions) -N</AdditionalOptions> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH)</AdditionalIncludeDirectories> + </ResourceCompile> + <Link> + <AdditionalDependencies>%(AdditionalDependencies);ole32.lib;oleaut32.lib;comctl32.lib;comdlg32.lib;setupapi.lib;user32.lib;kernel32.lib;gdi32.lib;uuid.lib</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="binding.cpp" /> + <ClCompile Include="bindview.cpp" /> + <ClCompile Include="component.cpp" /> + <ClCompile Include="netcfgapi.cpp" /> + <ResourceCompile Include="bindview.rc" /> + </ItemGroup> + <ItemGroup> + <Inf Exclude="@(Inf)" Include="*.inf" /> + <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> + <FilesToPackage Include="@(Inf->'%(CopyOutput)')" Condition="'@(Inf)'!=''" /> + </ItemGroup> + <ItemGroup> + <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> + <None Exclude="@(None)" Include="*.ico;*.cur;*.bmp;*.dlg;*.rct;*.gif;*.jpg;*.jpeg;*.wav;*.jpe;*.tiff;*.tif;*.png;*.rc2" /> + <None Exclude="@(None)" Include="*.def;*.bat;*.hpj;*.asmx" /> + </ItemGroup> + <ItemGroup> + <ClInclude Exclude="@(ClInclude)" Include="*.h;*.hpp;*.hxx;*.hm;*.inl;*.xsd" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> +</Project>
\ No newline at end of file diff --git a/network/config/bindview/bindview.vcxproj.Filters b/network/config/bindview/bindview.vcxproj.Filters new file mode 100644 index 00000000..964d777e --- /dev/null +++ b/network/config/bindview/bindview.vcxproj.Filters @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> + <UniqueIdentifier>{4372001E-614D-43C8-ACA0-0ACF46A23F6E}</UniqueIdentifier> + </Filter> + <Filter Include="Header Files"> + <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> + <UniqueIdentifier>{98620252-1A3C-4A35-8A10-A2376A0D90BF}</UniqueIdentifier> + </Filter> + <Filter Include="Resource Files"> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> + <UniqueIdentifier>{CC73B9F9-A9E1-4AA1-88AE-951314EA9903}</UniqueIdentifier> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="binding.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="bindview.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="component.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="netcfgapi.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ResourceCompile Include="bindview.rc"> + <Filter>Resource Files</Filter> + </ResourceCompile> + </ItemGroup> +</Project>
\ No newline at end of file |
