Author: janderwald
Date: Fri Oct 17 08:19:04 2008
New Revision: 36790
URL:
http://svn.reactos.org/svn/reactos?rev=36790&view=rev
Log:
* Convert ncpa to a simple wrapper which invokes netshell.dll IShellFolder
* Delete obsolete code
Removed:
trunk/reactos/dll/cpl/ncpa/lang/
trunk/reactos/dll/cpl/ncpa/ncpa.h
trunk/reactos/dll/cpl/ncpa/ncpa.rc
trunk/reactos/dll/cpl/ncpa/resource.h
trunk/reactos/dll/cpl/ncpa/resources/
trunk/reactos/dll/cpl/ncpa/rsrc.rc
trunk/reactos/dll/cpl/ncpa/tcpip_properties.c
Modified:
trunk/reactos/dll/cpl/ncpa/ncpa.c
trunk/reactos/dll/cpl/ncpa/ncpa.rbuild
Modified: trunk/reactos/dll/cpl/ncpa/ncpa.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/ncpa/ncpa.c?rev=36…
==============================================================================
--- trunk/reactos/dll/cpl/ncpa/ncpa.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/ncpa/ncpa.c [iso-8859-1] Fri Oct 17 08:19:04 2008
@@ -1,20 +1,3 @@
-/*
- * Copyright 2004 Gero Kuehn
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
/*
* PROJECT: ReactOS Network Control Panel
* FILE: lib/cpl/system/ncpa.c
@@ -24,1029 +7,25 @@
* 07-18-2004 Created
*/
-/*
- * Read this first !
- *
- * This file contains a first attempt for reactos network configuration
- *
- * - It is not complete.
- * - It does not work the way it works on Windows.
- *
- * A lot of code that can be found here now, will probably be relocated into the OS core
or some
- * protocol Co-Installers or Notify Objects later when all the required COM
- * and "netcfgx.dll" infrastructure (esp. headers and Interfaces) get
implemented step by step.
- *
- * This code is only a first approach to provide a usable network configuration dialogs
for
- * the new network support in Reactos.
- *
- * If you intend to extend this code by more, please contact me to avoid duplicate work.
- * There are already resources and code for TCP/IP configuration that are not
- * mature enough for committing them to CVS yet.
- */
-
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
-#include <tchar.h>
#include <windows.h>
-#include <iphlpapi.h>
-#include <commctrl.h>
+#include <shellapi.h>
#include <cpl.h>
-#include <wine/debug.h>
-WINE_DEFAULT_DEBUG_CHANNEL(ncpa);
-#ifndef _UNICODE
-#define debugstr_aw debugstr_a
-#else
-#define debugstr_aw debugstr_w
-#endif
-#include "resource.h"
-#include "ncpa.h"
-
-#define NCF_VIRTUAL 0x1
-#define NCF_SOFTWARE_ENUMERATED 0x2
-#define NCF_PHYSICAL 0x4
-#define NCF_HIDDEN 0x8
-#define NCF_NO_SERVICE 0x10
-#define NCF_NOT_USER_REMOVABLE 0x20
-#define NCF_MULTIPORT_INSTANCED_ADAPTER 0x40
-#define NCF_HAS_UI 0x80
-#define NCF_FILTER 0x400
-#define NCF_NDIS_PROTOCOL 0x4000
-
-typedef void (ENUMREGKEYCALLBACK)(void *pCookie,HKEY hBaseKey,TCHAR *pszSubKey);
-
-static LONG CALLBACK DisplayApplet(VOID);
-static INT_PTR CALLBACK NetworkPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM
lParam);
-void DisplayTCPIPProperties(HWND hParent,IP_ADAPTER_INFO *pInfo);
-
-HINSTANCE hApplet = 0;
-HWND hCPLWindow;
-
-/* Applets */
-static APPLET Applets[] =
-{
- {IDI_CPLSYSTEM, IDS_CPLSYSTEMNAME, IDS_CPLSYSTEMDESCRIPTION, DisplayApplet}
-};
-
-
-/* useful utilities */
-static VOID
-EnumRegKeys(ENUMREGKEYCALLBACK *pCallback,PVOID pCookie,HKEY hBaseKey,TCHAR
*tpszRegPath)
-{
- HKEY hKey;
- INT i;
- LONG ret;
- TCHAR tpszName[MAX_PATH];
- DWORD dwNameLen = sizeof(tpszName);
-
- if(RegOpenKeyEx(hBaseKey,tpszRegPath,0,KEY_ENUMERATE_SUB_KEYS,&hKey)!=ERROR_SUCCESS)
- {
- WARN("EnumRegKeys failed (key not found): %S\n", tpszRegPath);
- return;
- }
-
- for(i=0;;i++)
- {
- TCHAR pszNewPath[MAX_PATH];
- ret = RegEnumKeyEx(hKey,i,tpszName,&dwNameLen,NULL,NULL,NULL,NULL);
- if(ret != ERROR_SUCCESS)
- {
- WARN("EnumRegKeys: RegEnumKeyEx failed for %S (rc 0x%lx)\n", tpszName,
ret);
- break;
- }
-
- _stprintf(pszNewPath,_T("%s\\%s"),tpszRegPath,tpszName);
- TRACE("EnumRegKeys: Calling user supplied enum function\n");
- pCallback(pCookie,hBaseKey,pszNewPath);
-
- dwNameLen = sizeof(tpszName);
- }
-
- RegCloseKey(hKey);
-}
-
-void
-InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc,LPARAM lParam)
-{
- ZeroMemory(psp, sizeof(PROPSHEETPAGE));
- psp->dwSize = sizeof(PROPSHEETPAGE);
- psp->dwFlags = PSP_DEFAULT;
- psp->hInstance = hApplet;
- psp->pszTemplate = MAKEINTRESOURCE(idDlg);
- psp->pfnDlgProc = DlgProc;
- psp->lParam = lParam;
-}
-
-
-
-static BOOL
-FindNICClassKeyForCfgInstance(TCHAR *tpszCfgInst,TCHAR *tpszSubKeyOut)
-{
- int i;
- TCHAR tpszSubKey[MAX_PATH];
- TCHAR tpszCfgInst2[MAX_PATH];
- HKEY hKey;
- DWORD dwType,dwSize;
-
- for (i = 0; i < 100; i++)
- {
- _stprintf(tpszSubKey,_T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%04d"),i);
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,tpszSubKey,0,KEY_QUERY_VALUE,&hKey)!=ERROR_SUCCESS)
- continue;
- dwType = REG_SZ;
- dwSize = sizeof(tpszCfgInst2);
- if(RegQueryValueEx(hKey,_T("NetCfgInstanceId"),NULL,&dwType,(BYTE*)tpszCfgInst2,&dwSize)!=ERROR_SUCCESS)
{
- RegCloseKey(hKey);
- continue;
- }
- RegCloseKey(hKey);
- if(_tcscmp(tpszCfgInst,tpszCfgInst2)==0) {
- _tcscpy(tpszSubKeyOut,tpszSubKey);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-
-static void
-NICPropertyProtocolCallback(void *pCookie,HKEY hBaseKey,TCHAR *tpszSubKey)
-{
- HWND hwndDlg;
- DWORD dwCharacteristics;
- HKEY hKey,hNDIKey;
- DWORD dwType,dwSize;
- TCHAR tpszDescription[MAX_PATH];
- TCHAR tpszNotifyObjectCLSID[MAX_PATH];
- TCHAR *tpszSubKeyCopy;
- int nIndex;
-
- UNREFERENCED_PARAMETER(hBaseKey);
-
-// CLSID CLSID_NotifObj;
-// IUnknown *pUnk = NULL;
-// INetCfgComponentControl *pNetCfg;
-// INetCfgComponentPropertyUi *pNetCfgPropUI;
- hwndDlg = (HWND)pCookie;
-
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,tpszSubKey,0,KEY_QUERY_VALUE,&hKey)!=ERROR_SUCCESS)
- return;
-
- dwType = REG_DWORD;
- dwSize = sizeof(dwCharacteristics);
- if(RegQueryValueEx(hKey,_T("Characteristics"),NULL,&dwType,(BYTE*)&dwCharacteristics,&dwSize)!=
ERROR_SUCCESS)
- return;
-
- if(dwCharacteristics & NCF_HIDDEN)
- {
- RegCloseKey(hKey);
- return;
- }
-
- dwType = REG_SZ;
- dwSize = sizeof(tpszDescription);
- if(RegQueryValueEx(hKey,_T("Description"),NULL,&dwType,(BYTE*)tpszDescription,&dwSize)!=
ERROR_SUCCESS)
- return;
-
- RegOpenKeyEx(hKey,_T("Ndi"),0,KEY_QUERY_VALUE,&hNDIKey);
- dwType = REG_SZ;
- dwSize = sizeof(tpszNotifyObjectCLSID);
- if(RegQueryValueEx(hNDIKey,_T("ClsId"),NULL,&dwType,(BYTE*)tpszNotifyObjectCLSID,&dwSize)!=
ERROR_SUCCESS)
- ;//return;
-
- RegCloseKey(hNDIKey);
-
- //
- // This code works on Windows... but not on Reactos
- //
-
-// CLSIDFromString(tpszNotifyObjectCLSID,&CLSID_NotifObj);
-// CoCreateInstance(&CLSID_NotifObj,NULL,CLSCTX_INPROC_SERVER,&IID_IUnknown,(void**)&pUnk);
-// pUnk->lpVtbl->QueryInterface(pUnk,&IID_INetCfgComponentControl,(void**)&pNetCfg);
-// pUnk->lpVtbl->QueryInterface(pUnk,&IID_INetCfgComponentPropertyUi,(void**)&pNetCfgPropUI);
- {
- /*
- HRESULT hr;
- hr = pNetCfg->lpVtbl->Initialize(pNetCfg,&NetCfgComponent,&NetCfg,FALSE);
- hr = pNetCfgPropUI->lpVtbl->QueryPropertyUi(pNetCfgPropUI,(INetCfg*)&NetCfg);
- hr =
pNetCfgPropUI->lpVtbl->SetContext(pNetCfgPropUI,(INetCfg*)&NetCfgComponent);
- DWORD dwNumPages = 10;
- HPROPSHEETPAGE *bOut = NULL;
- UINT nPages;
- hr =
pNetCfgPropUI->MergePropPages(&dwNumPages,(BYTE**)&bOut,&nPages,GetDesktopWindow(),NULL);
- */
- }
-
- RegCloseKey(hKey);
- nIndex = (int)
SendDlgItemMessage(hwndDlg,IDC_COMPONENTSLIST,LB_ADDSTRING,0,(LPARAM)tpszDescription);
- tpszSubKeyCopy = _tcsdup(tpszSubKey);
- SendDlgItemMessage(hwndDlg,IDC_COMPONENTSLIST,LB_SETITEMDATA,nIndex,(LPARAM)tpszSubKeyCopy);
-}
-
-
-
-static INT_PTR CALLBACK
-NICPropertyPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- PGLOBAL_NCPA_DATA pGlobalData = (PGLOBAL_NCPA_DATA)GetWindowLongPtr(hwndDlg,
DWLP_USER);
-
- switch(uMsg)
- {
- case WM_INITDIALOG:
- {
- DWORD dwType,dwSize;
- TCHAR tpszSubKey[MAX_PATH];
- TCHAR tpszDisplayName[MAX_PATH];
- HKEY hKey;
-
- pGlobalData = (PGLOBAL_NCPA_DATA)((LPPROPSHEETPAGE)lParam)->lParam;
- if (pGlobalData == NULL)
- return FALSE;
-
- SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
-
- if(!FindNICClassKeyForCfgInstance(pGlobalData->CurrentAdapterName, tpszSubKey))
- {
- WARN("NIC Entry not found for '%s'\n",
debugstr_w(pGlobalData->CurrentAdapterName));
- MessageBox(hwndDlg,_T("NIC Entry not found"),_T("Registry
error"),MB_ICONSTOP);
- MessageBox(hwndDlg,pGlobalData->CurrentAdapterName,tpszSubKey,MB_ICONSTOP);
- }
-
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,tpszSubKey,0,KEY_QUERY_VALUE,&hKey)!=ERROR_SUCCESS)
- return 0;
- dwType = REG_SZ;
- dwSize = sizeof(tpszDisplayName);
- if(RegQueryValueEx(hKey,_T("DriverDesc"),NULL,&dwType,(BYTE*)tpszDisplayName,&dwSize)!=
ERROR_SUCCESS)
- return 0;
- RegCloseKey(hKey);
-
- SetDlgItemText(hwndDlg,IDC_NETCARDNAME,tpszDisplayName);
- EnableWindow(GetDlgItem(hwndDlg,IDC_CONFIGURE),FALSE);
-
- //SetDlgItemTextA(hwndDlg,IDC_NETCARDNAME,Info[pPage->lParam].Description);
- EnumRegKeys(NICPropertyProtocolCallback,hwndDlg,HKEY_LOCAL_MACHINE,_T("SYSTEM\\CurrentControlSet\\Control\\Network\\{4d36e973-e325-11ce-bfc1-08002be10318}"));
- EnumRegKeys(NICPropertyProtocolCallback,hwndDlg,HKEY_LOCAL_MACHINE,_T("SYSTEM\\CurrentControlSet\\Control\\Network\\{4d36e974-e325-11ce-bfc1-08002be10318}"));
- EnumRegKeys(NICPropertyProtocolCallback,hwndDlg,HKEY_LOCAL_MACHINE,_T("System\\CurrentControlSet\\Control\\Network\\{4D36E975-E325-11CE-BFC1-08002BE10318}"));
-
- SendDlgItemMessage(hwndDlg, IDC_COMPONENTSLIST, LB_SETCURSEL, 0, 0);
- SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_COMPONENTSLIST, LBN_SELCHANGE), 0);
- }
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_COMPONENTSLIST:
- if(HIWORD(wParam)==LBN_SELCHANGE)
- {
- TCHAR *tpszSubKey;
- TCHAR tpszHelpKey[MAX_PATH];
- TCHAR tpszHelpText[MAX_PATH];
- HKEY hNDIKey;
- DWORD dwType,dwSize;
- HWND hListBox = GetDlgItem(hwndDlg,IDC_COMPONENTSLIST);
- tpszSubKey =
(TCHAR*)SendMessage(hListBox,LB_GETITEMDATA,SendMessage(hListBox,LB_GETCURSEL,0,0),0);
- if(!tpszSubKey)
- break;
- _stprintf(tpszHelpKey,_T("%s\\Ndi"),tpszSubKey);
-
- RegOpenKeyEx(HKEY_LOCAL_MACHINE,tpszHelpKey,0,KEY_QUERY_VALUE,&hNDIKey);
- dwType = REG_SZ;
- dwSize = sizeof(tpszHelpText);
-
- tpszHelpText[0] = _T('\0');
- if (RegLoadMUIString(hNDIKey,
_T("HelpText"),tpszHelpText,dwSize,&dwSize,0,NULL) !=ERROR_SUCCESS)
- {
- DWORD dwResult;
- dwResult = GetSystemDirectory(tpszHelpKey, dwSize / sizeof(TCHAR));
- if (dwResult < dwSize && dwResult != 0)
- {
- if (RegLoadMUIString(hNDIKey,
_T("HelpText"),tpszHelpText,dwSize,&dwSize,0,tpszHelpKey) !=ERROR_SUCCESS)
- tpszHelpText[0] = _T('\0');
- }
- }
- RegCloseKey(hNDIKey);
-
- SetDlgItemText(hwndDlg,IDC_DESCRIPTION,tpszHelpText);
- }
- if(HIWORD(wParam)!=LBN_DBLCLK)
- break;
- // drop though
- case IDC_PROPERTIES:
- {
- if(pGlobalData->pCurrentAdapterInfo)
- {
- DisplayTCPIPProperties(hwndDlg, pGlobalData->pCurrentAdapterInfo);
- }
- else
- {
- FIXME("If you see this, then the IPHLPAPI.DLL probably needs more work because
GetAdaptersInfo did not return the expected data.\n");
- MessageBox(NULL,_T("If you see this, then the IPHLPAPI.DLL probably needs more
work because GetAdaptersInfo did not return the expected
data."),_T("Error"),MB_ICONSTOP);
- }
- }
- break;
- }
- break;
- }
- return FALSE;
-}
-
-
-static void
-DisplayNICProperties(HWND hParent, GLOBAL_NCPA_DATA* pGlobalData)
-{
- PROPSHEETPAGE psp[1];
- PROPSHEETHEADER psh;
- TCHAR tpszSubKey[MAX_PATH];
- HKEY hKey;
- DWORD dwType = REG_SZ;
- TCHAR tpszName[MAX_PATH];
- DWORD dwSize = sizeof(tpszName);
- TCHAR tpszCfgInstanceID[MAX_ADAPTER_NAME_LENGTH];
-
-#ifndef _UNICODE
- WideCharToMultiByte(CP_UTF8, 0, pGlobalData->CurrentAdapterName, -1,
tpszCfgInstanceID, MAX_ADAPTER_NAME_LENGTH, 0, 0);
-#else
- wcscpy(tpszCfgInstanceID, pGlobalData->CurrentAdapterName);
-#endif
-
- // Get the "Name" for this Connection
- _stprintf(tpszSubKey,_T("System\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection"),tpszCfgInstanceID);
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,tpszSubKey,0,KEY_QUERY_VALUE,&hKey)!=ERROR_SUCCESS)
- return;
- if(RegQueryValueEx(hKey,_T("Name"),NULL,&dwType,(BYTE*)tpszName,&dwSize)!=ERROR_SUCCESS)
- _stprintf(tpszName,_T("[ERROR]"));
- else
- _tcscat(tpszName,_T(" Properties"));
- RegCloseKey(hKey);
-
- ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
- psh.dwSize = sizeof(PROPSHEETHEADER);
- psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
- psh.hwndParent = hParent;
- psh.hInstance = hApplet;
- psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM));
- psh.pszCaption = tpszName;
- psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
- psh.nStartPage = 0;
- psh.ppsp = psp;
- psh.pfnCallback = NULL;
-
- InitPropSheetPage(&psp[0], IDD_NETPROPERTIES, NICPropertyPageProc,
(LPARAM)pGlobalData);
- PropertySheet(&psh);
- return;
-}
-
-void RefreshNICInfo(HWND hwndDlg, PGLOBAL_NCPA_DATA pGlobalData)
-{
- ULONG BufferSize;
- DWORD ErrRet = 0;
-
- if (pGlobalData->pFirstAdapterInfo)
- HeapFree(GetProcessHeap(), 0, pGlobalData->pFirstAdapterInfo);
-
- BufferSize = sizeof(IP_ADAPTER_INFO);
- pGlobalData->pFirstAdapterInfo = (PIP_ADAPTER_INFO) HeapAlloc(GetProcessHeap(), 0,
BufferSize);
-
- if (GetAdaptersInfo(pGlobalData->pFirstAdapterInfo, &BufferSize) ==
ERROR_BUFFER_OVERFLOW)
- {
- HeapFree(GetProcessHeap(), 0, pGlobalData->pFirstAdapterInfo);
- pGlobalData->pFirstAdapterInfo = (PIP_ADAPTER_INFO) HeapAlloc(GetProcessHeap(), 0,
BufferSize);
- }
-
- if ((ErrRet = GetAdaptersInfo(pGlobalData->pFirstAdapterInfo, &BufferSize)) !=
NO_ERROR)
- {
- ERR("error adapterinfo\n");
- MessageBox(hwndDlg, _T("error adapterinfo")
,_T("ncpa.cpl"),MB_ICONSTOP);
-
- if (pGlobalData->pFirstAdapterInfo)
- HeapFree(GetProcessHeap(), 0, pGlobalData->pFirstAdapterInfo);
- }
-}
-
-void UpdateCurrentAdapterInfo(HWND hwndDlg, PGLOBAL_NCPA_DATA pGlobalData)
-{
- PIP_INTERFACE_INFO pInfo;
- ULONG BufferSize = 0;
- DWORD dwRetVal = 0;
-
- if (!pGlobalData->pCurrentAdapterInfo)
- return;
-
- BufferSize = sizeof(IP_INTERFACE_INFO);
- pInfo = (PIP_INTERFACE_INFO) HeapAlloc(GetProcessHeap(), 0, BufferSize);
- if (ERROR_INSUFFICIENT_BUFFER == GetInterfaceInfo(pInfo, &BufferSize))
- {
- HeapFree(GetProcessHeap(), 0, pInfo);
- pInfo = (PIP_INTERFACE_INFO) HeapAlloc(GetProcessHeap(), 0, BufferSize);
- }
-
- dwRetVal = GetInterfaceInfo(pInfo, &BufferSize);
- if (NO_ERROR == dwRetVal)
- {
- DWORD i;
-
- for (i = 0; i < pInfo->NumAdapters; i++)
- {
- if (0 == wcscmp(pGlobalData->CurrentAdapterName, pInfo->Adapter[i].Name))
- {
- if (pInfo->Adapter[i].Index != pGlobalData->pCurrentAdapterInfo->Index)
- {
- RefreshNICInfo(hwndDlg, pGlobalData);
-
- pGlobalData->pCurrentAdapterInfo = pGlobalData->pFirstAdapterInfo;
- while (pGlobalData->pCurrentAdapterInfo)
- {
- if (pGlobalData->pCurrentAdapterInfo->Index == pInfo->Adapter[i].Index)
- return;
-
- pGlobalData->pCurrentAdapterInfo =
pGlobalData->pCurrentAdapterInfo->Next;
- }
- }
- }
- }
- }
- else if (ERROR_NO_DATA == dwRetVal)
- WARN("There are no network adapters with IPv4 enabled on the local
system\n");
- else
- ERR("GetInterfaceInfo failed.\n");
-}
-
-static VOID
-UpdateNICStatusData(HWND hwndDlg, PGLOBAL_NCPA_DATA pGlobalData)
-{
- DWORD dwRet = NO_ERROR;
-
- if (pGlobalData->pCurrentAdapterInfo)
- {
- if (NULL == pGlobalData->pIfTable)
- {
- pGlobalData->IfTableSize = sizeof(MIB_IFTABLE);
- pGlobalData->pIfTable = (PMIB_IFTABLE)HeapAlloc(GetProcessHeap(), 0,
pGlobalData->IfTableSize);
- if (NULL == pGlobalData->pIfTable)
- {
- static BOOL firstError = TRUE;
- if (firstError)
- {
- firstError = FALSE;
- WARN("Out of memory - could not allocate MIB_IFTABLE(1)");
- return;
- }
- }
- }
-
- /* Call GetIfTable once to see if we have a large enough buffer */
- dwRet = GetIfTable(pGlobalData->pIfTable, &pGlobalData->IfTableSize, FALSE);
- if (ERROR_INSUFFICIENT_BUFFER == dwRet)
- {
- HeapFree(GetProcessHeap(), 0, pGlobalData->pIfTable);
-
- pGlobalData->pIfTable = (PMIB_IFTABLE)HeapAlloc(GetProcessHeap(), 0,
pGlobalData->IfTableSize);
- if (NULL == pGlobalData->pIfTable)
- {
- static BOOL firstError = TRUE;
- if (firstError)
- {
- firstError = FALSE;
- WARN("Out of memory - could not allocate MIB_IFTABLE(2)");
- }
-
- pGlobalData->IfTableSize = 0;
- return;
- }
-
- dwRet = GetIfTable(pGlobalData->pIfTable, &pGlobalData->IfTableSize,
FALSE);
- if (NO_ERROR != dwRet)
- {
- HeapFree(GetProcessHeap(), 0, pGlobalData->pIfTable);
- pGlobalData->pIfTable = NULL;
- pGlobalData->IfTableSize = 0;
- return;
- }
- }
- }
-
- if (NO_ERROR == dwRet)
- {
- DWORD i;
- DWORD PktsOut = 0;
- DWORD PktsIn = 0;
- DWORD Mbps = 0;
- DWORD OperStatus = IF_OPER_STATUS_DISCONNECTED;
- PMIB_IFROW pIfRow = NULL;
- TCHAR Buffer[256], LocBuffer[256], szDecimalSep[3];
- SYSTEMTIME TimeConnected;
- NUMBERFMT fmt;
-
- memset(&TimeConnected, 0, sizeof(TimeConnected));
-
- if (pGlobalData->pCurrentAdapterInfo)
- {
- UpdateCurrentAdapterInfo(hwndDlg, pGlobalData);
-
- for (i = 0; i < pGlobalData->pIfTable->dwNumEntries; i++)
- {
- pIfRow = (PMIB_IFROW)&pGlobalData->pIfTable->table[i];
-
- if (pIfRow->dwIndex == pGlobalData->pCurrentAdapterInfo->Index)
- {
- DWORD DurationSeconds;
- ULONGLONG Ticks;
-
- PktsOut = pIfRow->dwOutOctets;
- PktsIn = pIfRow->dwInOctets;
- Mbps = pIfRow->dwSpeed;
- OperStatus = pIfRow->dwOperStatus;
-
- /* TODO: For some unknown reason, this doesn't correspond to the Windows
duration */
- Ticks = GetTickCount64();
- DurationSeconds = Ticks / 1000;
- TimeConnected.wSecond = (DurationSeconds % 60);
- TimeConnected.wMinute = (DurationSeconds / 60) % 60;
- TimeConnected.wHour = (DurationSeconds / (60 * 60)) % 24;
- TimeConnected.wDay = DurationSeconds / (60 * 60 * 24);
-
- break;
- }
- }
- }
-
- memset(&fmt, 0x0, sizeof(fmt));
- if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, szDecimalSep,
sizeof(szDecimalSep) / sizeof(szDecimalSep[0])))
- fmt.lpThousandSep = szDecimalSep;
- fmt.Grouping = 3;
- fmt.lpDecimalSep = _T("");
-
- _stprintf(Buffer, L"%u", PktsOut);
- GetNumberFormat(LOCALE_USER_DEFAULT, 0, Buffer, &fmt, LocBuffer, sizeof(LocBuffer)
/ sizeof(LocBuffer[0]));
- SendDlgItemMessage(hwndDlg, IDC_SEND, WM_SETTEXT, 0, (LPARAM)LocBuffer);
-
- _stprintf(Buffer, L"%u", PktsIn);
- GetNumberFormat(LOCALE_USER_DEFAULT, 0, Buffer, &fmt, LocBuffer, sizeof(LocBuffer)
/ sizeof(LocBuffer[0]));
- SendDlgItemMessage(hwndDlg, IDC_RECEIVED, WM_SETTEXT, 0, (LPARAM)LocBuffer);
-
- switch (OperStatus)
- {
- case IF_OPER_STATUS_NON_OPERATIONAL:
- OperStatus = IDS_STATUS_NON_OPERATIONAL;
- break;
-
- case IF_OPER_STATUS_UNREACHABLE:
- OperStatus = IDS_STATUS_UNREACHABLE;
- break;
-
- case IF_OPER_STATUS_DISCONNECTED:
- OperStatus = IDS_STATUS_DISCONNECTED;
- break;
-
- case IF_OPER_STATUS_CONNECTING:
- OperStatus = IDS_STATUS_CONNECTING;
- break;
-
- case IF_OPER_STATUS_CONNECTED:
- OperStatus = IDS_STATUS_CONNECTED;
- break;
-
- case IF_OPER_STATUS_OPERATIONAL:
- /* TODO: Find sub status, waiting for DHCP address, etc. */
- OperStatus = IDS_STATUS_OPERATIONAL;
- break;
-
- default:
- WARN("Unknown operation status: %d\n", OperStatus);
- OperStatus = IDS_STATUS_OPERATIONAL;
- break;
- }
- LoadString(hApplet, OperStatus, LocBuffer, sizeof(LocBuffer) / sizeof(LocBuffer[0]));
- SendDlgItemMessage(hwndDlg, IDC_STATUS, WM_SETTEXT, 0, (LPARAM)LocBuffer);
-
- GetTimeFormat(LOCALE_USER_DEFAULT, 0, &TimeConnected,
L"HH':'mm':'ss", LocBuffer, sizeof(LocBuffer) /
sizeof(LocBuffer[0]));
- if (0 == TimeConnected.wDay)
- {
- SendDlgItemMessage(hwndDlg, IDC_DURATION, WM_SETTEXT, 0, (LPARAM)LocBuffer);
- }
- else
- {
- TCHAR DayBuffer[256];
- if (1 == TimeConnected.wDay)
- {
- LoadString(hApplet, IDS_DURATION_DAY, DayBuffer, sizeof(DayBuffer) /
sizeof(DayBuffer[0]));
- }
- else
- {
- LoadString(hApplet, IDS_DURATION_DAYS, DayBuffer, sizeof(DayBuffer) /
sizeof(DayBuffer[0]));
- }
- _sntprintf(Buffer, 256, DayBuffer, TimeConnected.wDay, LocBuffer);
- SendDlgItemMessage(hwndDlg, IDC_DURATION, WM_SETTEXT, 0, (LPARAM)Buffer);
- }
-
- LoadString(hApplet, IDS_SPEED_MBPS, LocBuffer, sizeof(LocBuffer) /
sizeof(LocBuffer[0]));
- _sntprintf(Buffer, 256, LocBuffer, Mbps / 1000000);
- SendDlgItemMessage(hwndDlg, IDC_SPEED, WM_SETTEXT, 0, (LPARAM)Buffer);
- }
- else
- {
- static BOOL firstError = TRUE;
- if (firstError)
- {
- firstError = FALSE;
- ERR("GetIfTable failed with error code: %d\n", dwRet);
- return;
- }
- }
-}
-
-static INT_PTR CALLBACK
-NICStatusPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- PGLOBAL_NCPA_DATA pGlobalData;
- pGlobalData = (PGLOBAL_NCPA_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
-
- switch(uMsg)
- {
- case WM_INITDIALOG:
- {
- pGlobalData = (PGLOBAL_NCPA_DATA)((LPPROPSHEETPAGE)lParam)->lParam;
- if (pGlobalData == NULL)
- return FALSE;
-
- SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
-
- EnableWindow(GetDlgItem(hwndDlg,IDC_ENDISABLE),FALSE);
- pGlobalData->hStatsUpdateTimer = SetTimer(hwndDlg, 1, 1000, NULL);
- UpdateNICStatusData(hwndDlg, pGlobalData);
- }
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_PROPERTIES:
- {
- DisplayNICProperties(hwndDlg, pGlobalData);
- }
- break;
- }
- break;
- case WM_TIMER:
- {
- UpdateNICStatusData(hwndDlg, pGlobalData);
- }
- break;
- case WM_DESTROY:
- {
- KillTimer(hwndDlg, pGlobalData->hStatsUpdateTimer);
- pGlobalData->hStatsUpdateTimer = 0;
-
- if (pGlobalData->pIfTable)
- {
- HeapFree(GetProcessHeap(), 0, pGlobalData->pIfTable);
- pGlobalData->pIfTable = NULL;
- pGlobalData->IfTableSize = 0;
- }
- }
- break;
- }
- return FALSE;
-}
-
-static INT_PTR CALLBACK
-NICSupportPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- PGLOBAL_NCPA_DATA pGlobalData;
- pGlobalData = (PGLOBAL_NCPA_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
-
- switch(uMsg)
- {
- case WM_INITDIALOG:
- {
- pGlobalData = (PGLOBAL_NCPA_DATA)((LPPROPSHEETPAGE)lParam)->lParam;
- if (pGlobalData == NULL)
- return FALSE;
-
- SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
-
- if (pGlobalData->pCurrentAdapterInfo)
- {
- TCHAR Buffer[64];
-
- if (pGlobalData->pCurrentAdapterInfo->DhcpEnabled)
- LoadString(hApplet, IDS_ASSIGNED_DHCP, Buffer, sizeof(Buffer) / sizeof(TCHAR));
- else
- LoadString(hApplet, IDS_ASSIGNED_MANUAL, Buffer, sizeof(Buffer) / sizeof(TCHAR));
-
- SendDlgItemMessage(hwndDlg, IDC_DETAILSTYPE, WM_SETTEXT, 0, (LPARAM)Buffer);
- _stprintf(Buffer, _T("%S"),
pGlobalData->pCurrentAdapterInfo->IpAddressList.IpAddress.String);
- SendDlgItemMessage(hwndDlg, IDC_DETAILSIP, WM_SETTEXT, 0, (LPARAM)Buffer);
- _stprintf(Buffer, _T("%S"),
pGlobalData->pCurrentAdapterInfo->IpAddressList.IpMask.String);
- SendDlgItemMessage(hwndDlg, IDC_DETAILSSUBNET, WM_SETTEXT, 0, (LPARAM)Buffer);
- _stprintf(Buffer, _T("%S"),
pGlobalData->pCurrentAdapterInfo->GatewayList.IpAddress.String);
- SendDlgItemMessage(hwndDlg, IDC_DETAILSGATEWAY, WM_SETTEXT, 0, (LPARAM)Buffer);
- }
- }
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_PROPERTIES:
- {
- }
- break;
- case IDC_DETAILS:
- {
- FIXME("Not implemented: show detail window\n");
- MessageBox(hwndDlg,_T("not implemented: show detail
window"),_T("ncpa.cpl"),MB_ICONSTOP);
- }
- break;
- }
- break;
- }
- return FALSE;
-}
-
-static VOID
-DisplayNICStatus(HWND hParent,TCHAR *tpszCfgInstanceID)
-{
- PROPSHEETPAGE psp[2];
- PROPSHEETHEADER psh;
- TCHAR tpszSubKey[MAX_PATH];
- HKEY hKey;
- DWORD dwType = REG_SZ;
- TCHAR tpszName[MAX_PATH];
- DWORD dwSize = sizeof(tpszName);
- PGLOBAL_NCPA_DATA pGlobalData;
- PIP_ADAPTER_INFO pInfo;
- WCHAR wcsAdapterName[MAX_ADAPTER_NAME];
-
- pGlobalData = (PGLOBAL_NCPA_DATA)GetWindowLongPtr(hParent, DWLP_USER);
-
-#ifndef _UNICODE
- MultiByteToWideChar(CP_UTF8, 0, tpszCfgInstanceID, -1,
pGlobalData->CurrentAdapterName, MAX_ADAPTER_NAME);
-#else
- wcscpy(pGlobalData->CurrentAdapterName, tpszCfgInstanceID);
-#endif
-
- // Get the "Name" for this Connection
- _stprintf(tpszSubKey,_T("System\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection"),tpszCfgInstanceID);
- if
(RegOpenKeyEx(HKEY_LOCAL_MACHINE,tpszSubKey,0,KEY_QUERY_VALUE,&hKey)!=ERROR_SUCCESS)
- return;
-
- if
(RegQueryValueEx(hKey,_T("Name"),NULL,&dwType,(BYTE*)tpszName,&dwSize)!=ERROR_SUCCESS)
- _stprintf(tpszName,_T("[ERROR]"));
- //_stprintf(tpszName,_T("[ERROR]") _T(__FILE__) _T(" %d"),__LINE__
);
- else
- _tcscat(tpszName,_T(" Status"));
- RegCloseKey(hKey);
-
- ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
- psh.dwSize = sizeof(PROPSHEETHEADER);
- psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
- psh.hwndParent = hParent;
- psh.hInstance = hApplet;
- // FIX THESE REACTOS HEADERS !!!!!!!!!
- psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM));
- psh.pszCaption = tpszName;//Caption;
- psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
- psh.nStartPage = 0;
- psh.ppsp = psp;
- psh.pfnCallback = NULL;
-
- RefreshNICInfo(hParent, pGlobalData);
-
- pGlobalData->pCurrentAdapterInfo = NULL;
- pInfo = pGlobalData->pFirstAdapterInfo;
- while (pInfo)
- {
- MultiByteToWideChar(CP_UTF8, 0, pInfo->AdapterName, -1, wcsAdapterName,
MAX_ADAPTER_NAME);
- if (0 == wcscmp(wcsAdapterName, pGlobalData->CurrentAdapterName))
- {
- pGlobalData->pCurrentAdapterInfo = pInfo;
- break;
- }
-
- pInfo = pInfo->Next;
- }
-
- InitPropSheetPage(&psp[0], IDD_CARDPROPERTIES, NICStatusPageProc,
(LPARAM)pGlobalData);
- InitPropSheetPage(&psp[1], IDD_CARDSUPPORT, NICSupportPageProc,
(LPARAM)pGlobalData);
-
- PropertySheet(&psh);
- return;
-}
-
-//
-// IPHLPAPI does not provide a list of all adapters
-//
-#if 0
-static VOID
-EnumAdapters(HWND hwndDlg)
-{
- TCHAR pszText[MAX_ADAPTER_NAME_LENGTH + 4];
- IP_ADAPTER_INFO *pInfo;
- ULONG size;
- INT nIndex;
-
- size=sizeof(Info);
- if(GetAdaptersInfo(Info,&size)!=ERROR_SUCCESS)
- {
- WARN("IPHLPAPI.DLL failed to provide Adapter information\n");
- MessageBox(hwndDlg,L"IPHLPAPI.DLL failed to provide Adapter
information",L"Error",MB_ICONSTOP);
- return;
- }
-
- pInfo = &Info[0];
- while(pInfo)
- {
- swprintf(pszText,L"%S",Info[0].Description);
- nIndex = SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_ADDSTRING,0,(LPARAM)pszText);
- SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_SETITEMDATA,nIndex,(LPARAM)pInfo);
- pInfo = pInfo->Next;
- }
-}
-#endif
-
-
-
-static void
-NetAdapterCallback(void *pCookie,HKEY hBaseKey,TCHAR *tpszSubKey)
-{
- TCHAR tpszDisplayName[MAX_PATH];
- //TCHAR tpszDeviceID[MAX_PATH];
- TCHAR tpszCfgInstanceID[MAX_PATH];
- TCHAR *ptpszCfgInstanceID;
- HKEY hKey;
- DWORD dwType = REG_SZ;
- DWORD dwSize = sizeof(tpszDisplayName);
- int nIndex;
- HWND hwndDlg = (HWND)pCookie;
- DWORD dwCharacteristics;
-
- TRACE("NetAdapterCallback: %s\n", debugstr_aw(tpszSubKey));
-
- if(RegOpenKeyEx(hBaseKey,tpszSubKey,0,KEY_QUERY_VALUE,&hKey)!=ERROR_SUCCESS)
- return;
-
- TRACE("NetAdapterCallback: Reading Characteristics\n");
- dwType = REG_DWORD;
- dwSize = sizeof(dwCharacteristics);
- if(RegQueryValueEx(hKey,_T("Characteristics"),NULL,&dwType,(BYTE*)&dwCharacteristics,&dwSize)!=ERROR_SUCCESS)
- dwCharacteristics = 0;
- if (dwCharacteristics & NCF_HIDDEN)
- return;
- if (!(dwCharacteristics & NCF_VIRTUAL) && !(dwCharacteristics &
NCF_PHYSICAL))
- return;
-
- TRACE("NetAdapterCallback: Reading DriverDesc\n");
- dwType = REG_SZ;
- dwSize = sizeof(tpszDisplayName);
- if
(RegQueryValueEx(hKey,_T("DriverDesc"),NULL,&dwType,(BYTE*)tpszDisplayName,&dwSize)!=
ERROR_SUCCESS)
- _tcscpy(tpszDisplayName,_T("Unnamed Adapter"));
- TRACE("Network card: '%s'\n", debugstr_aw(tpszDisplayName));
-
- // get the link to the Enum Subkey (currently unused)
- //dwType = REG_SZ;
- //dwSize = sizeof(tpszDeviceID);
- //if(RegQueryValueEx(hKey,_T("MatchingDeviceId"),NULL,&dwType,(BYTE*)tpszDeviceID,&dwSize)
!= ERROR_SUCCESS) {
- // WARN("Missing MatchingDeviceId Entry\n");
- // MessageBox(hwndDlg,_T("Missing MatchingDeviceId Entry"),_T("Registry
Problem"),MB_ICONSTOP);
- // return;
- //}
-
- // get the card configuration GUID
- dwType = REG_SZ;
- dwSize = sizeof(tpszCfgInstanceID);
- if(RegQueryValueEx(hKey,_T("NetCfgInstanceId"),NULL,&dwType,(BYTE*)tpszCfgInstanceID,&dwSize)
!= ERROR_SUCCESS)
- {
- ERR("Missing NetCfgInstanceId Entry\n");
- MessageBox(hwndDlg,_T("Missing NetCfgInstanceId Entry"),_T("Registry
Problem"),MB_ICONSTOP);
- return;
- }
-
- ptpszCfgInstanceID = _tcsdup(tpszCfgInstanceID);
- //
- // **TODO** **FIXME** TBD
- // At this point, we should verify, if the device listed here
- // really represents a device that is currently connected to the system
- //
- // How is this done properly ?
-
- nIndex = (int)
SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_ADDSTRING,0,(LPARAM)tpszDisplayName);
- SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_SETITEMDATA,nIndex,(LPARAM)ptpszCfgInstanceID);
- RegCloseKey(hKey);
-}
-
-
-static void
-EnumAdapters(HWND hwndDlg)
-{
- LPTSTR lpRegPath =
_T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}");
-
- EnumRegKeys(NetAdapterCallback,hwndDlg,HKEY_LOCAL_MACHINE,lpRegPath);
- return;
-}
-
-
-static INT_PTR CALLBACK
-NetworkPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- NMHDR* pnmh;
- int nIndex;
- switch(uMsg)
- {
- case WM_INITDIALOG:
- {
- PGLOBAL_NCPA_DATA pGlobalData =
(PGLOBAL_NCPA_DATA)((LPPROPSHEETPAGE)lParam)->lParam;
- if (pGlobalData == NULL)
- return FALSE;
-
- SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
-
- EnableWindow(GetDlgItem(hwndDlg,IDC_ADD),FALSE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_REMOVE),FALSE);
-
- EnumAdapters(hwndDlg);
- SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_SETCURSEL,0,0);
- }
- break;
-
- case WM_NOTIFY:
- pnmh=(NMHDR*)lParam;
- switch(pnmh->code)
- {
- case PSN_APPLY:
- case PSN_RESET:
- while(SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_GETCOUNT,0,0)>0)
- {
- TCHAR *tpszString;
-
- tpszString = (TCHAR*)SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_GETITEMDATA,0,0);
- if(tpszString)
- free(tpszString);
- SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_DELETESTRING,0,0);
- }
- break;
- }
- break;
-
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_NETCARDLIST:
- if(HIWORD(wParam)==LBN_DBLCLK) {
- nIndex = (int) SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_GETCURSEL,0,0);
- if(nIndex!=-1)
- DisplayNICStatus(hwndDlg,(TCHAR*)SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_GETITEMDATA,nIndex,0));
- }
- break;
-
- case IDC_PROPERTIES:
- nIndex = (int) SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_GETCURSEL,0,0);
- if(nIndex!=-1)
- DisplayNICStatus(hwndDlg,(TCHAR*)SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_GETITEMDATA,nIndex,0));
- break;
- }
- break;
- }
-
- return FALSE;
-}
-
-
-
-/* First Applet */
-static LONG CALLBACK
+LONG CALLBACK
DisplayApplet(VOID)
{
- PGLOBAL_NCPA_DATA pGlobalData;
- PROPSHEETPAGE psp[1];
- PROPSHEETHEADER psh = {0};
- TCHAR Caption[1024];
- int Ret;
+ WCHAR szParameters[160];
+ //FIXME
+ // use correct path
+ //::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
- LoadString(hApplet, IDS_CPLSYSTEMNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
+ wcscpy(szParameters,
L"/n,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}");
- pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBAL_NCPA_DATA));
- if (pGlobalData == NULL)
- return 0;
-
- psh.dwSize = sizeof(PROPSHEETHEADER);
- psh.dwFlags = PSH_PROPSHEETPAGE;
- psh.hwndParent = hCPLWindow;
- psh.hInstance = hApplet;
- psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM));
- psh.pszCaption = Caption;
- psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
- psh.nStartPage = 0;
- psh.ppsp = psp;
- psh.pfnCallback = NULL;
-
- InitPropSheetPage(&psp[0], IDD_PROPPAGENETWORK, NetworkPageProc,
(LPARAM)pGlobalData);
-
- Ret = PropertySheet(&psh);
-
- HeapFree(GetProcessHeap(), 0, pGlobalData);
-
- return (LONG)(Ret != -1);
+ return (int) ShellExecuteW(NULL, L"open", L"explorer.exe",
szParameters, NULL, SW_SHOWDEFAULT) > 32;
}
/* Control Panel Callback */
@@ -1056,6 +35,7 @@
UNREFERENCED_PARAMETER(hwndCPl);
switch (uMsg)
{
+
case CPL_INIT:
{
return TRUE;
@@ -1063,23 +43,11 @@
case CPL_GETCOUNT:
{
- return sizeof(Applets)/sizeof(APPLET);
+ return 1;
}
-
- case CPL_INQUIRE:
- {
- CPLINFO *CPlInfo = (CPLINFO*)lParam2;
- CPlInfo->lData = 0;
- CPlInfo->idIcon = Applets[(int)lParam1].idIcon;
- CPlInfo->idName = Applets[(int)lParam1].idName;
- CPlInfo->idInfo = Applets[(int)lParam1].idDescription;
- break;
- }
-
case CPL_DBLCLK:
{
- hCPLWindow = hwndCPl;
- Applets[(int)lParam1].AppletProc();
+ DisplayApplet();
break;
}
}
@@ -1096,7 +64,6 @@
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
- hApplet = hinstDLL;
break;
}
Removed: trunk/reactos/dll/cpl/ncpa/ncpa.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/ncpa/ncpa.h?rev=36…
==============================================================================
--- trunk/reactos/dll/cpl/ncpa/ncpa.h [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/ncpa/ncpa.h (removed)
@@ -1,28 +1,0 @@
-#ifndef __NCPA_H
-#define __NCPA_H
-
-typedef LONG (CALLBACK *CPLAPPLET_PROC)(VOID);
-
-typedef struct
-{
- int idIcon;
- int idName;
- int idDescription;
- CPLAPPLET_PROC AppletProc;
-} APPLET, *PAPPLET;
-
-typedef struct
-{
- WCHAR CurrentAdapterName[MAX_ADAPTER_NAME];
- UINT_PTR hStatsUpdateTimer;
- PMIB_IFTABLE pIfTable;
- DWORD IfTableSize;
- PIP_ADAPTER_INFO pFirstAdapterInfo;
- PIP_ADAPTER_INFO pCurrentAdapterInfo;
-} GLOBAL_NCPA_DATA, *PGLOBAL_NCPA_DATA;
-
-extern HINSTANCE hApplet;
-
-#endif // __NCPA_H
-
-/* EOF */
Modified: trunk/reactos/dll/cpl/ncpa/ncpa.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/ncpa/ncpa.rbuild?r…
==============================================================================
--- trunk/reactos/dll/cpl/ncpa/ncpa.rbuild [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/ncpa/ncpa.rbuild [iso-8859-1] Fri Oct 17 08:19:04 2008
@@ -5,15 +5,8 @@
<include base="ncpa">.</include>
<define name="_WIN32_IE">0x600</define>
<define name="_WIN32_WINNT">0x600</define>
- <library>wine</library>
<library>kernel32</library>
<library>advapi32</library>
- <library>user32</library>
- <library>comctl32</library>
- <library>iphlpapi</library>
- <library>ws2_32</library>
- <library>dhcpcsvc</library>
+ <library>shell32</library>
<file>ncpa.c</file>
- <file>tcpip_properties.c</file>
- <file>ncpa.rc</file>
</module>
Removed: trunk/reactos/dll/cpl/ncpa/ncpa.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/ncpa/ncpa.rc?rev=3…
==============================================================================
--- trunk/reactos/dll/cpl/ncpa/ncpa.rc [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/ncpa/ncpa.rc (removed)
@@ -1,18 +1,0 @@
-/* $Id$ */
-
-#include <windows.h>
-#include "resource.h"
-
-LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
-
-#define REACTOS_VERSION_DLL
-#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Network Control Panel\0"
-#define REACTOS_STR_INTERNAL_NAME "ncpa\0"
-#define REACTOS_STR_ORIGINAL_FILENAME "ncpa.cpl\0"
-
-IDI_CPLSYSTEM ICON "resources/applet.ico"
-IDI_HORIZONTAL ICON "resources/HORIZ.ICO"
-IDI_VERTICAL ICON "resources/VERTIC.ICO"
-IDI_NETSTAT ICON "resources/NETCONN.ICO"
-
-#include "rsrc.rc"
Removed: trunk/reactos/dll/cpl/ncpa/resource.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/ncpa/resource.h?re…
==============================================================================
--- trunk/reactos/dll/cpl/ncpa/resource.h [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/ncpa/resource.h (removed)
@@ -1,86 +1,0 @@
-#ifndef __CPL_RESOURCE_H
-#define __CPL_RESOURCE_H
-
-/* metrics */
-#define PROPSHEETWIDTH 246
-#define PROPSHEETHEIGHT 228
-#define PROPSHEETPADDING 6
-#define SYSTEM_COLUMN (0 * PROPSHEETPADDING)
-// this is not supported by the MS Resource compiler:
-//#define LABELLINE(x) 0 //(((PROPSHEETPADDING + 2) * x) + (x + 2))
-
-#define ICONSIZE 16
-
-/* ids */
-
-#define IDI_CPLSYSTEM 100
-#define IDI_HORIZONTAL 101
-#define IDI_VERTICAL 102
-#define IDI_NETSTAT 103
-
-#define IDD_PROPPAGENETWORK 100
-#define IDD_CARDPROPERTIES 101
-#define IDD_NETPROPERTIES 102
-#define IDD_TCPIPPROPERTIES 103
-#define IDD_CARDSUPPORT 104
-
-#define IDS_CPLSYSTEMNAME 1001
-#define IDS_CPLSYSTEMDESCRIPTION 2001
-#define IDS_ASSIGNED_DHCP 2501
-#define IDS_ASSIGNED_MANUAL 2502
-#define IDS_ERROR 3001
-#define IDS_ENTER_VALID_IPADDRESS 3002
-#define IDS_ENTER_VALID_SUBNET 3003
-#define IDS_CANNOT_LOAD_CONFIG 3004
-#define IDS_CANNOT_CREATE_PROPSHEET 3005
-#define IDS_OUT_OF_MEMORY 3006
-#define IDS_CANNOT_SAVE_CHANGES 3007
-#define IDS_STATUS_NON_OPERATIONAL 4001
-#define IDS_STATUS_UNREACHABLE 4002
-#define IDS_STATUS_DISCONNECTED 4003
-#define IDS_STATUS_CONNECTING 4004
-#define IDS_STATUS_CONNECTED 4005
-#define IDS_STATUS_OPERATIONAL 4006
-#define IDS_SPEED_MBPS 4007
-#define IDS_DURATION_DAY 4008
-#define IDS_DURATION_DAYS 4009
-
-
-/* controls */
-#define IDC_NETCARDLIST 100
-#define IDC_ADD 101
-#define IDC_REMOVE 102
-#define IDC_PROPERTIES 103
-
-#define IDC_NETCARDNAME 104
-#define IDC_CONFIGURE 105
-#define IDC_COMPONENTSLIST 106
-#define IDC_INSTALL 107
-#define IDC_UNINSTALL 108
-//#define IDC_PROPERTIES 109
-#define IDC_DESCRIPTION 110
-#define IDC_SHOWTASKBAR 111
-#define IDC_SEND 112
-#define IDC_RECEIVED 113
-#define IDC_ENDISABLE 114
-#define IDC_USEDHCP 115
-#define IDC_NODHCP 116
-#define IDC_AUTODNS 117
-#define IDC_FIXEDDNS 118
-#define IDC_ADVANCED 119
-#define IDC_IPADDR 120
-#define IDC_SUBNETMASK 121
-#define IDC_DEFGATEWAY 122
-#define IDC_DNS1 123
-#define IDC_DNS2 124
-#define IDC_DETAILS 125
-#define IDC_DETAILSIP 126
-#define IDC_DETAILSTYPE 127
-#define IDC_DETAILSSUBNET 128
-#define IDC_DETAILSGATEWAY 129
-#define IDC_STATUS 130
-#define IDC_DURATION 131
-#define IDC_SPEED 132
-#endif /* __CPL_RESOURCE_H */
-
-/* EOF */
Removed: trunk/reactos/dll/cpl/ncpa/rsrc.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/ncpa/rsrc.rc?rev=3…
==============================================================================
--- trunk/reactos/dll/cpl/ncpa/rsrc.rc [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/ncpa/rsrc.rc (removed)
@@ -1,23 +1,0 @@
-#include <windows.h>
-#include "resource.h"
-
-#include "lang/bg-BG.rc"
-#include "lang/cs-CZ.rc"
-#include "lang/da-DK.rc"
-#include "lang/de-DE.rc"
-#include "lang/el-GR.rc"
-#include "lang/en-US.rc"
-#include "lang/es-ES.rc"
-#include "lang/fr-FR.rc"
-#include "lang/hu-HU.rc"
-#include "lang/id-ID.rc"
-#include "lang/it-IT.rc"
-#include "lang/ja-JP.rc"
-#include "lang/no-NO.rc"
-#include "lang/nl-NL.rc"
-#include "lang/pl-PL.rc"
-#include "lang/ru-RU.rc"
-#include "lang/sk-SK.rc"
-#include "lang/sv-SE.rc"
-#include "lang/uk-UA.rc"
-#include "lang/zh-CN.rc"
Removed: trunk/reactos/dll/cpl/ncpa/tcpip_properties.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/ncpa/tcpip_propert…
==============================================================================
--- trunk/reactos/dll/cpl/ncpa/tcpip_properties.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/ncpa/tcpip_properties.c (removed)
@@ -1,560 +1,0 @@
-/*
- * PROJECT: ReactOS Network Control Panel
- * LICENSE: GPL - See COPYING in the top level directory
- * FILE: lib/cpl/system/tcpip_properties.c
- * PURPOSE: ReactOS Network Control Panel
- * COPYRIGHT: Copyright 2004 Gero Kuehn (reactos.filter(a)gkware.com)
- * Copyright 2006 Ge van Geldorp <gvg(a)reactos.org>
- */
-
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <tchar.h>
-#include <windows.h>
-#include <iptypes.h>
-#include <iphlpapi.h>
-#include <commctrl.h>
-#include <dhcpcapi.h>
-#include <prsht.h>
-
-
-#ifdef _MSC_VER
-#include <cpl.h>
-#endif
-
-#include "resource.h"
-#include "ncpa.h"
-
-#include <wine/debug.h>
-WINE_DEFAULT_DEBUG_CHANNEL(ncpa);
-
-typedef struct _TCPIP_PROPERTIES_DATA {
- DWORD AdapterIndex;
- char *AdapterName;
- BOOL DhcpEnabled;
- DWORD IpAddress;
- DWORD SubnetMask;
- DWORD Gateway;
- DWORD Dns1;
- DWORD Dns2;
- BOOL OldDhcpEnabled;
- DWORD OldIpAddress;
- DWORD OldSubnetMask;
- DWORD OldGateway;
- DWORD OldDns1;
- DWORD OldDns2;
-} TCPIP_PROPERTIES_DATA, *PTCPIP_PROPERTIES_DATA;
-
-void InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPARAM lParam);
-
-DWORD APIENTRY DhcpNotifyConfigChange(LPWSTR ServerName, LPWSTR AdapterName,
- BOOL NewIpAddress, DWORD IpIndex,
- DWORD IpAddress, DWORD SubnetMask,
- int DhcpAction);
-
-
-static void
-ManualDNS(HWND Dlg, BOOL Enabled, UINT uCmd) {
- PTCPIP_PROPERTIES_DATA DlgData =
- (PTCPIP_PROPERTIES_DATA) GetWindowLongPtrW(Dlg, GWL_USERDATA);
-
- if (! DlgData->OldDhcpEnabled &&
- (uCmd == IDC_USEDHCP || uCmd == IDC_NODHCP)) {
- if (INADDR_NONE != DlgData->OldIpAddress) {
- SendDlgItemMessage(Dlg, IDC_IPADDR, IPM_SETADDRESS, 0,
- ntohl(DlgData->OldIpAddress));
- }
- if (INADDR_NONE != DlgData->OldSubnetMask) {
- SendDlgItemMessage(Dlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0,
- ntohl(DlgData->OldSubnetMask));
- }
- if (INADDR_NONE != DlgData->OldGateway) {
- SendDlgItemMessage(Dlg, IDC_DEFGATEWAY, IPM_SETADDRESS, 0,
- ntohl(DlgData->OldGateway));
- }
- }
-
- if (INADDR_NONE != DlgData->OldDns1 &&
- (uCmd == IDC_FIXEDDNS || uCmd == IDC_AUTODNS || IDC_NODHCP)) {
- SendDlgItemMessage(Dlg, IDC_DNS1, IPM_SETADDRESS, 0,
- ntohl(DlgData->OldDns1));
- if (INADDR_NONE != DlgData->OldDns2) {
- SendDlgItemMessage(Dlg, IDC_DNS2, IPM_SETADDRESS, 0,
- ntohl(DlgData->OldDns2));
- }
- }
-
- CheckDlgButton(Dlg, IDC_FIXEDDNS,
- Enabled ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(Dlg, IDC_AUTODNS,
- Enabled ? BST_UNCHECKED : BST_CHECKED);
- EnableWindow(GetDlgItem(Dlg, IDC_DNS1), Enabled);
- EnableWindow(GetDlgItem(Dlg, IDC_DNS2), FALSE/*Enabled*/);
- if (! Enabled) {
- SendDlgItemMessage(Dlg, IDC_DNS1, IPM_CLEARADDRESS, 0, 0);
- SendDlgItemMessage(Dlg, IDC_DNS2, IPM_CLEARADDRESS, 0, 0);
-
- }
-}
-
-static void
-EnableDHCP(HWND Dlg, BOOL Enabled, UINT uCmd) {
- CheckDlgButton(Dlg, IDC_USEDHCP, Enabled ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(Dlg, IDC_NODHCP, Enabled ? BST_UNCHECKED : BST_CHECKED);
- EnableWindow(GetDlgItem(Dlg, IDC_IPADDR), ! Enabled);
- EnableWindow(GetDlgItem(Dlg, IDC_SUBNETMASK), ! Enabled);
- EnableWindow(GetDlgItem(Dlg, IDC_DEFGATEWAY), ! Enabled);
- EnableWindow(GetDlgItem(Dlg, IDC_AUTODNS), Enabled);
- if (Enabled) {
- SendDlgItemMessage(Dlg, IDC_IPADDR, IPM_CLEARADDRESS, 0, 0);
- SendDlgItemMessage(Dlg, IDC_SUBNETMASK, IPM_CLEARADDRESS, 0, 0);
- SendDlgItemMessage(Dlg, IDC_DEFGATEWAY, IPM_CLEARADDRESS, 0, 0);
- } else {
- ManualDNS(Dlg, TRUE, uCmd);
- }
-}
-
-static void
-ShowError(HWND Parent, UINT MsgId)
-{
- WCHAR Error[32], Msg[64];
-
- if (0 == LoadStringW((HINSTANCE) GetWindowLongPtrW(Parent, GWLP_HINSTANCE),
- IDS_ERROR, Error, sizeof(Error) / sizeof(Error[0]))) {
- wcscpy(Error, L"Error");
- }
- if (0 == LoadStringW((HINSTANCE) GetWindowLongPtrW(Parent, GWLP_HINSTANCE),
- MsgId, Msg, sizeof(Msg) / sizeof(Msg[0]))) {
- wcscpy(Msg, L"Unknown error");
- }
- ERR("%s\n", debugstr_w(Msg));
- MessageBoxW(Parent, Msg, Error, MB_OK | MB_ICONSTOP);
-}
-
-static
-BOOL GetAddressFromField( HWND hwndDlg, UINT CtlId,
- DWORD *dwIPAddr,
- const char **AddressString ) {
- LRESULT lResult;
- struct in_addr inIPAddr;
-
- *AddressString = NULL;
-
- lResult = SendMessage(GetDlgItem(hwndDlg, CtlId), IPM_GETADDRESS, 0,
- (ULONG_PTR)dwIPAddr);
- if( lResult != 4 ) return FALSE;
-
- *dwIPAddr = htonl(*dwIPAddr);
- inIPAddr.s_addr = *dwIPAddr;
- *AddressString = inet_ntoa(inIPAddr);
- if( !*AddressString ) return FALSE;
-
- return TRUE;
-}
-
-static BOOL
-ValidateAndStore(HWND Dlg, PTCPIP_PROPERTIES_DATA DlgData)
-{
- DWORD IpAddress;
- MIB_IPFORWARDROW RowToAdd = { 0 }, RowToRem = { 0 };
-
- DlgData->DhcpEnabled = (BST_CHECKED ==
- IsDlgButtonChecked(Dlg, IDC_USEDHCP));
- if (! DlgData->DhcpEnabled) {
- DhcpReleaseIpAddressLease( DlgData->AdapterIndex );
-
- if (4 != SendMessageW(GetDlgItem(Dlg, IDC_IPADDR), IPM_GETADDRESS,
- 0, (LPARAM) &IpAddress)) {
- ShowError(Dlg, IDS_ENTER_VALID_IPADDRESS);
- SetFocus(GetDlgItem(Dlg, IDC_IPADDR));
- return FALSE;
- }
- DlgData->IpAddress = htonl(IpAddress);
- if (4 != SendMessageW(GetDlgItem(Dlg, IDC_SUBNETMASK), IPM_GETADDRESS,
- 0, (LPARAM) &IpAddress)) {
- ShowError(Dlg, IDS_ENTER_VALID_SUBNET);
- SetFocus(GetDlgItem(Dlg, IDC_SUBNETMASK));
- return FALSE;
- }
- DlgData->SubnetMask = htonl(IpAddress);
- if (4 != SendMessageW(GetDlgItem(Dlg, IDC_DEFGATEWAY), IPM_GETADDRESS,
- 0, (LPARAM) &IpAddress)) {
- DlgData->Gateway = INADDR_NONE;
- } else {
- DlgData->Gateway = htonl(IpAddress);
- }
- DhcpStaticRefreshParams
- ( DlgData->AdapterIndex, DlgData->IpAddress, DlgData->SubnetMask );
-
- RowToRem.dwForwardMask = 0;
- RowToRem.dwForwardMetric1 = 1;
- RowToRem.dwForwardNextHop = DlgData->OldGateway;
-
- DeleteIpForwardEntry( &RowToRem );
-
- RowToAdd.dwForwardMask = 0;
- RowToAdd.dwForwardMetric1 = 1;
- RowToAdd.dwForwardNextHop = DlgData->Gateway;
-
- CreateIpForwardEntry( &RowToAdd );
- assert(BST_CHECKED == IsDlgButtonChecked(Dlg, IDC_FIXEDDNS));
- } else {
- DlgData->IpAddress = INADDR_NONE;
- DlgData->SubnetMask = INADDR_NONE;
- DlgData->Gateway = INADDR_NONE;
- DhcpLeaseIpAddress( DlgData->AdapterIndex );
- }
-
- if (BST_CHECKED == IsDlgButtonChecked(Dlg, IDC_FIXEDDNS)) {
- if (4 != SendMessageW(GetDlgItem(Dlg, IDC_DNS1), IPM_GETADDRESS,
- 0, (LPARAM) &IpAddress)) {
- DlgData->Dns1 = INADDR_NONE;
- } else {
- DlgData->Dns1 = htonl(IpAddress);
- }
- if (4 != SendMessageW(GetDlgItem(Dlg, IDC_DNS2), IPM_GETADDRESS,
- 0, (LPARAM) &IpAddress)) {
- DlgData->Dns2 = INADDR_NONE;
- } else {
- DlgData->Dns2 = htonl(IpAddress);
- }
- } else {
- DlgData->Dns1 = INADDR_NONE;
- DlgData->Dns2 = INADDR_NONE;
- }
-
- return TRUE;
-}
-
-static BOOL
-InternTCPIPSettings(HWND Dlg, PTCPIP_PROPERTIES_DATA DlgData) {
- /*BOOL Changed;
- BOOL IpChanged;
- int DhcpAction;
- LPWSTR AdapterName;*/
- BOOL SetIpAddressByDhcp;
- BOOL SetDnsByDhcp;
- TCHAR pszRegKey[MAX_PATH];
- const char *AddressString;
- char emptyString[]="\0";
- DWORD Address = 0;
- LONG rc;
- HKEY hKey = NULL;
- BOOL ret = FALSE;
-
- if (! ValidateAndStore(Dlg, DlgData)) {
- /* Should never happen, we should have validated at PSN_KILLACTIVE */
- assert(FALSE);
- return FALSE;
- }
-
- SetIpAddressByDhcp = IsDlgButtonChecked(Dlg, IDC_USEDHCP);
- SetDnsByDhcp = IsDlgButtonChecked(Dlg, IDC_AUTODNS);
-
- /* Save parameters in HKLM\SYSTEM\CurrentControlSet\Services\{GUID}\Parameters\Tcpip
*/
-
_stprintf(pszRegKey,_T("SYSTEM\\CurrentControlSet\\Services\\%S\\Parameters\\Tcpip"),
DlgData->AdapterName);
- rc = RegOpenKey(HKEY_LOCAL_MACHINE, pszRegKey, &hKey);
- if (rc != ERROR_SUCCESS)
- goto cleanup;
- if (SetIpAddressByDhcp)
- AddressString = "0.0.0.0";
- else if (!GetAddressFromField(Dlg, IDC_IPADDR, &Address, &AddressString))
- goto cleanup;
- rc = RegSetValueExA(hKey, "IPAddress", 0, REG_SZ, (const
BYTE*)AddressString, strlen(AddressString) + 1);
- if (rc != ERROR_SUCCESS)
- goto cleanup;
- if (!SetIpAddressByDhcp && !GetAddressFromField(Dlg, IDC_SUBNETMASK,
&Address, &AddressString))
- goto cleanup;
- rc = RegSetValueExA(hKey, "SubnetMask", 0, REG_SZ, (const
BYTE*)AddressString, strlen(AddressString) + 1);
- if (rc != ERROR_SUCCESS)
- goto cleanup;
- if (!SetIpAddressByDhcp && !GetAddressFromField(Dlg, IDC_DEFGATEWAY,
&Address, &AddressString))
- goto cleanup;
- rc = RegSetValueExA(hKey, "DefaultGateway", 0, REG_SZ, (const
BYTE*)AddressString, strlen(AddressString) + 1);
- if (rc != ERROR_SUCCESS)
- goto cleanup;
- RegCloseKey(hKey);
-
- /* Save parameters in HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters */
- rc = RegOpenKey(HKEY_LOCAL_MACHINE,
_T("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"), &hKey);
- if (rc != ERROR_SUCCESS)
- goto cleanup;
- if (DlgData->Dns1 == INADDR_NONE)
- {
- rc = RegSetValueExA(hKey, "NameServer",0, REG_SZ, (const
BYTE*)emptyString, strlen(emptyString) + 1);
- if (rc != ERROR_SUCCESS && rc != ERROR_FILE_NOT_FOUND)
- goto cleanup;
- }
- else
- {
- if (!GetAddressFromField(Dlg, IDC_DNS1, &Address, &AddressString))
- goto cleanup;
- rc = RegSetValueExA(hKey, "NameServer", 0, REG_SZ, (const
BYTE*)AddressString, strlen(AddressString) + 1);
- if (rc != ERROR_SUCCESS)
- goto cleanup;
- }
-
- ret = TRUE;
-
-cleanup:
- if (hKey != NULL)
- RegCloseKey(hKey);
- return ret;
-#if 0
- Changed = FALSE;
- if (DlgData->DhcpEnabled) {
- Changed = ! DlgData->OldDhcpEnabled;
- IpChanged = FALSE;
- DhcpAction = 1;
- } else {
- Changed = DlgData->OldDhcpEnabled ||
- DlgData->IpAddress != DlgData->OldIpAddress ||
- DlgData->SubnetMask != DlgData->OldSubnetMask;
- IpChanged = DlgData->OldDhcpEnabled ||
- DlgData->IpAddress != DlgData->OldIpAddress;
- DhcpAction = 2;
- }
-
- if (Changed) {
- AdapterName = HeapAlloc(GetProcessHeap(), 0,
- (strlen(DlgData->AdapterName) + 1) *
- sizeof(WCHAR));
- if (NULL == AdapterName) {
- ShowError(Dlg, IDS_OUT_OF_MEMORY);
- return FALSE;
- }
- MultiByteToWideChar(CP_THREAD_ACP, 0, DlgData->AdapterName, -1,
- AdapterName, strlen(DlgData->AdapterName) + 1);
- if (0 == DhcpNotifyConfigChange(NULL, AdapterName, IpChanged,
- DlgData->AdapterIndex,
- DlgData->IpAddress,
- DlgData->SubnetMask, DhcpAction)) {
- HeapFree(GetProcessHeap(), 0, AdapterName);
- ShowError(Dlg, IDS_CANNOT_SAVE_CHANGES);
- return FALSE;
- }
- HeapFree(GetProcessHeap(), 0, AdapterName);
- }
-
- /* FIXME Save default gateway and DNS entries */
- return TRUE;
-#endif
-}
-
-static INT_PTR CALLBACK
-TCPIPPropertyPageProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- LPPROPSHEETPAGEW Page;
- PTCPIP_PROPERTIES_DATA DlgData;
- LPNMHDR Nmhdr;
-
- DlgData = (PTCPIP_PROPERTIES_DATA) GetWindowLongPtrW(Dlg, GWL_USERDATA);
- switch(uMsg) {
- case WM_INITDIALOG:
- Page = (LPPROPSHEETPAGEW) lParam;
- DlgData = (PTCPIP_PROPERTIES_DATA) Page->lParam;
- SetWindowLongPtrW(Dlg, GWL_USERDATA, Page->lParam);
-
- EnableWindow(GetDlgItem(Dlg, IDC_ADVANCED), FALSE);
-
- EnableDHCP(Dlg, DlgData->OldDhcpEnabled, 0);
-
- if (! DlgData->OldDhcpEnabled)
- {
- if (INADDR_NONE != DlgData->OldIpAddress) {
- SendDlgItemMessage(Dlg, IDC_IPADDR, IPM_SETADDRESS, 0,
- ntohl(DlgData->OldIpAddress));
- }
- if (INADDR_NONE != DlgData->OldSubnetMask) {
- SendDlgItemMessage(Dlg, IDC_SUBNETMASK, IPM_SETADDRESS, 0,
- ntohl(DlgData->OldSubnetMask));
- }
- if (INADDR_NONE != DlgData->OldGateway) {
- SendDlgItemMessage(Dlg, IDC_DEFGATEWAY, IPM_SETADDRESS, 0,
- ntohl(DlgData->OldGateway));
- }
- }
-
- if (INADDR_NONE != DlgData->OldDns1) {
- SendDlgItemMessage(Dlg, IDC_DNS1, IPM_SETADDRESS, 0,
- ntohl(DlgData->OldDns1));
- if (INADDR_NONE != DlgData->OldDns2) {
- SendDlgItemMessage(Dlg, IDC_DNS2, IPM_SETADDRESS, 0,
- ntohl(DlgData->OldDns2));
- }
- }
-
- if (DlgData->OldDhcpEnabled)
- {
- ManualDNS(Dlg, INADDR_NONE != DlgData->OldDns1, 0);
- }
-
- break;
-
- case WM_COMMAND:
- switch(LOWORD(wParam)) {
- case IDC_FIXEDDNS:
- ManualDNS(Dlg, TRUE, LOWORD(wParam));
- return TRUE;
-
- case IDC_AUTODNS:
- ManualDNS(Dlg, FALSE, LOWORD(wParam));
- return TRUE;
-
- case IDC_USEDHCP:
- EnableDHCP(Dlg, TRUE, LOWORD(wParam));
- return TRUE;
-
- case IDC_NODHCP:
- EnableDHCP(Dlg, FALSE, LOWORD(wParam));
- return TRUE;
- }
- break;
-
- case WM_NOTIFY:
- Nmhdr = (LPNMHDR) lParam;
-
- switch(Nmhdr->code) {
- case PSN_KILLACTIVE:
- /* Do validation here, must set FALSE to continue */
- SetWindowLongPtrW(Dlg, DWL_MSGRESULT,
- (LONG_PTR) ! ValidateAndStore(Dlg, DlgData));
- return TRUE;
-
- case PSN_APPLY:
- /* Set the IP Address and DNS Information so we won't
- * be doing all this for nothing */
- SetWindowLongPtrW(Dlg, DWL_MSGRESULT,
- InternTCPIPSettings(Dlg, DlgData) ?
- PSNRET_NOERROR : PSNRET_INVALID);
- return TRUE;
- }
- break;
- }
-
- return FALSE;
-}
-
-static BOOL
-LoadDataFromInfo(PTCPIP_PROPERTIES_DATA DlgData, IP_ADAPTER_INFO *Info)
-{
- IP_ADDR_STRING *pString;
- WCHAR RegKey[MAX_PATH];
- HKEY hKey;
- char Dns[MAX_PATH];
- DWORD Size;
- DWORD Type;
- DWORD dwError;
- char *NextDnsServer;
-
- DlgData->AdapterName = Info->AdapterName;
- DlgData->AdapterIndex = Info->Index;
-
- DlgData->OldDhcpEnabled = Info->DhcpEnabled;
-
- pString = &Info->IpAddressList;
- while (NULL != pString->Next) {
- pString = pString->Next;
- }
- DlgData->OldIpAddress = inet_addr(pString->IpAddress.String);
- DlgData->OldSubnetMask = inet_addr(pString->IpMask.String);
- pString = &Info->GatewayList;
- while (NULL != pString->Next) {
- pString = pString->Next;
- }
- DlgData->OldGateway = inet_addr(pString->IpAddress.String);
-
- DlgData->OldDns1 = INADDR_NONE;
- DlgData->OldDns2 = INADDR_NONE;
- swprintf(RegKey,
-
L"SYSTEM\\CurrentControlSet\\Services\\TCPIP\\Parameters\\Interfaces\\%S",
- Info->AdapterName);
- dwError = RegOpenKeyW(HKEY_LOCAL_MACHINE, RegKey, &hKey);
- if (dwError != ERROR_SUCCESS)
- {
- /* Try and fall back on the NameServer in Parameters */
- swprintf(RegKey,
- L"SYSTEM\\CurrentControlSet\\Services\\TCPIP\\Parameters\\");
- }
- dwError = RegOpenKeyW(HKEY_LOCAL_MACHINE, RegKey, &hKey);
- if (ERROR_SUCCESS == dwError) {
- Size = sizeof(Dns);
- RegQueryValueExA(hKey, "NameServer", NULL, &Type, (BYTE *)Dns,
- &Size);
- RegCloseKey(hKey);
-
- if ('\0' != Dns[0]) {
- DlgData->OldDns1 = inet_addr(Dns);
- NextDnsServer = strchr(Dns, ',');
- if (NULL != NextDnsServer && '\0' != *NextDnsServer) {
- DlgData->OldDns2 = inet_addr(NextDnsServer);
- }
- }
- }
-
- return TRUE;
-}
-
-void
-DisplayTCPIPProperties(HWND hParent, IP_ADAPTER_INFO *pInfo)
-{
- PROPSHEETPAGEW psp[1];
- PROPSHEETHEADERW psh;
- INITCOMMONCONTROLSEX cce;
- TCPIP_PROPERTIES_DATA DlgData;
- LPTSTR tpszCaption = NULL;
- INT StrLen;
-
- HWND hListBox = GetDlgItem(hParent, IDC_COMPONENTSLIST);
- int iListBoxIndex = (int) SendMessage(hListBox, LB_GETCURSEL, 0, 0);
-
- if(iListBoxIndex != LB_ERR)
- {
- StrLen = SendMessage(hListBox, LB_GETTEXTLEN, iListBoxIndex, 0);
-
- if (StrLen != LB_ERR)
- {
- TCHAR suffix[] = _T(" Properties");
- INT HeapSize = ((StrLen + 1) + (_tcslen(suffix) + 1)) * sizeof(TCHAR);
- tpszCaption = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, HeapSize);
- SendMessage(hListBox, LB_GETTEXT, iListBoxIndex, (LPARAM)tpszCaption);
- _tcscat(tpszCaption, suffix);
- }
- }
-
- if (! LoadDataFromInfo(&DlgData, pInfo))
- {
- ShowError(hParent, IDS_CANNOT_LOAD_CONFIG);
- return;
- }
-
- cce.dwSize = sizeof(INITCOMMONCONTROLSEX);
- cce.dwICC = ICC_INTERNET_CLASSES;
- InitCommonControlsEx(&cce);
-
- ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
- psh.dwSize = sizeof(PROPSHEETHEADER);
- psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
- psh.hwndParent = hParent;
- psh.hInstance = hApplet;
- psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM));
- psh.pszCaption = tpszCaption;
- psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
- psh.nStartPage = 0;
- psh.ppsp = psp;
- psh.pfnCallback = NULL;
-
- InitPropSheetPage(&psp[0], IDD_TCPIPPROPERTIES, TCPIPPropertyPageProc, (LPARAM)
&DlgData);
-
- if (PropertySheetW(&psh) == -1)
- {
- ShowError(hParent, IDS_CANNOT_CREATE_PROPSHEET);
- }
-
- if (tpszCaption != NULL)
- HeapFree(GetProcessHeap(), 0, tpszCaption);
-
- return;
-}