2 * Copyright 2004 Gero Kuehn
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 /* $Id: ncpa.c,v 1.4 2004/10/11 21:08:04 weiden Exp $
20 * PROJECT: ReactOS Network Control Panel
21 * FILE: lib/cpl/system/ncpa.c
22 * PURPOSE: ReactOS Network Control Panel
23 * PROGRAMMER: Gero Kuehn (reactos.filter@gkware.com)
28 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
29 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
33 // This file contains a first attempt for reactos network configuration
36 // - not the way it works on Windows
38 // A lot of code that can be found here now, will probably be relocated into the OS core or some
39 // protocol Co-Installers or Notify Objects later when all the required COM
40 // and "netcfgx.dll" infrastructure (esp. headers and Interfaces) get implemented step by step.
42 // This code is only a first approach to provide a usable network configuration dialogs for
43 // the new network support in Reactos.
45 // If you intend to extend this code by more, please contact me to avoid duplicate work.
46 // There are already resources and code for TCP/IP configuration that are not
47 // mature enough for committing them to CVS yet.
49 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
50 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 //#include <Netcfgn.h>
68 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
69 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
71 #define NCF_HIDDEN 0x08
72 #define NCF_HAS_UI 0x80
74 typedef void (ENUMREGKEYCALLBACK
)(void *pCookie
,HKEY hBaseKey
,TCHAR
*pszSubKey
);
75 void EnumRegKeys(ENUMREGKEYCALLBACK
*pCallback
,void *pCookie
,HKEY hBaseKey
,TCHAR
*tpszRegPath
)
80 TCHAR tpszName
[MAX_PATH
];
81 DWORD dwNameLen
= sizeof(tpszName
);
82 if(RegOpenKeyEx(hBaseKey
,tpszRegPath
,0,KEY_ALL_ACCESS
,&hKey
)!=ERROR_SUCCESS
)
84 OutputDebugString(_T("EnumRegKeys failed (key not found)\r\n"));
85 OutputDebugString(tpszRegPath
);
86 OutputDebugString(_T("\r\n"));
92 TCHAR pszNewPath
[MAX_PATH
];
93 ret
= RegEnumKeyEx(hKey
,i
,tpszName
,&dwNameLen
,NULL
,NULL
,NULL
,NULL
);
94 if(ret
!= ERROR_SUCCESS
)
96 OutputDebugString(_T("EnumRegKeys: RegEnumKeyEx failed for\r\n"));
97 OutputDebugString(tpszName
);
98 OutputDebugString(_T("\r\n"));
102 _stprintf(pszNewPath
,_T("%s\\%s"),tpszRegPath
,tpszName
);
103 OutputDebugString(_T("EnumRegKeys: Calling user supplied enum function\r\n"));
104 pCallback(pCookie
,hBaseKey
,pszNewPath
);
106 dwNameLen
= sizeof(tpszName
);
111 void InitPropSheetPage(PROPSHEETPAGE
*psp
, WORD idDlg
, DLGPROC DlgProc
,LPARAM lParam
)
113 ZeroMemory(psp
, sizeof(PROPSHEETPAGE
));
114 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
115 psp
->dwFlags
= PSP_DEFAULT
;
116 psp
->hInstance
= hApplet
;
118 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
120 psp
->u1
.pszTemplate
= MAKEINTRESOURCE(idDlg
);
122 psp
->pfnDlgProc
= DlgProc
;
123 psp
->lParam
= lParam
;
126 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
127 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
131 LONG CALLBACK
DisplayApplet(VOID
);
132 INT_PTR CALLBACK
NetworkPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
133 void DisplayTCPIPProperties(HWND hParent
,IP_ADAPTER_INFO
*pInfo
);
135 HINSTANCE hApplet
= 0;
140 {IDI_CPLSYSTEM
, IDS_CPLSYSTEMNAME
, IDS_CPLSYSTEMDESCRIPTION
, DisplayApplet
}
147 BOOL
FindNICClassKeyForCfgInstance(TCHAR
*tpszCfgInst
,TCHAR
*tpszSubKeyOut
)
150 TCHAR tpszSubKey
[MAX_PATH
];
151 TCHAR tpszCfgInst2
[MAX_PATH
];
156 _stprintf(tpszSubKey
,_T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%04d"),i
);
157 if(RegOpenKey(HKEY_LOCAL_MACHINE
,tpszSubKey
,&hKey
)!=ERROR_SUCCESS
)
160 dwSize
= sizeof(tpszCfgInst2
);
161 if(RegQueryValueEx(hKey
,_T("NetCfgInstanceId"),NULL
,&dwType
,(BYTE
*)tpszCfgInst2
,&dwSize
)!=ERROR_SUCCESS
) {
166 if(_tcscmp(tpszCfgInst
,tpszCfgInst2
)==0) {
167 _tcscpy(tpszSubKeyOut
,tpszSubKey
);
175 void NICPropertyProtocolCallback(void *pCookie
,HKEY hBaseKey
,TCHAR
*tpszSubKey
)
178 DWORD dwCharacteristics
;
181 TCHAR tpszDescription
[MAX_PATH
];
182 TCHAR tpszNotifyObjectCLSID
[MAX_PATH
];
183 TCHAR
*tpszSubKeyCopy
;
185 // CLSID CLSID_NotifObj;
186 // IUnknown *pUnk = NULL;
187 // INetCfgComponentControl *pNetCfg;
188 // INetCfgComponentPropertyUi *pNetCfgPropUI;
189 hwndDlg
= (HWND
)pCookie
;
191 if(RegOpenKey(HKEY_LOCAL_MACHINE
,tpszSubKey
,&hKey
)!=ERROR_SUCCESS
)
194 dwSize
= sizeof(dwCharacteristics
);
195 if(RegQueryValueEx(hKey
,_T("Characteristics"),NULL
,&dwType
,(BYTE
*)&dwCharacteristics
,&dwSize
)!= ERROR_SUCCESS
)
197 if(dwCharacteristics
& NCF_HIDDEN
) {
203 dwSize
= sizeof(tpszDescription
);
204 if(RegQueryValueEx(hKey
,_T("Description"),NULL
,&dwType
,(BYTE
*)tpszDescription
,&dwSize
)!= ERROR_SUCCESS
)
207 RegOpenKey(hKey
,_T("Ndi"),&hNDIKey
);
209 dwSize
= sizeof(tpszNotifyObjectCLSID
);
210 if(RegQueryValueEx(hNDIKey
,_T("ClsId"),NULL
,&dwType
,(BYTE
*)tpszNotifyObjectCLSID
,&dwSize
)!= ERROR_SUCCESS
)
212 RegCloseKey(hNDIKey
);
215 // This code works on Windows... but not on Reactos
218 // CLSIDFromString(tpszNotifyObjectCLSID,&CLSID_NotifObj);
219 // CoCreateInstance(&CLSID_NotifObj,NULL,CLSCTX_INPROC_SERVER,&IID_IUnknown,(void**)&pUnk);
220 // pUnk->lpVtbl->QueryInterface(pUnk,&IID_INetCfgComponentControl,(void**)&pNetCfg);
221 // pUnk->lpVtbl->QueryInterface(pUnk,&IID_INetCfgComponentPropertyUi,(void**)&pNetCfgPropUI);
225 hr = pNetCfg->lpVtbl->Initialize(pNetCfg,&NetCfgComponent,&NetCfg,FALSE);
226 hr = pNetCfgPropUI->lpVtbl->QueryPropertyUi(pNetCfgPropUI,(INetCfg*)&NetCfg);
227 hr = pNetCfgPropUI->lpVtbl->SetContext(pNetCfgPropUI,(INetCfg*)&NetCfgComponent);
228 DWORD dwNumPages = 10;
229 HPROPSHEETPAGE *bOut = NULL;
231 hr = pNetCfgPropUI->MergePropPages(&dwNumPages,(BYTE**)&bOut,&nPages,GetDesktopWindow(),NULL);
236 nIndex
= SendDlgItemMessage(hwndDlg
,IDC_COMPONENTSLIST
,LB_ADDSTRING
,0,(LPARAM
)tpszDescription
);
237 tpszSubKeyCopy
= _tcsdup(tpszSubKey
);
238 SendDlgItemMessage(hwndDlg
,IDC_COMPONENTSLIST
,LB_SETITEMDATA
,nIndex
,(LPARAM
)tpszSubKeyCopy
);
244 NICPropertyPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
246 PROPSHEETPAGE
*pPage
= (PROPSHEETPAGE
*)GetWindowLongPtr(hwndDlg
,GWL_USERDATA
);
251 TCHAR
*tpszCfgInstanceID
;
253 TCHAR tpszSubKey
[MAX_PATH
];
254 TCHAR tpszDisplayName
[MAX_PATH
];
256 pPage
= (PROPSHEETPAGE
*)lParam
;
257 tpszCfgInstanceID
= (TCHAR
*)pPage
->lParam
;
258 if(!FindNICClassKeyForCfgInstance(tpszCfgInstanceID
,tpszSubKey
))
260 MessageBox(hwndDlg
,_T("NIC Entry not found"),_T("Registry error"),MB_ICONSTOP
);
261 MessageBox(hwndDlg
,tpszCfgInstanceID
,tpszSubKey
,MB_ICONSTOP
);
264 if(RegOpenKey(HKEY_LOCAL_MACHINE
,tpszSubKey
,&hKey
)!=ERROR_SUCCESS
)
267 dwSize
= sizeof(tpszDisplayName
);
268 if(RegQueryValueEx(hKey
,_T("DriverDesc"),NULL
,&dwType
,(BYTE
*)tpszDisplayName
,&dwSize
)!= ERROR_SUCCESS
)
272 SetDlgItemText(hwndDlg
,IDC_NETCARDNAME
,tpszDisplayName
);
273 EnableWindow(GetDlgItem(hwndDlg
,IDC_CONFIGURE
),FALSE
);
276 SetWindowLongPtr(hwndDlg
,GWL_USERDATA
,(DWORD_PTR
)lParam
);
277 //SetDlgItemTextA(hwndDlg,IDC_NETCARDNAME,Info[pPage->lParam].Description);
278 EnumRegKeys(NICPropertyProtocolCallback
,hwndDlg
,HKEY_LOCAL_MACHINE
,_T("System\\CurrentControlSet\\Control\\Network\\{4D36E975-E325-11CE-BFC1-08002BE10318}"));
283 switch(LOWORD(wParam
))
285 case IDC_COMPONENTSLIST
:
286 if(HIWORD(wParam
)==LBN_SELCHANGE
)
289 TCHAR tpszHelpKey
[MAX_PATH
];
290 TCHAR tpszHelpText
[MAX_PATH
];
293 HWND hListBox
= GetDlgItem(hwndDlg
,IDC_COMPONENTSLIST
);
294 tpszSubKey
= (TCHAR
*)SendMessage(hListBox
,LB_GETITEMDATA
,SendMessage(hListBox
,LB_GETCURSEL
,0,0),0);
297 _stprintf(tpszHelpKey
,_T("%s\\Ndi"),tpszSubKey
);
299 RegOpenKey(HKEY_LOCAL_MACHINE
,tpszHelpKey
,&hNDIKey
);
301 dwSize
= sizeof(tpszHelpText
);
302 if(RegQueryValueEx(hNDIKey
,_T("HelpText"),NULL
,&dwType
,(BYTE
*)tpszHelpText
,&dwSize
)!= ERROR_SUCCESS
)
304 RegCloseKey(hNDIKey
);
306 SetDlgItemText(hwndDlg
,IDC_DESCRIPTION
,tpszHelpText
);
309 if(HIWORD(wParam
)!=LBN_DBLCLK
)
315 TCHAR tpszNDIKey
[MAX_PATH
];
316 TCHAR tpszClsIDText
[MAX_PATH
];
317 TCHAR
*tpszTCPIPClsID
= _T("{A907657F-6FDF-11D0-8EFB-00C04FD912B2}");
320 HWND hListBox
= GetDlgItem(hwndDlg
,IDC_COMPONENTSLIST
);
321 tpszSubKey
= (TCHAR
*)SendMessage(hListBox
,LB_GETITEMDATA
,SendMessage(hListBox
,LB_GETCURSEL
,0,0),0);
324 _stprintf(tpszNDIKey
,_T("%s\\Ndi"),tpszSubKey
);
326 RegOpenKey(HKEY_LOCAL_MACHINE
,tpszNDIKey
,&hNDIKey
);
328 dwSize
= sizeof(tpszClsIDText
);
329 if(RegQueryValueEx(hNDIKey
,_T("ClsId"),NULL
,&dwType
,(BYTE
*)tpszClsIDText
,&dwSize
)!= ERROR_SUCCESS
)
331 RegCloseKey(hNDIKey
);
333 if(_tcscmp(tpszTCPIPClsID
,tpszClsIDText
)==0)
335 IP_ADAPTER_INFO Adapters
[64];
336 IP_ADAPTER_INFO
*pAdapter
;
337 TCHAR
*tpszCfgInstanceID
;
338 DWORD dwSize
= sizeof(Adapters
);
339 memset(&Adapters
,0x00,sizeof(Adapters
));
340 if(GetAdaptersInfo(Adapters
,&dwSize
)!=ERROR_SUCCESS
)
343 tpszCfgInstanceID
= (TCHAR
*)pPage
->lParam
;
346 TCHAR tpszAdatperName
[MAX_PATH
];
347 swprintf(tpszAdatperName
,L
"%S",pAdapter
->AdapterName
);
348 OutputDebugString(_T("IPHLPAPI returned:\r\n"));
349 OutputDebugString(tpszAdatperName
);
350 OutputDebugString(_T("\r\n"));
351 if(_tcscmp(tpszAdatperName
,tpszCfgInstanceID
)==0)
353 DisplayTCPIPProperties(hwndDlg
,pAdapter
);
357 OutputDebugString(_T("... which is not the TCPIP property sheet\r\n"));
359 pAdapter
= pAdapter
->Next
;
362 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
);
368 MessageBox(NULL
,_T("This control panel is incomplete.\r\nUsually, the \"Notify Object\" for this Network component should be invoked here. Reactos lacks the infrastructure to do this right now.\r\n- C++\r\n- DDK Headers for notify objects\r\n- clean header structure, that allow Windows-Compatible COM C++ Code"),_T("Error"),MB_ICONSTOP
);
380 void DisplayNICProperties(HWND hParent
,TCHAR
*tpszCfgInstanceID
)
382 PROPSHEETPAGE psp
[1];
384 TCHAR tpszSubKey
[MAX_PATH
];
386 DWORD dwType
= REG_SZ
;
387 TCHAR tpszName
[MAX_PATH
];
388 DWORD dwSize
= sizeof(tpszName
);
390 // Get the "Name" for this Connection
391 _stprintf(tpszSubKey
,_T("System\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection"),tpszCfgInstanceID
);
392 if(RegOpenKey(HKEY_LOCAL_MACHINE
,tpszSubKey
,&hKey
)!=ERROR_SUCCESS
)
394 if(RegQueryValueEx(hKey
,_T("Name"),NULL
,&dwType
,(BYTE
*)tpszName
,&dwSize
)!=ERROR_SUCCESS
)
395 _stprintf(tpszName
,_T("[ERROR]"));
397 _tcscat(tpszName
,_T(" Properties"));
401 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
402 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
403 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
404 psh
.hwndParent
= hParent
;
405 psh
.hInstance
= hApplet
;
407 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
409 psh
.u1
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
411 psh
.pszCaption
= tpszName
;
412 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
417 psh
.u2
.nStartPage
= 0;
420 psh
.pfnCallback
= NULL
;
423 InitPropSheetPage(&psp
[0], IDD_NETPROPERTIES
, NICPropertyPageProc
,(LPARAM
)tpszCfgInstanceID
);
424 PropertySheet(&psh
) ;
431 NICStatusPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
437 PROPSHEETPAGE
*psp
= (PROPSHEETPAGE
*)lParam
;
438 EnableWindow(GetDlgItem(hwndDlg
,IDC_ENDISABLE
),FALSE
);
439 SetWindowLongPtr(hwndDlg
,DWL_USER
,(DWORD_PTR
)psp
->lParam
);
443 switch(LOWORD(wParam
))
447 TCHAR
*tpszCfgInstance
;
448 tpszCfgInstance
= (TCHAR
*)GetWindowLong(hwndDlg
,DWL_USER
);
449 DisplayNICProperties(hwndDlg
,tpszCfgInstance
);
458 void DisplayNICStatus(HWND hParent
,TCHAR
*tpszCfgInstanceID
)
460 PROPSHEETPAGE psp
[1];
462 TCHAR tpszSubKey
[MAX_PATH
];
464 DWORD dwType
= REG_SZ
;
465 TCHAR tpszName
[MAX_PATH
];
466 DWORD dwSize
= sizeof(tpszName
);
468 // Get the "Name" for this Connection
469 _stprintf(tpszSubKey
,_T("System\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection"),tpszCfgInstanceID
);
470 if(RegOpenKey(HKEY_LOCAL_MACHINE
,tpszSubKey
,&hKey
)!=ERROR_SUCCESS
)
472 if(RegQueryValueEx(hKey
,_T("Name"),NULL
,&dwType
,(BYTE
*)tpszName
,&dwSize
)!=ERROR_SUCCESS
)
473 _stprintf(tpszName
,_T("[ERROR]"));
474 //_stprintf(tpszName,_T("[ERROR]") _T(__FILE__) _T(" %d"),__LINE__ );
476 _tcscat(tpszName
,_T(" Status"));
479 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
480 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
481 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
482 psh
.hwndParent
= hParent
;
483 psh
.hInstance
= hApplet
;
484 // FIX THESE REACTOS HEADERS !!!!!!!!!
486 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
488 psh
.u1
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
490 psh
.pszCaption
= tpszName
;//Caption;
491 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
496 psh
.u2
.nStartPage
= 0;
499 psh
.pfnCallback
= NULL
;
502 InitPropSheetPage(&psp
[0], IDD_CARDPROPERTIES
, NICStatusPageProc
,(LPARAM
)tpszCfgInstanceID
);
503 PropertySheet(&psh
) ;
508 // IPHLPAPI does not provide a list of all adapters
511 void EnumAdapters(HWND hwndDlg)
513 IP_ADAPTER_INFO *pInfo;
514 ULONG size=sizeof(Info);
515 TCHAR pszText[MAX_ADAPTER_NAME_LENGTH + 4];
518 if(GetAdaptersInfo(Info,&size)!=ERROR_SUCCESS)
520 MessageBox(hwndDlg,L"IPHLPAPI.DLL failed to provide Adapter information",L"Error",MB_ICONSTOP);
526 swprintf(pszText,L"%S",Info[0].Description);
527 nIndex = SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_ADDSTRING,0,(LPARAM)pszText);
528 SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_SETITEMDATA,nIndex,(LPARAM)pInfo);
536 void NetAdapterCallback(void *pCookie
,HKEY hBaseKey
,TCHAR
*tpszSubKey
)
538 TCHAR tpszDisplayName
[MAX_PATH
];
539 //TCHAR tpszDeviceID[MAX_PATH];
540 TCHAR tpszCfgInstanceID
[MAX_PATH
];
541 TCHAR
*ptpszCfgInstanceID
;
543 DWORD dwType
= REG_SZ
;
544 DWORD dwSize
= sizeof(tpszDisplayName
);
546 HWND hwndDlg
= (HWND
)pCookie
;
547 DWORD dwCharacteristics
;
549 OutputDebugString(_T("NetAdapterCallback\r\n"));
550 OutputDebugString(tpszSubKey
);
551 OutputDebugString(_T("\r\n"));
552 if(RegOpenKeyEx(hBaseKey
,tpszSubKey
,0,KEY_ALL_ACCESS
,&hKey
)!=ERROR_SUCCESS
)
555 OutputDebugString(_T("NetAdapterCallback: Reading Characteristics\r\n"));
557 dwSize
= sizeof(dwCharacteristics
);
558 if(RegQueryValueEx(hKey
,_T("Characteristics"),NULL
,&dwType
,(BYTE
*)&dwCharacteristics
,&dwSize
)!=ERROR_SUCCESS
)
559 dwCharacteristics
= 0;
562 if(dwCharacteristics
& NCF_HIDDEN
)
564 // if(!(dwCharacteristics & NCF_HAS_UI))
567 OutputDebugString(_T("NetAdapterCallback: Reading DriverDesc\r\n"));
569 dwSize
= sizeof(tpszDisplayName
);
570 if(RegQueryValueEx(hKey
,_T("DriverDesc"),NULL
,&dwType
,(BYTE
*)tpszDisplayName
,&dwSize
)!= ERROR_SUCCESS
)
571 _tcscpy(tpszDisplayName
,_T("Unnamed Adapter"));
573 // get the link to the Enum Subkey (currently unused)
575 //dwSize = sizeof(tpszDeviceID);
576 //if(RegQueryValueEx(hKey,_T("MatchingDeviceId"),NULL,&dwType,(BYTE*)tpszDeviceID,&dwSize) != ERROR_SUCCESS) {
577 // MessageBox(hwndDlg,_T("Missing MatchingDeviceId Entry"),_T("Registry Problem"),MB_ICONSTOP);
581 // get the card configuration GUID
583 dwSize
= sizeof(tpszCfgInstanceID
);
584 if(RegQueryValueEx(hKey
,_T("NetCfgInstanceId"),NULL
,&dwType
,(BYTE
*)tpszCfgInstanceID
,&dwSize
) != ERROR_SUCCESS
) {
585 MessageBox(hwndDlg
,_T("Missing NetCfgInstanceId Entry"),_T("Registry Problem"),MB_ICONSTOP
);
589 ptpszCfgInstanceID
= _tcsdup(tpszCfgInstanceID
);
591 // **TODO** **FIXME** TBD
592 // At this point, we should verify, if the device listed here
593 // really represents a device that is currently connected to the system
595 // How is this done properly ?
598 nIndex
= SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_ADDSTRING
,0,(LPARAM
)tpszDisplayName
);
599 SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_SETITEMDATA
,nIndex
,(LPARAM
)ptpszCfgInstanceID
);
604 void EnumAdapters(HWND hwndDlg
)
606 TCHAR
*tpszRegPath
= _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}");
608 EnumRegKeys(NetAdapterCallback
,hwndDlg
,HKEY_LOCAL_MACHINE
,tpszRegPath
);
614 NetworkPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
622 EnableWindow(GetDlgItem(hwndDlg
,IDC_ADD
),FALSE
);
623 EnableWindow(GetDlgItem(hwndDlg
,IDC_REMOVE
),FALSE
);
625 SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_SETCURSEL
,0,0);
627 EnumAdapters(hwndDlg
);
637 while(SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETCOUNT
,0,0)>0)
640 tpszString
= (TCHAR
*)SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETITEMDATA
,0,0);
643 SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_DELETESTRING
,0,0);
650 switch(LOWORD(wParam
))
652 case IDC_NETCARDLIST
:
653 if(HIWORD(wParam
)==LBN_DBLCLK
) {
654 nIndex
= SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETCURSEL
,0,0);
656 DisplayNICStatus(hwndDlg
,(TCHAR
*)SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETITEMDATA
,nIndex
,0));
660 nIndex
= SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETCURSEL
,0,0);
662 DisplayNICStatus(hwndDlg
,(TCHAR
*)SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETITEMDATA
,nIndex
,0));
673 LONG CALLBACK
DisplayApplet(VOID
)
675 PROPSHEETPAGE psp
[1];
679 LoadString(hApplet
, IDS_CPLSYSTEMNAME
, Caption
, sizeof(Caption
) / sizeof(TCHAR
));
681 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
682 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
683 psh
.dwFlags
= PSH_PROPSHEETPAGE
;
684 psh
.hwndParent
= NULL
;
685 psh
.hInstance
= hApplet
;
687 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
689 psh
.u1
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
691 psh
.pszCaption
= Caption
;
692 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
697 psh
.u2
.nStartPage
= 0;
700 psh
.pfnCallback
= NULL
;
703 InitPropSheetPage(&psp
[0], IDD_PROPPAGENETWORK
, NetworkPageProc
,0);
705 return (LONG
)(PropertySheet(&psh
) != -1);
708 /* Control Panel Callback */
709 LONG CALLBACK
CPlApplet(HWND hwndCPl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
711 int i
= (int)lParam1
;
721 return sizeof(Applets
)/sizeof(APPLET
);
725 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
727 CPlInfo
->idIcon
= Applets
[i
].idIcon
;
728 CPlInfo
->idName
= Applets
[i
].idName
;
729 CPlInfo
->idInfo
= Applets
[i
].idDescription
;
734 Applets
[i
].AppletProc();
742 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD dwReason
, LPVOID lpvReserved
)
746 case DLL_PROCESS_ATTACH
:
747 case DLL_THREAD_ATTACH
: