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.3 2004/09/26 15:55:52 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 BOOL 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
);
243 BOOL CALLBACK
NICPropertyPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
245 PROPSHEETPAGE
*pPage
= (PROPSHEETPAGE
*)GetWindowLongPtr(hwndDlg
,GWL_USERDATA
);
250 TCHAR
*tpszCfgInstanceID
;
252 TCHAR tpszSubKey
[MAX_PATH
];
253 TCHAR tpszDisplayName
[MAX_PATH
];
255 pPage
= (PROPSHEETPAGE
*)lParam
;
256 tpszCfgInstanceID
= (TCHAR
*)pPage
->lParam
;
257 if(!FindNICClassKeyForCfgInstance(tpszCfgInstanceID
,tpszSubKey
))
259 MessageBox(hwndDlg
,_T("NIC Entry not found"),_T("Registry error"),MB_ICONSTOP
);
260 MessageBox(hwndDlg
,tpszCfgInstanceID
,tpszSubKey
,MB_ICONSTOP
);
263 if(RegOpenKey(HKEY_LOCAL_MACHINE
,tpszSubKey
,&hKey
)!=ERROR_SUCCESS
)
266 dwSize
= sizeof(tpszDisplayName
);
267 if(RegQueryValueEx(hKey
,_T("DriverDesc"),NULL
,&dwType
,(BYTE
*)tpszDisplayName
,&dwSize
)!= ERROR_SUCCESS
)
271 SetDlgItemText(hwndDlg
,IDC_NETCARDNAME
,tpszDisplayName
);
272 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}"));
282 switch(LOWORD(wParam
))
284 case IDC_COMPONENTSLIST
:
285 if(HIWORD(wParam
)==LBN_SELCHANGE
)
288 TCHAR tpszHelpKey
[MAX_PATH
];
289 TCHAR tpszHelpText
[MAX_PATH
];
292 HWND hListBox
= GetDlgItem(hwndDlg
,IDC_COMPONENTSLIST
);
293 tpszSubKey
= (TCHAR
*)SendMessage(hListBox
,LB_GETITEMDATA
,SendMessage(hListBox
,LB_GETCURSEL
,0,0),0);
296 _stprintf(tpszHelpKey
,_T("%s\\Ndi"),tpszSubKey
);
298 RegOpenKey(HKEY_LOCAL_MACHINE
,tpszHelpKey
,&hNDIKey
);
300 dwSize
= sizeof(tpszHelpText
);
301 if(RegQueryValueEx(hNDIKey
,_T("HelpText"),NULL
,&dwType
,(BYTE
*)tpszHelpText
,&dwSize
)!= ERROR_SUCCESS
)
303 RegCloseKey(hNDIKey
);
305 SetDlgItemText(hwndDlg
,IDC_DESCRIPTION
,tpszHelpText
);
308 if(HIWORD(wParam
)!=LBN_DBLCLK
)
314 TCHAR tpszNDIKey
[MAX_PATH
];
315 TCHAR tpszClsIDText
[MAX_PATH
];
316 TCHAR
*tpszTCPIPClsID
= _T("{A907657F-6FDF-11D0-8EFB-00C04FD912B2}");
319 HWND hListBox
= GetDlgItem(hwndDlg
,IDC_COMPONENTSLIST
);
320 tpszSubKey
= (TCHAR
*)SendMessage(hListBox
,LB_GETITEMDATA
,SendMessage(hListBox
,LB_GETCURSEL
,0,0),0);
323 _stprintf(tpszNDIKey
,_T("%s\\Ndi"),tpszSubKey
);
325 RegOpenKey(HKEY_LOCAL_MACHINE
,tpszNDIKey
,&hNDIKey
);
327 dwSize
= sizeof(tpszClsIDText
);
328 if(RegQueryValueEx(hNDIKey
,_T("ClsId"),NULL
,&dwType
,(BYTE
*)tpszClsIDText
,&dwSize
)!= ERROR_SUCCESS
)
330 RegCloseKey(hNDIKey
);
332 if(_tcscmp(tpszTCPIPClsID
,tpszClsIDText
)==0)
334 IP_ADAPTER_INFO Adapters
[64];
335 IP_ADAPTER_INFO
*pAdapter
;
336 TCHAR
*tpszCfgInstanceID
;
337 DWORD dwSize
= sizeof(Adapters
);
338 memset(&Adapters
,0x00,sizeof(Adapters
));
339 if(GetAdaptersInfo(Adapters
,&dwSize
)!=ERROR_SUCCESS
)
342 tpszCfgInstanceID
= (TCHAR
*)pPage
->lParam
;
345 TCHAR tpszAdatperName
[MAX_PATH
];
346 swprintf(tpszAdatperName
,L
"%S",pAdapter
->AdapterName
);
347 OutputDebugString(_T("IPHLPAPI returned:\r\n"));
348 OutputDebugString(tpszAdatperName
);
349 OutputDebugString(_T("\r\n"));
350 if(_tcscmp(tpszAdatperName
,tpszCfgInstanceID
)==0)
352 DisplayTCPIPProperties(hwndDlg
,pAdapter
);
356 OutputDebugString(_T("... which is not the TCPIP property sheet\r\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
);
379 void DisplayNICProperties(HWND hParent
,TCHAR
*tpszCfgInstanceID
)
381 PROPSHEETPAGE psp
[1];
383 TCHAR tpszSubKey
[MAX_PATH
];
385 DWORD dwType
= REG_SZ
;
386 TCHAR tpszName
[MAX_PATH
];
387 DWORD dwSize
= sizeof(tpszName
);
389 // Get the "Name" for this Connection
390 _stprintf(tpszSubKey
,_T("System\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection"),tpszCfgInstanceID
);
391 if(RegOpenKey(HKEY_LOCAL_MACHINE
,tpszSubKey
,&hKey
)!=ERROR_SUCCESS
)
393 if(RegQueryValueEx(hKey
,_T("Name"),NULL
,&dwType
,(BYTE
*)tpszName
,&dwSize
)!=ERROR_SUCCESS
)
394 _stprintf(tpszName
,_T("[ERROR]"));
396 _tcscat(tpszName
,_T(" Properties"));
400 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
401 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
402 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
403 psh
.hwndParent
= hParent
;
404 psh
.hInstance
= hApplet
;
406 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
408 psh
.u1
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
410 psh
.pszCaption
= tpszName
;
411 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
416 psh
.u2
.nStartPage
= 0;
419 psh
.pfnCallback
= NULL
;
422 InitPropSheetPage(&psp
[0], IDD_NETPROPERTIES
, NICPropertyPageProc
,(LPARAM
)tpszCfgInstanceID
);
423 PropertySheet(&psh
) ;
429 BOOL CALLBACK
NICStatusPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
435 PROPSHEETPAGE
*psp
= (PROPSHEETPAGE
*)lParam
;
436 EnableWindow(GetDlgItem(hwndDlg
,IDC_ENDISABLE
),FALSE
);
437 SetWindowLongPtr(hwndDlg
,DWL_USER
,(DWORD_PTR
)psp
->lParam
);
441 switch(LOWORD(wParam
))
445 TCHAR
*tpszCfgInstance
;
446 tpszCfgInstance
= (TCHAR
*)GetWindowLong(hwndDlg
,DWL_USER
);
447 DisplayNICProperties(hwndDlg
,tpszCfgInstance
);
456 void DisplayNICStatus(HWND hParent
,TCHAR
*tpszCfgInstanceID
)
458 PROPSHEETPAGE psp
[1];
460 TCHAR tpszSubKey
[MAX_PATH
];
462 DWORD dwType
= REG_SZ
;
463 TCHAR tpszName
[MAX_PATH
];
464 DWORD dwSize
= sizeof(tpszName
);
466 // Get the "Name" for this Connection
467 _stprintf(tpszSubKey
,_T("System\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection"),tpszCfgInstanceID
);
468 if(RegOpenKey(HKEY_LOCAL_MACHINE
,tpszSubKey
,&hKey
)!=ERROR_SUCCESS
)
470 if(RegQueryValueEx(hKey
,_T("Name"),NULL
,&dwType
,(BYTE
*)tpszName
,&dwSize
)!=ERROR_SUCCESS
)
471 _stprintf(tpszName
,_T("[ERROR]"));
472 //_stprintf(tpszName,_T("[ERROR]") _T(__FILE__) _T(" %d"),__LINE__ );
474 _tcscat(tpszName
,_T(" Status"));
477 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
478 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
479 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
480 psh
.hwndParent
= hParent
;
481 psh
.hInstance
= hApplet
;
482 // FIX THESE REACTOS HEADERS !!!!!!!!!
484 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
486 psh
.u1
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
488 psh
.pszCaption
= tpszName
;//Caption;
489 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
494 psh
.u2
.nStartPage
= 0;
497 psh
.pfnCallback
= NULL
;
500 InitPropSheetPage(&psp
[0], IDD_CARDPROPERTIES
, NICStatusPageProc
,(LPARAM
)tpszCfgInstanceID
);
501 PropertySheet(&psh
) ;
506 // IPHLPAPI does not provide a list of all adapters
509 void EnumAdapters(HWND hwndDlg)
511 IP_ADAPTER_INFO *pInfo;
512 ULONG size=sizeof(Info);
513 TCHAR pszText[MAX_ADAPTER_NAME_LENGTH + 4];
516 if(GetAdaptersInfo(Info,&size)!=ERROR_SUCCESS)
518 MessageBox(hwndDlg,L"IPHLPAPI.DLL failed to provide Adapter information",L"Error",MB_ICONSTOP);
524 swprintf(pszText,L"%S",Info[0].Description);
525 nIndex = SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_ADDSTRING,0,(LPARAM)pszText);
526 SendDlgItemMessage(hwndDlg,IDC_NETCARDLIST,LB_SETITEMDATA,nIndex,(LPARAM)pInfo);
534 void NetAdapterCallback(void *pCookie
,HKEY hBaseKey
,TCHAR
*tpszSubKey
)
536 TCHAR tpszDisplayName
[MAX_PATH
];
537 //TCHAR tpszDeviceID[MAX_PATH];
538 TCHAR tpszCfgInstanceID
[MAX_PATH
];
539 TCHAR
*ptpszCfgInstanceID
;
541 DWORD dwType
= REG_SZ
;
542 DWORD dwSize
= sizeof(tpszDisplayName
);
544 HWND hwndDlg
= (HWND
)pCookie
;
545 DWORD dwCharacteristics
;
547 OutputDebugString(_T("NetAdapterCallback\r\n"));
548 OutputDebugString(tpszSubKey
);
549 OutputDebugString(_T("\r\n"));
550 if(RegOpenKeyEx(hBaseKey
,tpszSubKey
,0,KEY_ALL_ACCESS
,&hKey
)!=ERROR_SUCCESS
)
553 OutputDebugString(_T("NetAdapterCallback: Reading Characteristics\r\n"));
555 dwSize
= sizeof(dwCharacteristics
);
556 if(RegQueryValueEx(hKey
,_T("Characteristics"),NULL
,&dwType
,(BYTE
*)&dwCharacteristics
,&dwSize
)!=ERROR_SUCCESS
)
557 dwCharacteristics
= 0;
560 if(dwCharacteristics
& NCF_HIDDEN
)
562 // if(!(dwCharacteristics & NCF_HAS_UI))
565 OutputDebugString(_T("NetAdapterCallback: Reading DriverDesc\r\n"));
567 dwSize
= sizeof(tpszDisplayName
);
568 if(RegQueryValueEx(hKey
,_T("DriverDesc"),NULL
,&dwType
,(BYTE
*)tpszDisplayName
,&dwSize
)!= ERROR_SUCCESS
)
569 _tcscpy(tpszDisplayName
,_T("Unnamed Adapter"));
571 // get the link to the Enum Subkey (currently unused)
573 //dwSize = sizeof(tpszDeviceID);
574 //if(RegQueryValueEx(hKey,_T("MatchingDeviceId"),NULL,&dwType,(BYTE*)tpszDeviceID,&dwSize) != ERROR_SUCCESS) {
575 // MessageBox(hwndDlg,_T("Missing MatchingDeviceId Entry"),_T("Registry Problem"),MB_ICONSTOP);
579 // get the card configuration GUID
581 dwSize
= sizeof(tpszCfgInstanceID
);
582 if(RegQueryValueEx(hKey
,_T("NetCfgInstanceId"),NULL
,&dwType
,(BYTE
*)tpszCfgInstanceID
,&dwSize
) != ERROR_SUCCESS
) {
583 MessageBox(hwndDlg
,_T("Missing NetCfgInstanceId Entry"),_T("Registry Problem"),MB_ICONSTOP
);
587 ptpszCfgInstanceID
= _tcsdup(tpszCfgInstanceID
);
589 // **TODO** **FIXME** TBD
590 // At this point, we should verify, if the device listed here
591 // really represents a device that is currently connected to the system
593 // How is this done properly ?
596 nIndex
= SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_ADDSTRING
,0,(LPARAM
)tpszDisplayName
);
597 SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_SETITEMDATA
,nIndex
,(LPARAM
)ptpszCfgInstanceID
);
602 void EnumAdapters(HWND hwndDlg
)
604 TCHAR
*tpszRegPath
= _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}");
606 EnumRegKeys(NetAdapterCallback
,hwndDlg
,HKEY_LOCAL_MACHINE
,tpszRegPath
);
611 BOOL CALLBACK
NetworkPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
619 EnableWindow(GetDlgItem(hwndDlg
,IDC_ADD
),FALSE
);
620 EnableWindow(GetDlgItem(hwndDlg
,IDC_REMOVE
),FALSE
);
622 SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_SETCURSEL
,0,0);
624 EnumAdapters(hwndDlg
);
634 while(SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETCOUNT
,0,0)>0)
637 tpszString
= (TCHAR
*)SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETITEMDATA
,0,0);
640 SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_DELETESTRING
,0,0);
647 switch(LOWORD(wParam
))
649 case IDC_NETCARDLIST
:
650 if(HIWORD(wParam
)==LBN_DBLCLK
) {
651 nIndex
= SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETCURSEL
,0,0);
653 DisplayNICStatus(hwndDlg
,(TCHAR
*)SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETITEMDATA
,nIndex
,0));
657 nIndex
= SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETCURSEL
,0,0);
659 DisplayNICStatus(hwndDlg
,(TCHAR
*)SendDlgItemMessage(hwndDlg
,IDC_NETCARDLIST
,LB_GETITEMDATA
,nIndex
,0));
670 LONG CALLBACK
DisplayApplet(VOID
)
672 PROPSHEETPAGE psp
[1];
676 LoadString(hApplet
, IDS_CPLSYSTEMNAME
, Caption
, sizeof(Caption
) / sizeof(TCHAR
));
678 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
679 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
680 psh
.dwFlags
= PSH_PROPSHEETPAGE
;
681 psh
.hwndParent
= NULL
;
682 psh
.hInstance
= hApplet
;
684 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
686 psh
.u1
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_CPLSYSTEM
));
688 psh
.pszCaption
= Caption
;
689 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
694 psh
.u2
.nStartPage
= 0;
697 psh
.pfnCallback
= NULL
;
700 InitPropSheetPage(&psp
[0], IDD_PROPPAGENETWORK
, NetworkPageProc
,0);
702 return (LONG
)(PropertySheet(&psh
) != -1);
705 /* Control Panel Callback */
706 LONG CALLBACK
CPlApplet(HWND hwndCPl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
708 int i
= (int)lParam1
;
718 return sizeof(Applets
)/sizeof(APPLET
);
722 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
724 CPlInfo
->idIcon
= Applets
[i
].idIcon
;
725 CPlInfo
->idName
= Applets
[i
].idName
;
726 CPlInfo
->idInfo
= Applets
[i
].idDescription
;
731 Applets
[i
].AppletProc();
739 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD dwReason
, LPVOID lpvReserved
)
743 case DLL_PROCESS_ATTACH
:
744 case DLL_THREAD_ATTACH
: