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.

441 lines
17 KiB

  1. #ifndef __MACHINE_H_
  2. #define __MACHINE_H_
  3. /*++
  4. Copyright (C) Microsoft Corporation
  5. Module Name:
  6. machine.h
  7. Abstract:
  8. header file that declares CMachine, CDevInfoist and CMachineList classes
  9. Author:
  10. William Hsieh (williamh) created
  11. Revision History:
  12. --*/
  13. LRESULT CALLBACK dmNotifyWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  14. typedef BOOL (*LPFNINSTALLDEVINST)(HWND hwndParent, LPCTSTR DeviceId, BOOL UpdateDriver, DWORD* pReboot);
  15. typedef BOOL (*LPFNROLLBACKDRIVER)(HWND hwndParent, LPCTSTR RegistryKey, DWORD Flags, DWORD* pReboot);
  16. class CDevice;
  17. class CClass;
  18. class CComputer;
  19. class CLogConf;
  20. class CResDes;
  21. class CMachineList;
  22. class CFolder;
  23. #define DM_NOTIFY_TIMERID 0x444d4d44
  24. //This class represents SETUPAPI's <Device Information List>
  25. //
  26. // WARNING !!!
  27. // no copy constructor and assignment operator are provided ---
  28. // DO NOT ASSIGN A CDevInfoList from one to another!!!!!
  29. class CDevInfoList
  30. {
  31. public:
  32. CDevInfoList(HDEVINFO hDevInfo = INVALID_HANDLE_VALUE, HWND hwndParent = NULL)
  33. :m_hDevInfo(hDevInfo), m_hwndParent(hwndParent)
  34. {
  35. }
  36. virtual ~CDevInfoList()
  37. {
  38. if (INVALID_HANDLE_VALUE != m_hDevInfo)
  39. DiDestroyDeviceInfoList();
  40. }
  41. operator HDEVINFO()
  42. {
  43. return m_hDevInfo;
  44. }
  45. BOOL DiGetDeviceInfoListDetail(PSP_DEVINFO_LIST_DETAIL_DATA DetailData)
  46. {
  47. return SetupDiGetDeviceInfoListDetail(m_hDevInfo, DetailData);
  48. }
  49. BOOL DiOpenDeviceInfo(LPCTSTR DeviceID, HWND hwndParent, DWORD OpenFlags,
  50. PSP_DEVINFO_DATA DevData)
  51. {
  52. return SetupDiOpenDeviceInfo(m_hDevInfo, DeviceID, hwndParent, OpenFlags,
  53. DevData);
  54. }
  55. BOOL DiEnumDeviceInfo(DWORD Index, PSP_DEVINFO_DATA DevData)
  56. {
  57. return SetupDiEnumDeviceInfo(m_hDevInfo, Index, DevData);
  58. }
  59. BOOL DiBuildDriverInfoList(PSP_DEVINFO_DATA DevData, DWORD DriverType)
  60. {
  61. return SetupDiBuildDriverInfoList(m_hDevInfo, DevData, DriverType);
  62. }
  63. BOOL DiEnumDriverInfo(PSP_DEVINFO_DATA DevData, DWORD DriverType, DWORD Index,
  64. PSP_DRVINFO_DATA DrvData)
  65. {
  66. return SetupDiEnumDriverInfo(m_hDevInfo, DevData, DriverType, Index, DrvData);
  67. }
  68. BOOL DiDestroyDriverInfoList(PSP_DEVINFO_DATA DevData, DWORD DriverType)
  69. {
  70. return SetupDiDestroyDriverInfoList(m_hDevInfo, DevData, DriverType);
  71. }
  72. BOOL DiCallClassInstaller(DI_FUNCTION InstallFunction, PSP_DEVINFO_DATA DevData)
  73. {
  74. return SetupDiCallClassInstaller(InstallFunction, m_hDevInfo, DevData);
  75. }
  76. BOOL DiChangeState(PSP_DEVINFO_DATA DevData)
  77. {
  78. return SetupDiChangeState(m_hDevInfo, DevData);
  79. }
  80. HKEY DiOpenDevRegKey(PSP_DEVINFO_DATA DevData, DWORD Scope, DWORD HwProfile,
  81. DWORD KeyType, REGSAM samDesired)
  82. {
  83. return SetupDiOpenDevRegKey(m_hDevInfo, DevData, Scope, HwProfile,
  84. KeyType, samDesired);
  85. }
  86. BOOL DiGetDeviceRegistryProperty(PSP_DEVINFO_DATA DevData, DWORD Property,
  87. PDWORD PropertyDataType, PBYTE PropertyBuffer,
  88. DWORD PropertyBufferSize, PDWORD RequiredSize)
  89. {
  90. return SetupDiGetDeviceRegistryProperty(m_hDevInfo, DevData,
  91. Property, PropertyDataType,
  92. PropertyBuffer,
  93. PropertyBufferSize,
  94. RequiredSize
  95. );
  96. }
  97. BOOL DiGetDeviceInstallParams(PSP_DEVINFO_DATA DevData,
  98. PSP_DEVINSTALL_PARAMS DevInstParams)
  99. {
  100. return SetupDiGetDeviceInstallParams(m_hDevInfo, DevData, DevInstParams);
  101. }
  102. BOOL DiGetClassInstallParams(PSP_DEVINFO_DATA DevData,
  103. PSP_CLASSINSTALL_HEADER ClassInstallHeader,
  104. DWORD ClassInstallParamsSize,
  105. PDWORD RequiredSize)
  106. {
  107. return SetupDiGetClassInstallParams(m_hDevInfo, DevData,
  108. ClassInstallHeader,
  109. ClassInstallParamsSize,
  110. RequiredSize);
  111. }
  112. BOOL DiSetDeviceInstallParams(PSP_DEVINFO_DATA DevData,
  113. PSP_DEVINSTALL_PARAMS DevInstParams)
  114. {
  115. return SetupDiSetDeviceInstallParams(m_hDevInfo, DevData, DevInstParams);
  116. }
  117. BOOL DiSetClassInstallParams(PSP_DEVINFO_DATA DevData,
  118. PSP_CLASSINSTALL_HEADER ClassInstallHeader,
  119. DWORD ClassInstallParamsSize)
  120. {
  121. return SetupDiSetClassInstallParams(m_hDevInfo, DevData,
  122. ClassInstallHeader,
  123. ClassInstallParamsSize);
  124. }
  125. BOOL DiGetClassDevPropertySheet(PSP_DEVINFO_DATA DevData,
  126. LPPROPSHEETHEADER PropertySheetHeader,
  127. DWORD PagesAllowed,
  128. DWORD Flags)
  129. {
  130. return SetupDiGetClassDevPropertySheets(m_hDevInfo, DevData,
  131. PropertySheetHeader, PagesAllowed,
  132. NULL, Flags);
  133. }
  134. BOOL DiGetExtensionPropSheetPage(PSP_DEVINFO_DATA DevData,
  135. LPFNADDPROPSHEETPAGE pfnAddPropSheetPage,
  136. DWORD PageType,
  137. LPARAM lParam
  138. );
  139. BOOL DiGetSelectedDriver(PSP_DEVINFO_DATA DevData, PSP_DRVINFO_DATA DriverInfoData)
  140. {
  141. return SetupDiGetSelectedDriver(m_hDevInfo, DevData, DriverInfoData);
  142. }
  143. BOOL DiSetSelectedDriver(PSP_DEVINFO_DATA DevData, PSP_DRVINFO_DATA DriverInfoData)
  144. {
  145. return SetupDiSetSelectedDriver(m_hDevInfo, DevData, DriverInfoData);
  146. }
  147. BOOL DiTurnOnDiFlags(PSP_DEVINFO_DATA DevData, DWORD FlagMask );
  148. BOOL DiTurnOffDiFlags(PSP_DEVINFO_DATA DevData, DWORD FlagsMask);
  149. BOOL DiTurnOnDiExFlags(PSP_DEVINFO_DATA DevData, DWORD FlagMask );
  150. BOOL DiTurnOffDiExFlags(PSP_DEVINFO_DATA DevData, DWORD FlagsMask);
  151. BOOL InstallDevInst(HWND hwndParent, LPCTSTR DeviceID, BOOL UpdateDriver, DWORD* pReboot);
  152. BOOL RollbackDriver(HWND hwndParent, LPCTSTR RegistryKeyName, DWORD Flags, DWORD* pReboot);
  153. DWORD DiGetFlags(PSP_DEVINFO_DATA DevData = NULL);
  154. DWORD DiGetExFlags(PSP_DEVINFO_DATA DevData = NULL);
  155. void DiDestroyDeviceInfoList();
  156. HWND OwnerWindow()
  157. {
  158. return m_hwndParent;
  159. }
  160. protected:
  161. HDEVINFO m_hDevInfo;
  162. HWND m_hwndParent;
  163. private:
  164. CDevInfoList(const CDevInfoList&);
  165. CDevInfoList& operator=(const CDevInfoList&);
  166. };
  167. class CMachine : public CDevInfoList
  168. {
  169. public:
  170. CMachine(LPCTSTR MachineName = NULL);
  171. virtual ~CMachine();
  172. operator HMACHINE()
  173. {
  174. return m_hMachine;
  175. }
  176. LPCTSTR GetMachineDisplayName()
  177. {
  178. return (LPCTSTR)m_strMachineDisplayName;
  179. }
  180. LPCTSTR GetMachineFullName()
  181. {
  182. return (LPCTSTR)m_strMachineFullName;
  183. }
  184. LPCTSTR GetRemoteMachineFullName()
  185. {
  186. return m_IsLocal ? NULL : (LPCTSTR)m_strMachineFullName;
  187. }
  188. HMACHINE GetHMachine()
  189. {
  190. return m_hMachine;
  191. }
  192. BOOL IsLocal()
  193. {
  194. return m_IsLocal;
  195. }
  196. BOOL AttachFolder(CFolder* pFolder);
  197. void DetachFolder(CFolder* pFolder);
  198. BOOL IsFolderAttached(CFolder* pFolder);
  199. BOOL AttachPropertySheet(HWND hwndPropertySheet);
  200. void DetachPropertySheet(HWND hwndPropertySheet);
  201. HWND GetDeviceWindowHandle(LPCTSTR DeviceId);
  202. HWND GetClassWindowHandle(LPGUID ClassGuid);
  203. BOOL AttachChildMachine(CMachine* ChildMachine);
  204. void DetachChildMachine(CMachine* ChildMachine);
  205. BOOL Initialize(
  206. HWND hwndParent = NULL,
  207. LPCTSTR DeviceId = NULL,
  208. LPGUID ClassGuid = NULL
  209. );
  210. DWORD GetNumberOfDevices() const
  211. {
  212. return (DWORD)m_listDevice.GetCount();
  213. }
  214. BOOL GetFirstClass(CClass** ppClass, PVOID& Context);
  215. BOOL GetNextClass(CClass** ppClass, PVOID& Context);
  216. BOOL GetFirstDevice(CDevice** ppDevice, PVOID& Context);
  217. BOOL GetNextDevice(CDevice** ppDevice, PVOID& Context);
  218. CDevice* DevNodeToDevice(DEVNODE dn);
  219. BOOL Reenumerate();
  220. BOOL DoMiniRefresh();
  221. BOOL Refresh();
  222. BOOL DestroyNotifyWindow();
  223. int GetComputerIconIndex()
  224. {
  225. return m_ComputerIndex;
  226. }
  227. int GetResourceIconIndex()
  228. {
  229. return m_ResourceIndex;
  230. }
  231. BOOL ShouldPropertySheetDestroy()
  232. {
  233. return m_PropertySheetShoudDestroy;
  234. }
  235. void SetPropertySheetShouldDestroy()
  236. {
  237. m_PropertySheetShoudDestroy = TRUE;
  238. }
  239. BOOL GetInfDigitalSigner(LPCTSTR FullInfPath, String& DigitalSigner);
  240. BOOL DoNotCreateDevice(SC_HANDLE SCMHandle, LPGUID ClassGuid, DEVINST DevInst);
  241. BOOL IsUserAGuest()
  242. {
  243. return m_UserIsAGuest;
  244. }
  245. HDEVINFO DiCreateDeviceInfoList(LPGUID ClassGuid, HWND hwndParent)
  246. {
  247. return SetupDiCreateDeviceInfoListEx(ClassGuid, hwndParent,
  248. GetRemoteMachineFullName(), NULL);
  249. }
  250. HDEVINFO DiGetClassDevs(LPGUID ClassGuid, LPCTSTR Enumerator, HWND hwndParent, DWORD Flags)
  251. {
  252. return SetupDiGetClassDevsEx(ClassGuid, Enumerator, hwndParent,
  253. Flags, NULL, GetRemoteMachineFullName(), NULL
  254. );
  255. }
  256. HIMAGELIST DiGetClassImageList()
  257. {
  258. return m_ImageListData.ImageList;
  259. }
  260. BOOL DiBuildClassInfoList(DWORD Flags, LPGUID ClassGuid,
  261. DWORD ClassGuidListSize, PDWORD RequiredSize)
  262. {
  263. return SetupDiBuildClassInfoListEx(Flags, ClassGuid,
  264. ClassGuidListSize, RequiredSize,
  265. GetRemoteMachineFullName(), NULL);
  266. }
  267. HKEY DiOpenClassRegKey(LPGUID ClassGuid, REGSAM samDesired, DWORD Flags)
  268. {
  269. return SetupDiOpenClassRegKeyEx(ClassGuid, samDesired, Flags,
  270. GetRemoteMachineFullName(), NULL);
  271. }
  272. BOOL DiLoadClassIcon(LPGUID ClassGuid, HICON* LargeIcon, PINT MiniIconIndex)
  273. {
  274. return SetupDiLoadClassIcon(ClassGuid, LargeIcon, MiniIconIndex);
  275. }
  276. BOOL DiGetClassImageList(PSP_CLASSIMAGELIST_DATA pImageListData)
  277. {
  278. return SetupDiGetClassImageListEx(pImageListData,
  279. GetRemoteMachineFullName(), NULL);
  280. }
  281. BOOL DiDestroyClassImageList(PSP_CLASSIMAGELIST_DATA pImageListData)
  282. {
  283. return SetupDiDestroyClassImageList(pImageListData);
  284. }
  285. BOOL DiGetClassImageIndex(LPGUID ClassGuid, PINT ImageIndex)
  286. {
  287. return SetupDiGetClassImageIndex(&m_ImageListData, ClassGuid, ImageIndex);
  288. }
  289. BOOL DiClassNameFromGuid(LPGUID ClassGuid, LPTSTR ClassName,
  290. DWORD ClassNameSize, PDWORD RequiredSize)
  291. {
  292. return SetupDiClassNameFromGuidEx(ClassGuid, ClassName,
  293. ClassNameSize, RequiredSize,
  294. GetRemoteMachineFullName(), NULL);
  295. }
  296. BOOL DiGetClassFriendlyNameString(LPGUID Guid, String& strClass);
  297. BOOL DiDestroyDeviceInfoList(HDEVINFO hDevInfo)
  298. {
  299. return SetupDiDestroyDeviceInfoList(hDevInfo);
  300. }
  301. ///////////////////////////////////////////////////////////////////////////
  302. //// Configuration Manager APIs
  303. ////
  304. CONFIGRET GetLastCR()
  305. {
  306. return m_LastCR;
  307. }
  308. BOOL CmGetConfigFlags(DEVNODE dn, DWORD* pFlags);
  309. BOOL CmGetCapabilities(DEVNODE dn, DWORD* pCapabilities);
  310. BOOL CmGetDeviceIDString(DEVNODE dn, String& str);
  311. BOOL CmGetDescriptionString(DEVNODE dn, String& str);
  312. BOOL CmGetMFGString(DEVNODE dn, String& str);
  313. BOOL CmGetProviderString(DEVNODE dn, String& str);
  314. BOOL CmGetDriverDateString(DEVNODE dn, String& str);
  315. BOOL CmGetDriverDateData(DEVNODE dn, FILETIME *ft);
  316. BOOL CmGetDriverVersionString(DEVNODE dn, String& str);
  317. BOOL CmGetClassGuid(DEVNODE dn, GUID& Guid);
  318. BOOL CmGetStatus(DEVNODE dn, DWORD* pProblem, DWORD* pStatus);
  319. BOOL CmGetKnownLogConf(DEVNODE dn, LOG_CONF* plc, DWORD* plcType);
  320. BOOL CmReenumerate(DEVNODE dn, ULONG Flags);
  321. BOOL CmGetHwProfileFlags(DEVNODE dn, ULONG Profile, ULONG* pFlags);
  322. BOOL CmGetHwProfileFlags(LPCTSTR DeviceID, ULONG Profile, ULONG* pFlags);
  323. BOOL CmSetHwProfileFlags(DEVNODE dn, ULONG Profile, ULONG Flags);
  324. BOOL CmSetHwProfileFlags(LPCTSTR DeviceID, ULONG Profile, ULONG Flags);
  325. BOOL CmGetCurrentHwProfile(ULONG* phwpf);
  326. BOOL CmGetHwProfileInfo(int Index, PHWPROFILEINFO pHwProfileInfo);
  327. BOOL CmGetBusGuid(DEVNODE dn, LPGUID Guid);
  328. BOOL CmGetBusGuidString(DEVNODE dn, String& str);
  329. DEVNODE CmGetParent(DEVNODE dn);
  330. DEVNODE CmGetChild(DEVNODE dn);
  331. DEVNODE CmGetSibling(DEVNODE dn);
  332. DEVNODE CmGetRootDevNode();
  333. BOOL CmHasResources(DEVNODE dn);
  334. DWORD CmGetResDesDataSize(RES_DES rd);
  335. BOOL CmGetResDesData(RES_DES rd, PVOID pData, ULONG DataSize);
  336. BOOL CmGetNextResDes(PRES_DES prdNext, RES_DES rd, RESOURCEID ForResource,
  337. PRESOURCEID pTheResource);
  338. void CmFreeResDesHandle(RES_DES rd);
  339. void CmFreeResDes(PRES_DES prdPrev, RES_DES rd);
  340. void CmFreeLogConfHandle(LOG_CONF lc);
  341. BOOL CmGetFirstLogConf(DEVNODE dn, LOG_CONF* plc, ULONG Type);
  342. CONFIGRET CmGetRegistryProperty(DEVNODE dn, ULONG Property,
  343. PVOID pBuffer,
  344. ULONG* BufferSize);
  345. BOOL EnableRefresh(BOOL fEnable);
  346. BOOL ScheduleRefresh();
  347. void Lock()
  348. {
  349. EnterCriticalSection(&m_CriticalSection);
  350. }
  351. void Unlock()
  352. {
  353. LeaveCriticalSection(&m_CriticalSection);
  354. }
  355. CComputer* m_pComputer;
  356. CMachine* m_ParentMachine;
  357. UINT m_msgRefresh;
  358. private:
  359. // no copy constructor and no assigment operator
  360. CMachine(const CMachine& MachineSrc);
  361. CMachine& operator=(const CMachine& MachineSrc);
  362. BOOL BuildClassesFromGuidList(LPGUID GuidList, DWORD Guids);
  363. CONFIGRET CmGetRegistrySoftwareProperty(DEVNODE dn, LPCTSTR ValueName,
  364. PVOID pBuffer, ULONG* pBufferSize);
  365. void CreateDeviceTree(CDevice* pParent, CDevice* pSibling, DEVNODE dn);
  366. BOOL CreateClassesAndDevices(LPCTSTR DeviceId = NULL, LPGUID ClassGuid = NULL);
  367. void DestroyClassesAndDevices();
  368. BOOL CreateNotifyWindow();
  369. String m_strMachineDisplayName;
  370. String m_strMachineFullName;
  371. HMACHINE m_hMachine;
  372. CONFIGRET m_LastCR;
  373. CList<CClass*, CClass*> m_listClass;
  374. SP_CLASSIMAGELIST_DATA m_ImageListData;
  375. int m_ComputerIndex;
  376. int m_ResourceIndex;
  377. CList<CDevice*, CDevice*> m_listDevice;
  378. DWORD m_Flags;
  379. BOOL m_Initialized;
  380. BOOL m_IsLocal;
  381. BOOL m_PropertySheetShoudDestroy;
  382. BOOL m_UserIsAGuest;
  383. HWND m_hwndNotify;
  384. CList<CFolder*, CFolder*> m_listFolders;
  385. int m_RefreshDisableCounter;
  386. BOOL m_RefreshPending;
  387. BOOL m_ShowNonPresentDevices;
  388. CRITICAL_SECTION m_CriticalSection;
  389. CRITICAL_SECTION m_PropertySheetCriticalSection;
  390. CRITICAL_SECTION m_ChildMachineCriticalSection;
  391. CList<HWND, HWND> m_listPropertySheets;
  392. CList<CMachine*, CMachine*> m_listChildMachines;
  393. };
  394. class CMachineList
  395. {
  396. public:
  397. CMachineList() {};
  398. ~CMachineList();
  399. BOOL CreateMachine(LPCTSTR MachineName, CMachine** ppMachine);
  400. CMachine* FindMachine(LPCTSTR MachineName);
  401. private:
  402. CMachineList(const CMachineList& MachineListSrc);
  403. CMachineList& operator=(const CMachineList& MachineListSrc);
  404. CList<CMachine*, CMachine*> m_listMachines;
  405. };
  406. #endif //__MACHINE_H_