Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

701 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation
  6. //
  7. // File: hdwwiz.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <windowsx.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <cpl.h>
  20. #include <prsht.h>
  21. #include <commctrl.h>
  22. #include <dlgs.h>
  23. #include <shellapi.h>
  24. #include <shlobj.h>
  25. #include <shlobjp.h>
  26. #include <shlwapi.h>
  27. #include <cfgmgr32.h>
  28. #include <setupapi.h>
  29. #include <spapip.h>
  30. #include <regstr.h>
  31. #include <srrestoreptapi.h>
  32. #include <mountmgr.h>
  33. #include <devguid.h>
  34. #include <powrprof.h>
  35. #include <shfusion.h>
  36. #include <strsafe.h>
  37. #include "resource.h"
  38. #pragma warning( default : 4201 )
  39. extern HMODULE hHdwWiz;
  40. extern HMODULE hDevMgr;
  41. extern HMODULE hNewDev;
  42. extern int g_BlankIconIndex;
  43. #define SIZECHARS(x) (sizeof((x))/sizeof(TCHAR))
  44. //
  45. // devmgr.dll exports
  46. //
  47. typedef
  48. UINT
  49. (*PDEVICEPROBLEMTEXT)(
  50. HMACHINE hMachine,
  51. DEVNODE DevNode,
  52. ULONG ProblemNumber,
  53. LPTSTR Buffer,
  54. UINT BufferSize
  55. );
  56. typedef
  57. int
  58. (*PDEVICEPROPERTIESEX)(
  59. HWND hwndParent,
  60. LPCSTR MachineName,
  61. LPCSTR DeviceID,
  62. DWORD Flags,
  63. BOOL ShowDeviceTree
  64. );
  65. typedef
  66. int
  67. (*PDEVICEPROBLEMWIZARD)(
  68. HWND hwndParent,
  69. PTCHAR MachineName,
  70. PTCHAR DeviceID
  71. );
  72. //
  73. // Search thread Functions
  74. //
  75. #define SEARCH_NULL 0
  76. #define SEARCH_EXIT 1
  77. #define SEARCH_DRIVERS 2
  78. #define SEARCH_DELAY 3
  79. #define SEARCH_DETECT 4
  80. #define SEARCH_PNPENUM 5
  81. #define WUM_DELAYTIMER (WM_USER+280)
  82. #define WUM_DOINSTALL (WM_USER+281)
  83. #define WUM_DETECT (WM_USER+282)
  84. #define WUM_PNPENUMERATE (WM_USER+283)
  85. #define WUM_RESOURCEPICKER (WM_USER+284)
  86. #define MAX_MESSAGE_STRING 512
  87. #define MAX_MESSAGE_TITLE 50
  88. typedef struct _SearchThreadData {
  89. HWND hDlg;
  90. HANDLE hThread;
  91. HANDLE RequestEvent;
  92. HANDLE ReadyEvent;
  93. HANDLE CancelEvent;
  94. ULONG Param;
  95. UCHAR Function;
  96. BOOLEAN CancelRequest;
  97. LPTSTR Path;
  98. } SEARCHTHREAD, *PSEARCHTHREAD;
  99. typedef struct _ClassDeviceInfo {
  100. HDEVINFO Missing;
  101. HDEVINFO Detected;
  102. } CLASSDEVINFO, *PCLASSDEVINFO;
  103. typedef struct _DeviceDetectionData {
  104. HWND hDlg;
  105. LPGUID ClassGuid;
  106. DWORD ClassProgress;
  107. UCHAR TotalProgress;
  108. BOOLEAN Reboot;
  109. BOOLEAN MissingOrNew;
  110. CLASSDEVINFO ClassDevInfo[1];
  111. } DEVICEDETECTION, *PDEVICEDETECTION;
  112. typedef struct _NewDeviceWizardExtension {
  113. HPROPSHEETPAGE hPropSheet;
  114. HPROPSHEETPAGE hPropSheetEnd; // optional
  115. SP_NEWDEVICEWIZARD_DATA DeviceWizardData;
  116. } WIZARDEXTENSION, *PWIZARDEXTENSION;
  117. typedef struct _HardwareWizard {
  118. HDEVINFO hDeviceInfo;
  119. HDEVINFO PNPEnumDeviceInfo;
  120. INT PrevPage;
  121. INT EnterFrom;
  122. INT EnterInto;
  123. DWORD ClassGuidNum;
  124. DWORD ClassGuidSize;
  125. LPGUID ClassGuidList;
  126. LPGUID ClassGuidSelected;
  127. GUID lvClassGuidSelected;
  128. GUID SavedClassGuid;
  129. HCURSOR IdcWait;
  130. HCURSOR IdcAppStarting;
  131. HCURSOR IdcArrow;
  132. HCURSOR CurrCursor;
  133. HFONT hfontTextMarlett;
  134. HFONT hfontTextBold;
  135. HFONT hfontTextBigBold;
  136. INT cyText;
  137. PSEARCHTHREAD SearchThread;
  138. PDEVICEDETECTION DeviceDetection; // used by detect code
  139. SP_DEVINFO_DATA DeviceInfoData;
  140. DWORD AnalyzeResult;
  141. HWND hwndProbList;
  142. DEVINST DevInst;
  143. DEVINST ProblemDevInst;
  144. SP_INSTALLWIZARD_DATA InstallDynaWiz;
  145. HPROPSHEETPAGE SelectDevicePage;
  146. SP_CLASSIMAGELIST_DATA ClassImageList;
  147. BOOL Registered;
  148. BOOL Installed;
  149. BOOL InstallPending;
  150. BOOL Cancelled;
  151. BOOL CopyFilesOnly;
  152. BOOL FoundPnPDevices;
  153. BOOL ExitDetect;
  154. BOOL PromptForReboot;
  155. BOOL RunTroubleShooter;
  156. BOOL Shutdown;
  157. DWORD Reboot;
  158. DWORD LastError;
  159. WIZARDEXTENSION WizExtPreSelect;
  160. WIZARDEXTENSION WizExtSelect;
  161. WIZARDEXTENSION WizExtUnplug;
  162. WIZARDEXTENSION WizExtPreAnalyze;
  163. WIZARDEXTENSION WizExtPostAnalyze;
  164. WIZARDEXTENSION WizExtFinishInstall;
  165. TCHAR ClassName[MAX_CLASS_NAME_LEN];
  166. TCHAR ClassDescription[LINE_LEN];
  167. TCHAR DriverDescription[LINE_LEN];
  168. } HARDWAREWIZ, *PHARDWAREWIZ;
  169. #define NUMPROPPAGES 22
  170. typedef struct _HardwareWizPropertySheet {
  171. PROPSHEETHEADER PropSheetHeader;
  172. HPROPSHEETPAGE PropSheetPages[NUMPROPPAGES];
  173. } HDWPROPERTYSHEET, *PHDWPROPERTYSHEET;
  174. #define TNULL ((TCHAR)0)
  175. typedef BOOL
  176. (CALLBACK* ADDDEVNODETOLIST_CALLBACK)(
  177. PHARDWAREWIZ HardwareWiz,
  178. PSP_DEVINFO_DATA DeviceInfoData
  179. );
  180. INT_PTR CALLBACK
  181. HdwIntroDlgProc(
  182. HWND hDlg,
  183. UINT message,
  184. WPARAM wParam,
  185. LPARAM lParam
  186. );
  187. INT_PTR CALLBACK
  188. HdwConnectedDlgProc(
  189. HWND hDlg,
  190. UINT wMsg,
  191. WPARAM wParam,
  192. LPARAM lParam
  193. );
  194. INT_PTR CALLBACK
  195. HdwConnectedFinishDlgProc(
  196. HWND hDlg,
  197. UINT wMsg,
  198. WPARAM wParam,
  199. LPARAM lParam
  200. );
  201. INT_PTR CALLBACK
  202. HdwProbListDlgProc(
  203. HWND hDlg,
  204. UINT message,
  205. WPARAM wParam,
  206. LPARAM lParam
  207. );
  208. INT_PTR CALLBACK
  209. HdwProbListFinishDlgProc(
  210. HWND hDlg,
  211. UINT wMsg,
  212. WPARAM wParam,
  213. LPARAM lParam
  214. );
  215. INT_PTR CALLBACK
  216. HdwClassListDlgProc(
  217. HWND hDlg,
  218. UINT message,
  219. WPARAM wParam,
  220. LPARAM lParam
  221. );
  222. INT_PTR CALLBACK
  223. HdwDevicePropDlgProc(
  224. HWND hDlg,
  225. UINT message,
  226. WPARAM wParam,
  227. LPARAM lParam
  228. );
  229. INT_PTR CALLBACK
  230. HdwPnpEnumDlgProc(
  231. HWND hDlg,
  232. UINT wMsg,
  233. WPARAM wParam,
  234. LPARAM lParam
  235. );
  236. INT_PTR CALLBACK
  237. HdwPnpFinishDlgProc(
  238. HWND hDlg,
  239. UINT wMsg,
  240. WPARAM wParam,
  241. LPARAM lParam
  242. );
  243. INT_PTR CALLBACK
  244. HdwAskDetectDlgProc(
  245. HWND hDlg,
  246. UINT wMsg,
  247. WPARAM wParam,
  248. LPARAM lParam
  249. );
  250. INT_PTR CALLBACK
  251. HdwDetectionDlgProc(
  252. HWND hDlg,
  253. UINT wMsg,
  254. WPARAM wParam,
  255. LPARAM lParam
  256. );
  257. INT_PTR CALLBACK
  258. HdwDetectInstallDlgProc(
  259. HWND hDlg,
  260. UINT wMsg,
  261. WPARAM wParam,
  262. LPARAM lParam
  263. );
  264. INT_PTR CALLBACK
  265. HdwDetectRebootDlgProc(
  266. HWND hDlg,
  267. UINT wMsg,
  268. WPARAM wParam,
  269. LPARAM lParam
  270. );
  271. INT_PTR CALLBACK
  272. HdwPickClassDlgProc(
  273. HWND hDlg,
  274. UINT wMsg,
  275. WPARAM wParam,
  276. LPARAM lParam
  277. );
  278. INT_PTR CALLBACK
  279. HdwSelectDeviceDlgProc(
  280. HWND hDlg,
  281. UINT wMsg,
  282. WPARAM wParam,
  283. LPARAM lParam
  284. );
  285. INT_PTR CALLBACK
  286. HdwAnalyzeDlgProc(
  287. HWND hDlg,
  288. UINT wMsg,
  289. WPARAM wParam,
  290. LPARAM lParam
  291. );
  292. INT_PTR CALLBACK
  293. HdwInstallDevDlgProc(
  294. HWND hDlg,
  295. UINT wMsg,
  296. WPARAM wParam,
  297. LPARAM lParam
  298. );
  299. INT_PTR CALLBACK
  300. HdwAddDeviceFinishDlgProc(
  301. HWND hDlg,
  302. UINT wMsg,
  303. WPARAM wParam,
  304. LPARAM lParam
  305. );
  306. INT_PTR CALLBACK
  307. InstallNewDeviceDlgProc(
  308. HWND hDlg,
  309. UINT message,
  310. WPARAM wParam,
  311. LPARAM lParam
  312. );
  313. INT_PTR CALLBACK
  314. WizExtPreSelectDlgProc(
  315. HWND hDlg,
  316. UINT wMsg,
  317. WPARAM wParam,
  318. LPARAM lParam
  319. );
  320. INT_PTR CALLBACK
  321. WizExtSelectDlgProc(
  322. HWND hDlg,
  323. UINT wMsg,
  324. WPARAM wParam,
  325. LPARAM lParam
  326. );
  327. INT_PTR CALLBACK
  328. WizExtPreAnalyzeDlgProc(
  329. HWND hDlg,
  330. UINT wMsg,
  331. WPARAM wParam,
  332. LPARAM lParam
  333. );
  334. INT_PTR CALLBACK
  335. WizExtPreAnalyzeEndDlgProc(
  336. HWND hDlg,
  337. UINT wMsg,
  338. WPARAM wParam,
  339. LPARAM lParam
  340. );
  341. INT_PTR CALLBACK
  342. WizExtPostAnalyzeDlgProc(
  343. HWND hDlg,
  344. UINT wMsg,
  345. WPARAM wParam,
  346. LPARAM lParam
  347. );
  348. INT_PTR CALLBACK
  349. WizExtPostAnalyzeEndDlgProc(
  350. HWND hDlg,
  351. UINT wMsg,
  352. WPARAM wParam,
  353. LPARAM lParam
  354. );
  355. INT_PTR CALLBACK
  356. WizExtFinishInstallDlgProc(
  357. HWND hDlg,
  358. UINT wMsg,
  359. WPARAM wParam,
  360. LPARAM lParam
  361. );
  362. INT_PTR CALLBACK
  363. WizExtFinishInstallEndDlgProc(
  364. HWND hDlg,
  365. UINT wMsg,
  366. WPARAM wParam,
  367. LPARAM lParam
  368. );
  369. PHDWPROPERTYSHEET
  370. HdwWizard(
  371. HWND hwndParent,
  372. PHARDWAREWIZ HardwareWiz,
  373. int StartPageId
  374. );
  375. //
  376. // miscutil.c
  377. //
  378. VOID
  379. HdwWizPropagateMessage(
  380. HWND hWnd,
  381. UINT uMessage,
  382. WPARAM wParam,
  383. LPARAM lParam
  384. );
  385. LONG
  386. HdwBuildClassInfoList(
  387. PHARDWAREWIZ HardwareWiz,
  388. DWORD ClassListFlags
  389. );
  390. int
  391. HdwMessageBox(
  392. HWND hWnd,
  393. LPTSTR szIdText,
  394. LPTSTR szIdCaption,
  395. UINT Type
  396. );
  397. LONG
  398. HdwUnhandledExceptionFilter(
  399. struct _EXCEPTION_POINTERS *ExceptionInfo
  400. );
  401. BOOL
  402. NoPrivilegeWarning(
  403. HWND hWnd
  404. );
  405. VOID
  406. _OnSysColorChange(
  407. HWND hWnd,
  408. WPARAM wParam,
  409. LPARAM lParam
  410. );
  411. void
  412. LoadText(
  413. PTCHAR szText,
  414. int SizeText,
  415. int nStartString,
  416. int nEndString
  417. );
  418. void
  419. InstallFailedWarning(
  420. HWND hDlg,
  421. PHARDWAREWIZ HardwareWiz
  422. );
  423. void
  424. SetDlgText(
  425. HWND hDlg,
  426. int iControl,
  427. int nStartString,
  428. int nEndString
  429. );
  430. void
  431. SetDriverDescription(
  432. HWND hDlg,
  433. int iControl,
  434. PHARDWAREWIZ HardwareWiz
  435. );
  436. HPROPSHEETPAGE
  437. CreateWizExtPage(
  438. int PageResourceId,
  439. DLGPROC pfnDlgProc,
  440. PHARDWAREWIZ HardwareWiz
  441. );
  442. BOOL
  443. AddClassWizExtPages(
  444. HWND hwndParentDlg,
  445. PHARDWAREWIZ HardwareWiz,
  446. PSP_NEWDEVICEWIZARD_DATA DeviceWizardData,
  447. DI_FUNCTION InstallFunction
  448. );
  449. void
  450. RemoveClassWizExtPages(
  451. HWND hwndParentDlg,
  452. PSP_NEWDEVICEWIZARD_DATA DeviceWizardData
  453. );
  454. BOOL
  455. IsDeviceHidden(
  456. PSP_DEVINFO_DATA DeviceInfoData
  457. );
  458. BOOL
  459. ShutdownMachine(
  460. HWND hWnd
  461. );
  462. int
  463. DeviceProperties(
  464. HWND hWnd,
  465. DEVNODE DevNode,
  466. ULONG Flags
  467. );
  468. //
  469. // devcfg.c
  470. //
  471. typedef void
  472. (*PFNDETECTPROBCALLBACK)(
  473. PHARDWAREWIZ HardwareWiz,
  474. DEVINST DevInst,
  475. ULONG Problem
  476. );
  477. BOOL
  478. BuildDeviceListView(
  479. PHARDWAREWIZ HardwareWiz,
  480. HWND hwndListView,
  481. BOOL ShowHiddenDevices,
  482. DEVINST SelectedDevInst,
  483. DWORD *DevicesDetected,
  484. ADDDEVNODETOLIST_CALLBACK AddDevNodeToListCallBack
  485. );
  486. PTCHAR
  487. BuildFriendlyName(
  488. DEVINST DevInst
  489. );
  490. extern TCHAR szUnknown[64];
  491. extern TCHAR szUnknownDevice[64];
  492. //
  493. // sthread.c
  494. //
  495. LONG
  496. CreateSearchThread(
  497. PHARDWAREWIZ HardwareWiz
  498. );
  499. void
  500. DestroySearchThread(
  501. PSEARCHTHREAD SearchThread
  502. );
  503. BOOL
  504. SearchThreadRequest(
  505. PSEARCHTHREAD SearchThread,
  506. HWND hDlg,
  507. UCHAR Function,
  508. ULONG Param
  509. );
  510. void
  511. CancelSearchRequest(
  512. PHARDWAREWIZ HardwareWiz
  513. );
  514. //
  515. // install.c
  516. //
  517. void
  518. InstallSilentChildSiblings(
  519. HWND hwndParent,
  520. PHARDWAREWIZ HardwareWiz,
  521. DEVINST DeviceInstance,
  522. BOOL ReinstallAll
  523. );
  524. //
  525. // pnpenum.c
  526. //
  527. DWORD
  528. PNPEnumerate(
  529. PHARDWAREWIZ HardwareWiz
  530. );
  531. //
  532. // detect.c
  533. //
  534. void
  535. BuildDeviceDetection(
  536. HWND hwndParent,
  537. PHARDWAREWIZ HardwareWiz
  538. );
  539. //
  540. // finish.c
  541. //
  542. DWORD
  543. HdwRemoveDevice(
  544. PHARDWAREWIZ HardwareWiz
  545. );
  546. BOOL
  547. DeviceHasResources(
  548. DEVINST DeviceInst
  549. );
  550. void
  551. DisplayResource(
  552. PHARDWAREWIZ HardwareWiz,
  553. HWND hWndParent,
  554. BOOL NeedsForcedConfig
  555. );
  556. //
  557. // getdev.c
  558. //
  559. PTCHAR
  560. DeviceProblemText(
  561. DEVNODE DevNode,
  562. ULONG Status,
  563. ULONG ProblemNumber
  564. );
  565. BOOL
  566. ProblemDeviceListFilter(
  567. PHARDWAREWIZ HardwareWiz,
  568. PSP_DEVINFO_DATA DeviceInfoData
  569. );
  570. //
  571. // config mgr privates
  572. //
  573. DWORD
  574. CMP_WaitNoPendingInstallEvents(
  575. IN DWORD dwTimeout
  576. );
  577. #ifdef DBG
  578. void
  579. Trace(
  580. LPCTSTR format,
  581. ...
  582. );
  583. #define TRACE( args ) Trace args
  584. #else
  585. #define TRACE( args )
  586. #endif // DBG