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.

592 lines
20 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: N C S E T U P . H
  7. //
  8. // Contents: HRESULT wrappers for the Setup Api.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 16 Apr 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #ifndef _NCSETUP_H_
  17. #define _NCSETUP_H_
  18. #include <setupapi.h>
  19. #include "ncstring.h"
  20. enum SD_DEID_FLAG_TYPE
  21. {
  22. SDDFT_FLAGS,
  23. SDDFT_FLAGSEX,
  24. };
  25. enum SD_FLAGS_BINARY_OP
  26. {
  27. SDFBO_AND,
  28. SDFBO_OR,
  29. SDFBO_XOR,
  30. };
  31. //+---------------------------------------------------------------------------
  32. // Lower level wrappers
  33. //
  34. HRESULT
  35. HrSetupCommitFileQueue (HWND hwndOwner, HSPFILEQ hfq,
  36. PSP_FILE_CALLBACK pfc, PVOID pvCtx);
  37. HRESULT
  38. HrSetupInitDefaultQueueCallbackEx (HWND hwndOwner,
  39. HWND hwndAlternate,
  40. UINT uMsg,
  41. DWORD dwReserved1,
  42. PVOID dwReserved2,
  43. PVOID* ppvCtx);
  44. HRESULT
  45. HrSetupOpenFileQueue (HSPFILEQ* phfq);
  46. HRESULT
  47. HrSetupOpenInfFile (PCWSTR pszFileName,
  48. PCWSTR pszInfClass,
  49. DWORD dwInfStyle,
  50. UINT* punErrorLine,
  51. HINF* phinf);
  52. HRESULT
  53. HrSetupFindFirstLine (HINF hinf,
  54. PCWSTR pszSection,
  55. PCWSTR pszKey,
  56. INFCONTEXT* pctx);
  57. HRESULT
  58. HrSetupFindNextLine (const INFCONTEXT& ctxIn,
  59. INFCONTEXT* pctxOut);
  60. HRESULT
  61. HrSetupFindNextMatchLine (const INFCONTEXT& ctxIn,
  62. PCWSTR pszKey,
  63. INFCONTEXT* pctxOut);
  64. HRESULT
  65. HrSetupGetLineByIndex (HINF hinf,
  66. PCWSTR pszSection,
  67. DWORD dwIndex,
  68. INFCONTEXT* pctx);
  69. HRESULT
  70. HrSetupGetLineCount (HINF hinf,
  71. PCWSTR pszSection,
  72. ULONG* pulCount);
  73. HRESULT
  74. HrSetupGetBinaryField (const INFCONTEXT& ctx,
  75. DWORD dwFieldIndex,
  76. BYTE* pbBuf, DWORD cbBuf,
  77. DWORD* pbRequired);
  78. HRESULT
  79. HrSetupGetIntField (const INFCONTEXT& ctx,
  80. DWORD dwFieldIndex,
  81. INT* pnValue);
  82. HRESULT
  83. HrSetupGetMultiSzField (const INFCONTEXT& ctx,
  84. DWORD dwFieldIndex,
  85. PWSTR pszBuf, DWORD cchBuf,
  86. DWORD* pcchRequired);
  87. HRESULT
  88. HrSetupGetMultiSzFieldWithAlloc (const INFCONTEXT& ctx,
  89. DWORD dwFieldIndex,
  90. PWSTR* ppszBuf);
  91. HRESULT
  92. HrSetupGetStringField (const INFCONTEXT& ctx,
  93. DWORD dwFieldIndex,
  94. tstring* pstr);
  95. HRESULT
  96. HrSetupGetStringField (const INFCONTEXT& ctx,
  97. DWORD dwFieldIndex,
  98. PWSTR pszBuf, DWORD cchBuf,
  99. DWORD* pcchRequired);
  100. HRESULT
  101. HrSetupScanFileQueueWithNoCallback (HSPFILEQ hfq, DWORD dwFlags,
  102. HWND hwnd, PDWORD pdwResult);
  103. VOID
  104. SetupCloseInfFileSafe(HINF hinf);
  105. //+---------------------------------------------------------------------------
  106. // Intermediate functionality
  107. //
  108. HRESULT
  109. HrSetupGetMultiSzFieldMapToDword (const INFCONTEXT& ctx,
  110. DWORD dwFieldIndex,
  111. const MAP_SZ_DWORD* aMapSzDword,
  112. UINT cMapSzDword,
  113. DWORD* pdwValue);
  114. HRESULT
  115. HrSetupGetStringFieldMapToDword (const INFCONTEXT& ctx,
  116. DWORD dwFieldIndex,
  117. const MAP_SZ_DWORD* aMapSzDword,
  118. UINT cMapSzDword,
  119. DWORD* pdwValue);
  120. HRESULT
  121. HrSetupGetStringFieldAsBool (const INFCONTEXT& ctx,
  122. DWORD dwFieldIndex,
  123. BOOL* pfValue);
  124. //+---------------------------------------------------------------------------
  125. // Find first and get
  126. //
  127. HRESULT
  128. HrSetupGetFirstDword (HINF hinf,
  129. PCWSTR pszSection,
  130. PCWSTR pszKey,
  131. DWORD* pdwValue);
  132. HRESULT
  133. HrSetupGetFirstString (HINF hinf,
  134. PCWSTR pszSection,
  135. PCWSTR pszKey,
  136. tstring* pstr);
  137. HRESULT
  138. HrSetupGetFirstMultiSzFieldWithAlloc (HINF hinf, PCWSTR szSection,
  139. PCWSTR szKey, PWSTR *pszOut);
  140. HRESULT
  141. HrSetupGetFirstMultiSzMapToDword (HINF hinf,
  142. PCWSTR pszSection,
  143. PCWSTR pszKey,
  144. const MAP_SZ_DWORD* aMapSzDword,
  145. UINT cMapSzDword,
  146. DWORD* pdwValue);
  147. HRESULT
  148. HrSetupGetFirstStringMapToDword (HINF hinf,
  149. PCWSTR pszSection,
  150. PCWSTR pszKey,
  151. const MAP_SZ_DWORD* aMapSzDword,
  152. UINT cMapSzDword,
  153. DWORD* pdwValue);
  154. HRESULT
  155. HrSetupGetFirstStringAsBool (HINF hinf,
  156. PCWSTR pszSection,
  157. PCWSTR pszKey,
  158. BOOL* pfValue);
  159. HRESULT
  160. HrSetupGetInfInformation (LPCVOID pvInfSpec,
  161. DWORD dwSearchControl,
  162. PSP_INF_INFORMATION* ppinfInfo);
  163. HRESULT
  164. HrSetupIsValidNt5Inf (HINF hinf);
  165. HRESULT
  166. HrSetupQueryInfVersionInformation (PSP_INF_INFORMATION pinfInfo,
  167. UINT uiIndex, PCWSTR szKey,
  168. PWSTR* ppszInfo);
  169. //+--------------------------------------------------------------------------
  170. // SetupDi* wrappers and helpers
  171. //
  172. HRESULT
  173. HrSetupCopyOemInf(IN const tstring& strSourceName,
  174. IN const tstring& strSourceMediaLocation, OPTIONAL
  175. IN DWORD dwSourceMediaType, IN DWORD dwCopyStyle,
  176. OUT tstring* pstrDestFilename, OPTIONAL
  177. OUT tstring* pstrDestFilenameComponent OPTIONAL);
  178. HRESULT
  179. HrSetupCopyOemInfBuffer(
  180. IN PCWSTR pszSourceName,
  181. IN PCWSTR pszSourceMediaLocation, OPTIONAL
  182. IN DWORD SourceMediaType,
  183. IN DWORD CopyStyle,
  184. OUT PWSTR pszDestFilename,
  185. IN DWORD cchDestFilename,
  186. OUT PWSTR* ppszDestFilenameComponent OPTIONAL);
  187. HRESULT
  188. HrSetupDiBuildDriverInfoList(IN HDEVINFO hdi, IN OUT PSP_DEVINFO_DATA pdeid,
  189. IN DWORD dwDriverType);
  190. HRESULT
  191. HrSetupDiCallClassInstaller(DI_FUNCTION dif, HDEVINFO hdi,
  192. PSP_DEVINFO_DATA pdeid);
  193. HRESULT
  194. HrSetupDiCreateDeviceInfo(IN HDEVINFO hdi, IN PCWSTR szDeviceName,
  195. IN const GUID& guidClass, PCWSTR szDesc,
  196. IN HWND hwndParent, IN DWORD dwFlags,
  197. OUT PSP_DEVINFO_DATA pdeid);
  198. HRESULT
  199. HrSetupDiEnumDeviceInfo(IN HDEVINFO hdi, IN DWORD dwIndex,
  200. PSP_DEVINFO_DATA pdeid);
  201. HRESULT
  202. HrSetupDiEnumDriverInfo(IN HDEVINFO hdi, PSP_DEVINFO_DATA pdeid,
  203. IN DWORD dwDriverType, IN DWORD dwIndex,
  204. OUT PSP_DRVINFO_DATA pdrid);
  205. HRESULT
  206. HrSetupDiSelectBestCompatDrv(IN HDEVINFO hdi,
  207. IN OUT PSP_DEVINFO_DATA pdeid);
  208. HRESULT
  209. HrSetupDiGetClassDevs (
  210. IN const GUID* pguidClass, OPTIONAL
  211. IN PCWSTR pszEnumerator, OPTIONAL
  212. IN HWND hwndParent, OPTIONAL
  213. IN DWORD dwFlags,
  214. OUT HDEVINFO* phdi);
  215. HRESULT
  216. HrSetupDiGetDeviceInfoListClass(IN HDEVINFO hdi, OUT GUID* pGuid);
  217. HRESULT
  218. HrSetupDiGetDeviceInstanceId(IN HDEVINFO hdi,
  219. IN PSP_DEVINFO_DATA pdeid,
  220. OUT PWSTR pszId,
  221. IN DWORD cchId,
  222. OUT DWORD* cchRequired);
  223. HRESULT
  224. HrSetupDiInstallDevice(IN HDEVINFO hdi, IN OUT PSP_DEVINFO_DATA pdeid);
  225. HRESULT
  226. HrSetupDiOpenDevRegKey(IN HDEVINFO hdi,
  227. IN PSP_DEVINFO_DATA pdeid, IN DWORD dwScope,
  228. IN DWORD dwHwProfile, IN DWORD dwKeyType,
  229. IN REGSAM samDesired, OUT HKEY* phkey);
  230. HRESULT
  231. HrSetupDiSetClassInstallParams(IN HDEVINFO hdi, IN PSP_DEVINFO_DATA pdeid,
  232. IN PSP_CLASSINSTALL_HEADER pcih,
  233. IN DWORD cbSize);
  234. HRESULT
  235. HrSetupDiGetFixedSizeClassInstallParams(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid,
  236. PSP_CLASSINSTALL_HEADER pcih,
  237. int cbSize);
  238. HRESULT
  239. HrSetupDiGetSelectedDriver(IN HDEVINFO hdi, IN PSP_DEVINFO_DATA pdeid,
  240. OUT PSP_DRVINFO_DATA pdrid);
  241. HRESULT
  242. HrSetupDiGetDriverInfoDetail(IN HDEVINFO hdi, IN PSP_DEVINFO_DATA pdeid,
  243. IN PSP_DRVINFO_DATA pdrid,
  244. OUT PSP_DRVINFO_DETAIL_DATA* ppdridd);
  245. HRESULT
  246. HrSetupDiSetSelectedDriver(IN HDEVINFO hdi, IN PSP_DEVINFO_DATA pdeid,
  247. IN OUT PSP_DRVINFO_DATA pdrid);
  248. HRESULT
  249. HrSetupDiCreateDevRegKey(IN HDEVINFO hdi,
  250. IN PSP_DEVINFO_DATA pdeid, IN DWORD dwScope,
  251. IN DWORD dwHwProfile, IN DWORD dwKeyType,
  252. IN HINF hinf,
  253. PCWSTR szInfSectionName,
  254. OUT HKEY* phkey);
  255. HRESULT
  256. HrSetupDiGetActualSectionToInstall(IN HINF hinf,
  257. IN PCWSTR szSectionName,
  258. OUT tstring* pstrActualSectionName,
  259. OUT tstring* pstrExtension OPTIONAL);
  260. HRESULT
  261. HrSetupDiGetActualSectionToInstallWithAlloc(IN HINF hinf,
  262. IN PWSTR pszSection,
  263. OUT PWSTR* ppszActualSection,
  264. OUT PWSTR* ppszExtension OPTIONAL);
  265. HRESULT
  266. HrSetupDiGetActualSectionToInstallWithBuffer(
  267. IN HINF hinf,
  268. IN PCWSTR pszSection,
  269. OUT PWSTR pszActualSection,
  270. IN DWORD cchActualSection,
  271. OUT DWORD* pcchRequired,
  272. OUT PWSTR* ppszExtension OPTIONAL);
  273. HRESULT
  274. HrSetupDiGetDeviceInstallParams(IN const HDEVINFO hdi,
  275. IN const PSP_DEVINFO_DATA pdeid, OPTIONAL
  276. OUT PSP_DEVINSTALL_PARAMS pdeip);
  277. HRESULT
  278. HrSetupDiGetDriverInstallParams(IN const HDEVINFO hdi,
  279. IN const PSP_DEVINFO_DATA pdeid, OPTIONAL
  280. IN const PSP_DRVINFO_DATA pdrid,
  281. OUT PSP_DRVINSTALL_PARAMS pdrip);
  282. void
  283. SetupDiSetConfigFlags(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid, DWORD dwFlags,
  284. SD_FLAGS_BINARY_OP eOp);
  285. HRESULT
  286. HrSetupDiSetDeviceInstallParams(IN const HDEVINFO hdi,
  287. IN const PSP_DEVINFO_DATA pdeid, OPTIONAL
  288. IN const PSP_DEVINSTALL_PARAMS pdeip);
  289. HRESULT
  290. HrSetupDiSetDriverInstallParams(IN const HDEVINFO hdi,
  291. IN const PSP_DEVINFO_DATA pdeid, OPTIONAL
  292. IN const PSP_DRVINFO_DATA pdrid,
  293. IN const PSP_DRVINSTALL_PARAMS pdrip);
  294. HRESULT
  295. HrSetupDiSetDeipFlags(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid,
  296. DWORD dwFlags, SD_DEID_FLAG_TYPE eFlagType,
  297. SD_FLAGS_BINARY_OP eOp);
  298. HRESULT
  299. HrSetupDiRemoveDevice(IN HDEVINFO hdi,
  300. IN PSP_DEVINFO_DATA pdeid);
  301. HRESULT
  302. HrSetupDiOpenDeviceInfo(IN const HDEVINFO hdi,
  303. IN PCWSTR szPnpInstanceId,
  304. IN HWND hwndParent, IN DWORD dwOpenFlags,
  305. OUT PSP_DEVINFO_DATA pdeid OPTIONAL);
  306. HRESULT
  307. HrSetupDiCreateDeviceInfoList(const GUID* pguidClass, HWND hwndParent,
  308. HDEVINFO* phdi);
  309. HRESULT
  310. HrSetupDiGetDeviceName(IN HDEVINFO hdi, PSP_DEVINFO_DATA pdeid,
  311. OUT PWSTR* ppszName);
  312. HRESULT
  313. HrSetupDiSetDeviceName (
  314. IN HDEVINFO hdi,
  315. IN PSP_DEVINFO_DATA pdeid,
  316. IN PCWSTR szDeviceName);
  317. HRESULT
  318. HrSetupDiGetDeviceRegistryPropertyWithAlloc(
  319. IN HDEVINFO hdi,
  320. IN PSP_DEVINFO_DATA pdeid,
  321. IN DWORD dwProperty,
  322. OUT DWORD* pdwRegType, OPTIONAL
  323. OUT BYTE** ppbBuffer);
  324. HRESULT
  325. HrSetupDiGetDeviceRegistryProperty(
  326. IN HDEVINFO hdi,
  327. IN PSP_DEVINFO_DATA pdeid,
  328. IN DWORD dwProperty,
  329. OUT DWORD* pdwRegType, OPTIONAL
  330. OUT BYTE* pbBuffer,
  331. IN DWORD cbBufferSize,
  332. OUT DWORD* pcbRequiredSize OPTIONAL
  333. );
  334. HRESULT
  335. HrSetupDiSetDeviceRegistryProperty(IN HDEVINFO hdi,
  336. IN OUT PSP_DEVINFO_DATA pdeid,
  337. IN DWORD dwProperty,
  338. IN const BYTE* pbBuffer,
  339. IN DWORD cbSize);
  340. HRESULT
  341. HrSetupDiSendPropertyChangeNotification(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid,
  342. DWORD dwStateChange, DWORD dwScope,
  343. DWORD dwProfileId);
  344. BOOL
  345. FSetupDiCheckIfRestartNeeded(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid);
  346. HRESULT
  347. HrSetupDiGetClassImageList(PSP_CLASSIMAGELIST_DATA pcild);
  348. HRESULT
  349. HrSetupDiDestroyClassImageList(PSP_CLASSIMAGELIST_DATA pcild);
  350. VOID
  351. SetupDiDestroyDeviceInfoListSafe(HDEVINFO hdi);
  352. HRESULT
  353. HrSetupDiGetClassImageIndex(PSP_CLASSIMAGELIST_DATA pcild,
  354. const GUID* pguidClass, INT* pnIndex);
  355. HRESULT
  356. HrSetupDiGetParentWindow(IN const HDEVINFO hdi,
  357. IN const PSP_DEVINFO_DATA pdeid,
  358. OUT HWND* phwndParent);
  359. HRESULT
  360. HrSetupInstallFilesFromInfSection(HINF hinf, HINF hinfLayout, HSPFILEQ hfq,
  361. PCWSTR szSection, PCWSTR szSourcePath,
  362. UINT ulFlags);
  363. HRESULT
  364. HrSetupInstallFromInfSection(HWND hwnd, HINF hinf, PCWSTR szSection,
  365. UINT ulFlags, HKEY hkey, PCWSTR szSource,
  366. UINT ulCopyFlags, PSP_FILE_CALLBACK pfc,
  367. PVOID pvCtx, HDEVINFO hdi,
  368. PSP_DEVINFO_DATA pdeid);
  369. HRESULT
  370. HrSetupInstallServicesFromInfSection(HINF hinf, PCWSTR szSection,
  371. DWORD dwFlags);
  372. HRESULT
  373. HrFindDeviceOnInterface (
  374. const GUID* pguidDeviceId,
  375. const GUID* pguidInterfaceId,
  376. PCWSTR pszwReferenceString,
  377. DWORD dwFlagsAndAttributes,
  378. HANDLE* phFile);
  379. HRESULT
  380. HrInstallSoftwareDeviceOnInterface (
  381. const GUID* pguidDeviceId,
  382. const GUID* pguidInterfaceId,
  383. PCWSTR pszwReferenceString,
  384. BOOL fForceInstall,
  385. PCWSTR pszwInfFilename,
  386. HWND hwndParent);
  387. #if defined(REMOTE_BOOT)
  388. HRESULT
  389. HrIsRemoteBootAdapter(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid);
  390. #endif
  391. //+---------------------------------------------------------------------------
  392. //
  393. // Class: CSetupInfFile
  394. //
  395. // Purpose: Handles operations on an INF file.
  396. //
  397. // Justification:
  398. // This is a class instead of seperate functions to allow us to move
  399. // towards the error handling model associated with throwing exceptions.
  400. // That is, when one of these objects is declared on the stack, and
  401. // an exception is thrown, it will clean itself up. (This object
  402. // does NOT explicitly throw any exceptions.)
  403. //
  404. class CSetupInfFile
  405. {
  406. public:
  407. CSetupInfFile ();
  408. ~CSetupInfFile () { EnsureClosed(); }
  409. void Close ();
  410. HRESULT HrOpen (PCWSTR pszFileName, PCWSTR pszInfClass,
  411. DWORD dwInfStyle, UINT* punErrorLine);
  412. HINF Hinf ();
  413. HRESULT HrGetDword (PCWSTR pszSection, PCWSTR pszKey,
  414. DWORD* pdwValue);
  415. HRESULT HrGetString (PCWSTR pszSection, PCWSTR pszKey,
  416. tstring* pstr);
  417. HRESULT HrGetStringAsBool (PCWSTR pszSection, PCWSTR pszKey,
  418. BOOL* pfValue);
  419. HRESULT HrGetStringMapToDword (PCWSTR pszSection, PCWSTR pszKey,
  420. const MAP_SZ_DWORD* aMapSzDword,
  421. UINT cMapSzDword,
  422. DWORD* pdwValue);
  423. HRESULT HrGetMultiSzMapToDword (PCWSTR pszSection, PCWSTR pszKey,
  424. const MAP_SZ_DWORD* aMapSzDword,
  425. UINT cMapSzDword,
  426. DWORD* pdwValue);
  427. protected:
  428. void EnsureClosed ();
  429. HINF m_hinf;
  430. };
  431. inline CSetupInfFile::CSetupInfFile ()
  432. {
  433. m_hinf = NULL;
  434. }
  435. inline
  436. HRESULT CSetupInfFile::HrOpen (PCWSTR pszFileName, PCWSTR pszInfClass,
  437. DWORD dwInfStyle, UINT* punErrorLine)
  438. {
  439. AssertSzH (!m_hinf, "You must first close the previous one you opened.");
  440. return HrSetupOpenInfFile (pszFileName, pszInfClass, dwInfStyle,
  441. punErrorLine, &m_hinf);
  442. }
  443. inline HINF CSetupInfFile::Hinf ()
  444. {
  445. AssertSzH (m_hinf, "You must call HrOpen first.");
  446. return m_hinf;
  447. }
  448. inline
  449. HRESULT CSetupInfFile::HrGetDword (PCWSTR pszSection, PCWSTR pszKey,
  450. DWORD* pdwValue)
  451. {
  452. return HrSetupGetFirstDword (Hinf(), pszSection, pszKey, pdwValue);
  453. }
  454. inline
  455. HRESULT CSetupInfFile::HrGetString (PCWSTR pszSection, PCWSTR pszKey,
  456. tstring* pstr)
  457. {
  458. return HrSetupGetFirstString (Hinf(), pszSection, pszKey, pstr);
  459. }
  460. inline
  461. HRESULT CSetupInfFile::HrGetStringAsBool (PCWSTR pszSection, PCWSTR pszKey,
  462. BOOL* pfValue)
  463. {
  464. return HrSetupGetFirstStringAsBool (Hinf(), pszSection, pszKey, pfValue);
  465. }
  466. inline
  467. HRESULT CSetupInfFile::HrGetStringMapToDword (PCWSTR pszSection, PCWSTR pszKey,
  468. const MAP_SZ_DWORD* aMapSzDword,
  469. UINT cMapSzDword,
  470. DWORD* pdwValue)
  471. {
  472. return HrSetupGetFirstStringMapToDword (Hinf(), pszSection, pszKey,
  473. aMapSzDword, cMapSzDword, pdwValue);
  474. }
  475. inline
  476. HRESULT CSetupInfFile::HrGetMultiSzMapToDword (PCWSTR pszSection, PCWSTR pszKey,
  477. const MAP_SZ_DWORD* aMapSzDword,
  478. UINT cMapSzDword,
  479. DWORD* pdwValue)
  480. {
  481. return HrSetupGetFirstMultiSzMapToDword (Hinf(), pszSection, pszKey,
  482. aMapSzDword, cMapSzDword, pdwValue);
  483. }
  484. inline BOOL
  485. IsValidHandle(HANDLE h)
  486. {
  487. return (h && INVALID_HANDLE_VALUE != h);
  488. }
  489. // Moved from oemupgrd.h
  490. //
  491. HRESULT HrInstallFromInfSectionInFile(IN HWND hwndParent,
  492. IN PCWSTR szInfName,
  493. IN PCWSTR szSection,
  494. IN HKEY hkeyRelative,
  495. IN BOOL fQuietInstall);
  496. #endif // _NCSETUP_H_