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
19 * PROJECT: ReactOS Network Control Panel
20 * FILE: lib/cpl/system/ncpa.c
21 * PURPOSE: ReactOS Network Control Panel
22 * PROGRAMMER: Gero Kuehn (reactos.filter@gkware.com)
30 * This file contains a first attempt for reactos network configuration
32 * - It is not complete.
33 * - It does not work the way it works on Windows.
35 * A lot of code that can be found here now, will probably be relocated into the OS core or some
36 * protocol Co-Installers or Notify Objects later when all the required COM
37 * and "netcfgx.dll" infrastructure (esp. headers and Interfaces) get implemented step by step.
39 * This code is only a first approach to provide a usable network configuration dialogs for
40 * the new network support in Reactos.
42 * If you intend to extend this code by more, please contact me to avoid duplicate work.
43 * There are already resources and code for TCP/IP configuration that are not
44 * mature enough for committing them to CVS yet.
61 #define NCF_VIRTUAL 0x1
62 #define NCF_SOFTWARE_ENUMERATED 0x2
63 #define NCF_PHYSICAL 0x4
64 #define NCF_HIDDEN 0x8
65 #define NCF_NO_SERVICE 0x10
66 #define NCF_NOT_USER_REMOVABLE 0x20
67 #define NCF_MULTIPORT_INSTANCED_ADAPTER 0x40
68 #define NCF_HAS_UI 0x80
69 #define NCF_FILTER 0x400
70 #define NCF_NDIS_PROTOCOL 0x4000
72 typedef void (ENUMREGKEYCALLBACK
)(void *pCookie
,HKEY hBaseKey
,TCHAR
*pszSubKey
);
74 static LONG CALLBACK
DisplayApplet(VOID
);
75 static INT_PTR CALLBACK
NetworkPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
76 void DisplayTCPIPProperties(HWND hParent
,IP_ADAPTER_INFO
*pInfo
);
78 HINSTANCE hApplet
= 0;
81 static APPLET Applets
[] =
83 {IDI_CPLSYSTEM
, IDS_CPLSYSTEMNAME
, IDS_CPLSYSTEMDESCRIPTION
, DisplayApplet
}
87 /* useful utilities */
89 EnumRegKeys(ENUMREGKEYCALLBACK
*pCallback
,PVOID pCookie
,HKEY hBaseKey
,TCHAR
*tpszRegPath
)
94 TCHAR tpszName
[MAX_PATH
];
95 DWORD dwNameLen
= sizeof(tpszName
);
97 if(RegOpenKeyEx(hBaseKey
,tpszRegPath
,0,KEY_ENUMERATE_SUB_KEYS
,&hKey
)!=ERROR_SUCCESS
)
99 DPRINT("EnumRegKeys failed (key not found): %S\n", tpszRegPath
);
105 TCHAR pszNewPath
[MAX_PATH
];
106 ret
= RegEnumKeyEx(hKey
,i
,tpszName
,&dwNameLen
,NULL
,NULL
,NULL
,NULL
);
107 if(ret
!= ERROR_SUCCESS
)
109 DPRINT("EnumRegKeys: RegEnumKeyEx failed for %S (rc 0x%lx)\n", tpszName
, ret
);
113 _stprintf(pszNewPath
,_T("%s\\%s"),tpszRegPath
,tpszName
);
114 DPRINT("EnumRegKeys: Calling user supplied enum function\n");
115 pCallback(pCookie
,hBaseKey
,pszNewPath
);
117 dwNameLen
= sizeof(tpszName
);
124 InitPropSheetPage(PROPSHEETPAGE
*psp
, WORD idDlg
, DLGPROC DlgProc
,LPARAM lParam
)
126 ZeroMemory(psp
, sizeof(PROPSHEETPAGE
));
127 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
128 psp
->dwFlags
= PSP_DEFAULT
;
129 psp
->hInstance
= hApplet
;
130 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
131 psp
->pfnDlgProc
= DlgProc
;
132 psp
->lParam
= lParam
;
138 FindNICClassKeyForCfgInstance(TCHAR
*tpszCfgInst
,TCHAR
*tpszSubKeyOut
)
141 TCHAR tpszSubKey
[MAX_PATH
];
142 TCHAR tpszCfgInst2
[MAX_PATH
];
146 for (i
= 0; i
< 100; i
++)
148 _stprintf(tpszSubKey
,_T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%04d"),i
);
149 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE
,tpszSubKey
,0,KEY_QUERY_VALUE
,&hKey
)!=ERROR_SUCCESS
)
152 dwSize
= sizeof(tpszCfgInst2
);
153 if(RegQueryValueEx(hKey
,_T("NetCfgInstanceId"),NULL
,&dwType
,(BYTE
*)tpszCfgInst2
,&dwSize
)!=ERROR_SUCCESS
) {
158 if(_tcscmp(tpszCfgInst
,tpszCfgInst2
)==0) {
159 _tcscpy(tpszSubKeyOut
,tpszSubKey
);
168 NICPropertyProtocolCallback(void *pCookie
,HKEY hBaseKey
,TCHAR
*tpszSubKey
)
171 DWORD dwCharacteristics
;
174 TCHAR tpszDescription
[MAX_PATH
];
175 TCHAR tpszNotifyObjectCLSID
[MAX_PATH
];
176 TCHAR
*tpszSubKeyCopy
;
179 UNREFERENCED_PARAMETER(hBaseKey
);
181 // CLSID CLSID_NotifObj;
182 // IUnknown *pUnk = NULL;
183 // INetCfgComponentControl *pNetCfg;
184 // INetCfgComponentPropertyUi *pNetCfgPropUI;
185 hwndDlg
= (HWND
)pCookie
;
187 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE
,tpszSubKey
,0,KEY_QUERY_VALUE
,&hKey
)!=ERROR_SUCCESS
)
191 dwSize
= sizeof(dwCharacteristics
);
192 if(RegQueryValueEx(hKey
,_T("Characteristics"),NULL
,&dwType
,(BYTE
*)&dwCharacteristics
,&dwSize
)!= ERROR_SUCCESS
)
195 if(dwCharacteristics
& NCF_HIDDEN
)
202 dwSize
= sizeof(tpszDescription
);
203 if(RegQueryValueEx(hKey
,_T("Description"),NULL
,&dwType
,(BYTE
*)tpszDescription
,&dwSize
)!= ERROR_SUCCESS
)
206 RegOpenKeyEx(hKey
,_T("Ndi"),0,KEY_QUERY_VALUE
,&hNDIKey
);
208 dwSize
= sizeof(tpszNotifyObjectCLSID
);
209 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
= (int) SendDlgItemMessage(hwndDlg
,IDC_COMPONENTSLIST
,LB_ADDSTRING
,0,(LPARAM
)tpszDescription
);
237 tpszSubKeyCopy
= _tcsdup(tpszSubKey
);
238 SendDlgItemMessage(hwndDlg
,IDC_COMPONENTSLIST
,LB_SETITEMDATA
,nIndex
,(LPARAM
)tpszSubKeyCopy
);
243 static INT_PTR CALLBACK
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(RegOpenKeyEx(HKEY_LOCAL_MACHINE
,tpszSubKey
,0,KEY_QUERY_VALUE
,&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
);
275 SetWindowLongPtr(hwndDlg
,GWL_USERDATA
,(DWORD_PTR
)lParam
);
276 //SetDlgItemTextA(hwndDlg,IDC_NETCARDNAME,Info[pPage->lParam].Description);
277 EnumRegKeys(NICPropertyProtocolCallback
,hwndDlg
,HKEY_LOCAL_MACHINE
,_T("System\\CurrentControlSet\\Control\\Network\\{4D36E975-E325-11CE-BFC1-08002BE10318}"));
279 SendDlgItemMessage(hwndDlg
, IDC_COMPONENTSLIST
, LB_SETCURSEL
, 0, 0);
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 RegOpenKeyEx(HKEY_LOCAL_MACHINE
,tpszHelpKey
,0,KEY_QUERY_VALUE
,&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
)
314 TCHAR
*tpszSubKey
= NULL
;
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 int iListBoxIndex
= (int) SendMessage(hListBox
,LB_GETCURSEL
,0,0);
322 if(iListBoxIndex
!= LB_ERR
)
323 tpszSubKey
= (TCHAR
*)SendMessage(hListBox
,LB_GETITEMDATA
,iListBoxIndex
,0);
326 _stprintf(tpszNDIKey
,_T("%s\\Ndi"),tpszSubKey
);
328 RegOpenKeyEx(HKEY_LOCAL_MACHINE
,tpszNDIKey
,0,KEY_QUERY_VALUE
,&hNDIKey
);
329 dwSize
= sizeof(tpszClsIDText
);
330 if(RegQueryValueEx(hNDIKey
,_T("ClsId"),NULL
,&dwType
,(BYTE
*)tpszClsIDText
,&dwSize
)!= ERROR_SUCCESS
|| dwType
!= REG_SZ
)
332 RegCloseKey(hNDIKey
);
334 if(_tcscmp(tpszTCPIPClsID
,tpszClsIDText
)==0)
336 IP_ADAPTER_INFO Adapters
[64];
337 IP_ADAPTER_INFO
*pAdapter
;
338 TCHAR
*tpszCfgInstanceID
;
339 DWORD dwSize
= sizeof(Adapters
);
340 memset(&Adapters
,0x00,sizeof(Adapters
));
341 if(GetAdaptersInfo(Adapters
,&dwSize
)!=ERROR_SUCCESS
)
344 tpszCfgInstanceID
= (TCHAR
*)pPage
->lParam
;
347 TCHAR tpszAdapterName
[MAX_PATH
];
348 swprintf(tpszAdapterName
,L
"%S",pAdapter
->AdapterName
);
349 DPRINT("IPHLPAPI returned: %S\n", tpszAdapterName
);
350 if(_tcscmp(tpszAdapterName
,tpszCfgInstanceID
)==0)
352 DisplayTCPIPProperties(hwndDlg
,pAdapter
);
356 DPRINT("... which is not the TCPIP property sheet\n");
358 pAdapter
= pAdapter
->Next
;
361 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
);
367 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 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(RegOpenKeyEx(HKEY_LOCAL_MACHINE
,tpszSubKey
,0,KEY_QUERY_VALUE
,&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
;
406 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
407 psh
.pszCaption
= tpszName
;
408 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
411 psh
.pfnCallback
= NULL
;
414 InitPropSheetPage(&psp
[0], IDD_NETPROPERTIES
, NICPropertyPageProc
,(LPARAM
)tpszCfgInstanceID
);
419 static INT_PTR CALLBACK
420 NICStatusPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
426 PROPSHEETPAGE
*psp
= (PROPSHEETPAGE
*)lParam
;
427 EnableWindow(GetDlgItem(hwndDlg
,IDC_ENDISABLE
),FALSE
);
428 SetWindowLongPtr(hwndDlg
,DWL_USER
,(DWORD_PTR
)psp
->lParam
);
432 switch(LOWORD(wParam
))
436 TCHAR
*tpszCfgInstance
;
437 tpszCfgInstance
= (TCHAR
*)GetWindowLong(hwndDlg
,DWL_USER
);
438 DisplayNICProperties(hwndDlg
,tpszCfgInstance
);
447 static INT_PTR CALLBACK
448 NICSupportPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
457 PIP_ADAPTER_INFO pAdapterInfo
= NULL
;
458 ULONG adaptOutBufLen
;
462 pAdapterInfo
= (IP_ADAPTER_INFO
*) malloc( sizeof(IP_ADAPTER_INFO
) );
463 adaptOutBufLen
= sizeof(IP_ADAPTER_INFO
);
465 if (GetAdaptersInfo( pAdapterInfo
, &adaptOutBufLen
) == ERROR_BUFFER_OVERFLOW
)
468 pAdapterInfo
= (IP_ADAPTER_INFO
*) malloc (adaptOutBufLen
);
471 if ((ErrRet
= GetAdaptersInfo(pAdapterInfo
, &adaptOutBufLen
)) != NO_ERROR
)
473 MessageBox(hwndDlg
, _T("error adapterinfo") ,_T("ncpa.cpl"),MB_ICONSTOP
);
475 if (pAdapterInfo
) free(pAdapterInfo
);
481 /*FIXME: select the correct adapter info!!*/
482 _stprintf(Buffer
, _T("%S"), pAdapterInfo
->IpAddressList
.IpAddress
.String
);
483 SendDlgItemMessage(hwndDlg
, IDC_DETAILSIP
, WM_SETTEXT
, 0, (LPARAM
)Buffer
);
484 _stprintf(Buffer
, _T("%S"), pAdapterInfo
->IpAddressList
.IpMask
.String
);
485 SendDlgItemMessage(hwndDlg
, IDC_DETAILSSUBNET
, WM_SETTEXT
, 0, (LPARAM
)Buffer
);
486 _stprintf(Buffer
, _T("%S"), pAdapterInfo
->GatewayList
.IpAddress
.String
);
487 SendDlgItemMessage(hwndDlg
, IDC_DETAILSGATEWAY
, WM_SETTEXT
, 0, (LPARAM
)Buffer
);
497 switch(LOWORD(wParam
))
505 MessageBox(hwndDlg
,_T("not implemented: show detail window"),_T("ncpa.cpl"),MB_ICONSTOP
);
517 DisplayNICStatus(HWND hParent
,TCHAR
*tpszCfgInstanceID
)
519 PROPSHEETPAGE psp
[2];
521 TCHAR tpszSubKey
[MAX_PATH
];
523 DWORD dwType
= REG_SZ
;
524 TCHAR tpszName
[MAX_PATH
];
525 DWORD dwSize
= sizeof(tpszName
);
527 // Get the "Name" for this Connection
528 _stprintf(tpszSubKey
,_T("System\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection"),tpszCfgInstanceID
);
529 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,tpszSubKey
,0,KEY_QUERY_VALUE
,&hKey
)!=ERROR_SUCCESS
)
532 if (RegQueryValueEx(hKey
,_T("Name"),NULL
,&dwType
,(BYTE
*)tpszName
,&dwSize
)!=ERROR_SUCCESS
)
533 _stprintf(tpszName
,_T("[ERROR]"));
534 //_stprintf(tpszName,_T("[ERROR]") _T(__FILE__) _T(" %d"),__LINE__ );
536 _tcscat(tpszName
,_T(" Status"));
539 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
540 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
541 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
542 psh
.hwndParent
= hParent
;
543 psh
.hInstance
= hApplet
;
544 // FIX THESE REACTOS HEADERS !!!!!!!!!
545 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
546 psh
.pszCaption
= tpszName
;//Caption;
547 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
550 psh
.pfnCallback
= NULL
;
552 InitPropSheetPage(&psp
[0], IDD_CARDPROPERTIES
, NICStatusPageProc
, (LPARAM
)tpszCfgInstanceID
);
553 InitPropSheetPage(&psp
[1], IDD_CARDSUPPORT
, NICSupportPageProc
, (LPARAM
)tpszCfgInstanceID
);
560 // IPHLPAPI does not provide a list of all adapters
564 EnumAdapters(HWND hwndDlg
)
566 TCHAR pszText
[MAX_ADAPTER_NAME_LENGTH
+ 4];
567 IP_ADAPTER_INFO
*pInfo
;
572 if(GetAdaptersInfo(Info
,&size
)!=ERROR_SUCCESS
)
574 MessageBox(hwndDlg
,L
"IPHLPAPI.DLL failed to provide Adapter information",L
"Error",MB_ICONSTOP
);
581 swprintf(pszText
,L
"%S",Info
[0].Description
);
582 nIndex
= SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_ADDSTRING
,0,(LPARAM
)pszText
);
583 SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_SETITEMDATA
,nIndex
,(LPARAM
)pInfo
);
592 NetAdapterCallback(void *pCookie
,HKEY hBaseKey
,TCHAR
*tpszSubKey
)
594 TCHAR tpszDisplayName
[MAX_PATH
];
595 //TCHAR tpszDeviceID[MAX_PATH];
596 TCHAR tpszCfgInstanceID
[MAX_PATH
];
597 TCHAR
*ptpszCfgInstanceID
;
599 DWORD dwType
= REG_SZ
;
600 DWORD dwSize
= sizeof(tpszDisplayName
);
602 HWND hwndDlg
= (HWND
)pCookie
;
603 DWORD dwCharacteristics
;
605 DPRINT("NetAdapterCallback: %S\n", tpszSubKey
);
607 if(RegOpenKeyEx(hBaseKey
,tpszSubKey
,0,KEY_QUERY_VALUE
,&hKey
)!=ERROR_SUCCESS
)
610 DPRINT("NetAdapterCallback: Reading Characteristics\n");
612 dwSize
= sizeof(dwCharacteristics
);
613 if(RegQueryValueEx(hKey
,_T("Characteristics"),NULL
,&dwType
,(BYTE
*)&dwCharacteristics
,&dwSize
)!=ERROR_SUCCESS
)
614 dwCharacteristics
= 0;
616 if (dwCharacteristics
& NCF_HIDDEN
)
619 if (!(dwCharacteristics
& NCF_VIRTUAL
) && !(dwCharacteristics
& NCF_PHYSICAL
))
622 DPRINT("NetAdapterCallback: Reading DriverDesc\n");
624 dwSize
= sizeof(tpszDisplayName
);
625 if (RegQueryValueEx(hKey
,_T("DriverDesc"),NULL
,&dwType
,(BYTE
*)tpszDisplayName
,&dwSize
)!= ERROR_SUCCESS
)
626 _tcscpy(tpszDisplayName
,_T("Unnamed Adapter"));
628 // get the link to the Enum Subkey (currently unused)
630 //dwSize = sizeof(tpszDeviceID);
631 //if(RegQueryValueEx(hKey,_T("MatchingDeviceId"),NULL,&dwType,(BYTE*)tpszDeviceID,&dwSize) != ERROR_SUCCESS) {
632 // MessageBox(hwndDlg,_T("Missing MatchingDeviceId Entry"),_T("Registry Problem"),MB_ICONSTOP);
636 // get the card configuration GUID
638 dwSize
= sizeof(tpszCfgInstanceID
);
639 if(RegQueryValueEx(hKey
,_T("NetCfgInstanceId"),NULL
,&dwType
,(BYTE
*)tpszCfgInstanceID
,&dwSize
) != ERROR_SUCCESS
) {
640 MessageBox(hwndDlg
,_T("Missing NetCfgInstanceId Entry"),_T("Registry Problem"),MB_ICONSTOP
);
644 ptpszCfgInstanceID
= _tcsdup(tpszCfgInstanceID
);
646 // **TODO** **FIXME** TBD
647 // At this point, we should verify, if the device listed here
648 // really represents a device that is currently connected to the system
650 // How is this done properly ?
653 nIndex
= (int) SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_ADDSTRING
,0,(LPARAM
)tpszDisplayName
);
654 SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_SETITEMDATA
,nIndex
,(LPARAM
)ptpszCfgInstanceID
);
660 EnumAdapters(HWND hwndDlg
)
662 LPTSTR lpRegPath
= _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}");
664 EnumRegKeys(NetAdapterCallback
,hwndDlg
,HKEY_LOCAL_MACHINE
,lpRegPath
);
669 static INT_PTR CALLBACK
670 NetworkPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
678 EnableWindow(GetDlgItem(hwndDlg
,IDC_ADD
),FALSE
);
679 EnableWindow(GetDlgItem(hwndDlg
,IDC_REMOVE
),FALSE
);
681 EnumAdapters(hwndDlg
);
682 SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_SETCURSEL
,0,0);
692 while(SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETCOUNT
,0,0)>0)
696 tpszString
= (TCHAR
*)SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETITEMDATA
,0,0);
699 SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_DELETESTRING
,0,0);
706 switch(LOWORD(wParam
))
708 case IDC_NETCARDLIST
:
709 if(HIWORD(wParam
)==LBN_DBLCLK
) {
710 nIndex
= (int) SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETCURSEL
,0,0);
712 DisplayNICStatus(hwndDlg
,(TCHAR
*)SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETITEMDATA
,nIndex
,0));
717 nIndex
= (int) SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETCURSEL
,0,0);
719 DisplayNICStatus(hwndDlg
,(TCHAR
*)SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETITEMDATA
,nIndex
,0));
734 PROPSHEETPAGE psp
[1];
735 PROPSHEETHEADER psh
= {0};
738 LoadString(hApplet
, IDS_CPLSYSTEMNAME
, Caption
, sizeof(Caption
) / sizeof(TCHAR
));
740 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
741 psh
.dwFlags
= PSH_PROPSHEETPAGE
;
742 psh
.hwndParent
= NULL
;
743 psh
.hInstance
= hApplet
;
744 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
745 psh
.pszCaption
= Caption
;
746 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
749 psh
.pfnCallback
= NULL
;
751 InitPropSheetPage(&psp
[0], IDD_PROPPAGENETWORK
, NetworkPageProc
,0);
753 return (LONG
)(PropertySheet(&psh
) != -1);
756 /* Control Panel Callback */
758 CPlApplet(HWND hwndCPl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
760 UNREFERENCED_PARAMETER(hwndCPl
);
770 return sizeof(Applets
)/sizeof(APPLET
);
775 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
777 CPlInfo
->idIcon
= Applets
[(int)lParam1
].idIcon
;
778 CPlInfo
->idName
= Applets
[(int)lParam1
].idName
;
779 CPlInfo
->idInfo
= Applets
[(int)lParam1
].idDescription
;
785 Applets
[(int)lParam1
].AppletProc();
794 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD dwReason
, LPVOID lpvReserved
)
796 UNREFERENCED_PARAMETER(lpvReserved
);
800 case DLL_PROCESS_ATTACH
:
801 case DLL_THREAD_ATTACH
: