Source code of Windows XP (NT5)
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.

720 lines
12 KiB

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