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.

572 lines
15 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File:
  7. //
  8. // Contents: Common routines for dealing with INetCfg interfaces.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 24 Mar 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #ifndef _NCNETCFG_H_
  17. #define _NCNETCFG_H_
  18. #include "ncbase.h"
  19. #include "nccom.h"
  20. #include "ncstring.h"
  21. #include "netcfgp.h"
  22. #include "netcfgx.h"
  23. BOOL
  24. FClassGuidFromComponentId (
  25. PCWSTR pszComponentId,
  26. const GUID** ppguidClass);
  27. BOOL
  28. FInfFileFromComponentId (
  29. PCWSTR pszComponentId,
  30. PWSTR pszInfFile);
  31. //+---------------------------------------------------------------------------
  32. //
  33. // Function: FEqualComponentId
  34. //
  35. // Purpose: Compares 2 components IDs to see if they are equal.
  36. //
  37. // Arguments:
  38. // pszComp1 [in] Name of first component ID.
  39. // pszComp2 [in] Name of second compoennt ID.
  40. //
  41. // Returns: TRUE if component IDs are equal, FALSE if not.
  42. //
  43. // Author: danielwe 9 Apr 1997
  44. //
  45. // Notes: Current comparison is case-INSENSITIVE
  46. //
  47. inline
  48. FEqualComponentId (
  49. PCWSTR pszComp1,
  50. PCWSTR pszComp2)
  51. {
  52. return !lstrcmpiW(pszComp1, pszComp2);
  53. }
  54. BOOL
  55. FGetInstanceGuidOfComponentFromAnswerFileMap (
  56. IN PCWSTR pszComponentId,
  57. OUT GUID* pguid);
  58. BOOL
  59. FGetInstanceGuidOfComponentInAnswerFile (
  60. PCWSTR pszComponentId,
  61. INetCfg* pnc,
  62. LPGUID pguid);
  63. enum FIBN_FLAGS
  64. {
  65. FIBN_NORMAL = 0x00000000,
  66. FIBN_PREFIX = 0x00000001
  67. };
  68. BOOL
  69. FIsBindingName (
  70. PCWSTR pszName,
  71. DWORD dwFlags,
  72. INetCfgBindingInterface* pncbi);
  73. BOOL
  74. FIsComponentId (
  75. PCWSTR pszComponentId,
  76. INetCfgComponent* pncc);
  77. struct NETWORK_INSTALL_PARAMS
  78. {
  79. DWORD dwSetupFlags;
  80. DWORD dwUpgradeFromBuildNo;
  81. PCWSTR pszAnswerFile;
  82. PCWSTR pszAnswerSection;
  83. };
  84. struct FILTER_INSTALL_PARAMS
  85. {
  86. void * pnccAdapter;
  87. void * pnccFilter;
  88. tstring * pstrInterface;
  89. };
  90. enum ARA_FLAGS
  91. {
  92. ARA_ADD = 0x01,
  93. ARA_REMOVE = 0x02,
  94. };
  95. HRESULT
  96. HrAddOrRemoveAdapter (
  97. INetCfg* pnc,
  98. PCWSTR pszComponentId,
  99. DWORD dwFlags,
  100. OBO_TOKEN* pOboToken,
  101. UINT cInstances,
  102. INetCfgComponent** ppncc);
  103. HRESULT
  104. HrCreateAndInitializeINetCfg (
  105. BOOL* pfInitCom,
  106. INetCfg** ppnc,
  107. BOOL fGetWriteLock,
  108. DWORD cmsTimeout,
  109. PCWSTR pszwClientDesc,
  110. PWSTR* ppszwClientDesc);
  111. HRESULT
  112. HrFindAndRemoveAllInstancesOfAdapter (
  113. INetCfg* pnc,
  114. PCWSTR pszwComponentId);
  115. HRESULT
  116. HrFindAndRemoveAllInstancesOfAdapters (
  117. INetCfg* pnc,
  118. ULONG cComponents,
  119. const PCWSTR* apszwComponentId);
  120. HRESULT
  121. HrFindAndRemoveComponent (
  122. INetCfg* pnc,
  123. const GUID* pguidClass,
  124. PCWSTR pszwComponentId,
  125. OBO_TOKEN* pOboToken);
  126. HRESULT
  127. HrFindAndRemoveComponents (
  128. INetCfg* pnc,
  129. ULONG cComponents,
  130. const GUID** apguidClass,
  131. const PCWSTR* apszwComponentId,
  132. OBO_TOKEN* pOboToken);
  133. HRESULT
  134. HrFindAndRemoveComponentsOboComponent (
  135. INetCfg* pnc,
  136. ULONG cComponents,
  137. const GUID** apguidClass,
  138. const PCWSTR* apszwComponentId,
  139. INetCfgComponent* pnccObo);
  140. HRESULT
  141. HrFindAndRemoveComponentsOboUser (
  142. INetCfg* pnc,
  143. ULONG cComponents,
  144. const GUID** apguidClass,
  145. const PCWSTR* apszwComponentId);
  146. HRESULT
  147. HrFindComponents (
  148. INetCfg* pnc,
  149. ULONG cComponents,
  150. const GUID** apguidClass,
  151. const PCWSTR* apszwComponentId,
  152. INetCfgComponent** apncc);
  153. HRESULT
  154. HrGetBindingInterfaceComponents (
  155. INetCfgBindingInterface* pncbi,
  156. INetCfgComponent** ppnccUpper,
  157. INetCfgComponent** ppnccLower);
  158. HRESULT
  159. HrGetLastComponentAndInterface (
  160. INetCfgBindingPath* pncbp,
  161. INetCfgComponent** ppncc,
  162. PWSTR* ppszwInterfaceName);
  163. HRESULT
  164. HrInstallComponent (
  165. INetCfg* pnc,
  166. const NETWORK_INSTALL_PARAMS* pnip,
  167. const GUID* pguidClass,
  168. PCWSTR pszwComponentId,
  169. OBO_TOKEN* pOboToken,
  170. INetCfgComponent** ppncc);
  171. HRESULT
  172. HrInstallComponents (
  173. INetCfg* pnc,
  174. const NETWORK_INSTALL_PARAMS* pnip,
  175. ULONG cComponents,
  176. const GUID** apguidClass,
  177. const PCWSTR* apszwComponentId,
  178. OBO_TOKEN* pOboToken);
  179. HRESULT
  180. HrInstallComponentsOboComponent (
  181. INetCfg* pnc,
  182. const NETWORK_INSTALL_PARAMS* pnip,
  183. ULONG cComponents,
  184. const GUID** apguidClass,
  185. const PCWSTR* apszwComponentId,
  186. INetCfgComponent* pnccObo);
  187. HRESULT
  188. HrInstallComponentsOboUser (
  189. INetCfg* pnc,
  190. const NETWORK_INSTALL_PARAMS* pnip,
  191. ULONG cComponents,
  192. const GUID** apguidClass,
  193. const PCWSTR* apszwComponentId);
  194. HRESULT
  195. HrInstallComponentOboComponent (
  196. INetCfg* pnc,
  197. const NETWORK_INSTALL_PARAMS* pnip,
  198. const GUID& rguidClass,
  199. PCWSTR pszwComponentId,
  200. INetCfgComponent* pnccObo,
  201. INetCfgComponent** ppncc);
  202. HRESULT
  203. HrInstallComponentOboSoftware(
  204. INetCfg* pnc,
  205. const NETWORK_INSTALL_PARAMS* pnip,
  206. const GUID& rguidClass,
  207. PCWSTR pszwComponentId,
  208. PCWSTR pszwManufacturer,
  209. PCWSTR pszwProduct,
  210. PCWSTR pszwDisplayName,
  211. INetCfgComponent** ppncc);
  212. HRESULT
  213. HrInstallComponentOboUser (
  214. INetCfg* pnc,
  215. const NETWORK_INSTALL_PARAMS* pnip,
  216. const GUID& rguidClass,
  217. PCWSTR pszwComponentId,
  218. INetCfgComponent** ppncc);
  219. HRESULT
  220. HrInstallRasIfNeeded (
  221. INetCfg* pnc);
  222. HRESULT
  223. HrIsLanCapableAdapter (
  224. INetCfgComponent* pncc);
  225. HRESULT
  226. HrIsLanCapableProtocol (
  227. INetCfgComponent* pncc);
  228. HRESULT
  229. HrQueryNotifyObject (
  230. INetCfgComponent* pncc,
  231. REFIID riid,
  232. VOID** ppvObject);
  233. HRESULT
  234. HrRemoveComponent (
  235. INetCfg* pnc,
  236. INetCfgComponent* pnccToRemove,
  237. OBO_TOKEN* pOboToken,
  238. PWSTR * pmszwRefs);
  239. HRESULT
  240. HrRemoveComponentOboComponent (
  241. INetCfg* pnc,
  242. const GUID& rguidClass,
  243. PCWSTR pszwComponentId,
  244. INetCfgComponent* pnccObo);
  245. HRESULT
  246. HrRemoveComponentOboSoftware (
  247. INetCfg* pnc,
  248. const GUID& rguidClass,
  249. PCWSTR pszwComponentId,
  250. PCWSTR pszwManufacturer,
  251. PCWSTR pszwProduct,
  252. PCWSTR pszwDisplayName);
  253. HRESULT
  254. HrRemoveComponentOboUser (
  255. INetCfg* pnc,
  256. const GUID& rguidClass,
  257. PCWSTR pszwComponentId);
  258. HRESULT
  259. HrUninitializeAndReleaseINetCfg (
  260. BOOL fUninitCom,
  261. INetCfg* pnc,
  262. BOOL fHasLock = FALSE);
  263. HRESULT
  264. HrUninitializeAndUnlockINetCfg (
  265. INetCfg* pnc);
  266. HRESULT
  267. HrRunWinsock2Migration();
  268. HRESULT
  269. HrNcRemoveComponent(INetCfg* pinc, const GUID& guidClass,
  270. PCWSTR pszInstanceGuid);
  271. EXTERN_C
  272. HRESULT
  273. WINAPI
  274. HrDiAddComponentToINetCfg(
  275. IN INetCfg* pINetCfg,
  276. IN INetCfgInternalSetup* pInternalSetup,
  277. IN const NIQ_INFO* pInfo);
  278. EXTERN_C
  279. VOID
  280. WINAPI
  281. UpdateLanaConfigUsingAnswerfile (
  282. IN PCWSTR pszAnswerFile,
  283. IN PCWSTR pszSection);
  284. HRESULT
  285. HrNcRegCreateComponentNetworkKeyForDevice(const GUID& guidClass, HKEY* phkey,
  286. PCWSTR pszInstanceGuid,
  287. PCWSTR pszPnpId);
  288. HRESULT
  289. HrNcRegCreateComponentNetworkKey(const GUID& guidClass, PHKEY phkeyComponent,
  290. PCWSTR pszInstanceGuid);
  291. HRESULT
  292. HrNcNotifyINetCfgAndConnectionWizardOfInstallation(
  293. IN HDEVINFO hdi,
  294. IN PSP_DEVINFO_DATA pdeid,
  295. IN PCWSTR pszPnpId,
  296. IN const GUID& InstanceGuid,
  297. IN NC_INSTALL_TYPE eType);
  298. HRESULT
  299. HrNcNotifyINetCfgAndConnectionWizardOfInstallation(HDEVINFO hdi,
  300. PSP_DEVINFO_DATA pdeid, PCWSTR pszwPnpId, PCWSTR pszInstanceGuid,
  301. NC_INSTALL_TYPE eType);
  302. HRESULT
  303. HrNcNotifyINetCfgOfRemoval(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid,
  304. PCWSTR pszwInstanceGuid);
  305. struct COMPONENT_INFO
  306. {
  307. PCWSTR pszComponentId;
  308. const GUID * pguidClass;
  309. PCWSTR pszInfFile;
  310. };
  311. extern const COMPONENT_INFO*
  312. PComponentInfoFromComponentId (
  313. PCWSTR pszComponentId);
  314. //------------------------------------------------------------------------
  315. // CIterNetCfgBindingPath - iterator for IEnumNetCfgBindingPath
  316. //
  317. // This class is is a simple wrapper around CIEnumIter with a call
  318. // to INetCfgComponent::EnumBindingPaths to get the enumerator.
  319. //
  320. class CIterNetCfgBindingPath : public CIEnumIter<IEnumNetCfgBindingPath, INetCfgBindingPath*>
  321. {
  322. public:
  323. NOTHROW CIterNetCfgBindingPath (INetCfgComponent* pncc);
  324. NOTHROW ~CIterNetCfgBindingPath () { ReleaseObj(m_pebp); }
  325. protected:
  326. IEnumNetCfgBindingPath* m_pebp;
  327. };
  328. //------------------------------------------------------------------------
  329. // CIterNetCfgUpperBindingPath - iterator for IEnumNetCfgBindingPath
  330. //
  331. // This class is is a simple wrapper around CIEnumIter with a call
  332. // to INetCfgComponent::EnumUpperBindingPaths to get the enumerator.
  333. //
  334. class CIterNetCfgUpperBindingPath : public CIEnumIter<IEnumNetCfgBindingPath, INetCfgBindingPath*>
  335. {
  336. public:
  337. NOTHROW CIterNetCfgUpperBindingPath (INetCfgComponent* pncc);
  338. NOTHROW ~CIterNetCfgUpperBindingPath () { ReleaseObj(m_pebp); }
  339. protected:
  340. IEnumNetCfgBindingPath* m_pebp;
  341. };
  342. //------------------------------------------------------------------------
  343. // CIterNetCfgBindingInterface - iterator for IEnumNetCfgBindingInterface
  344. //
  345. // This class is is a simple wrapper around CIEnumIter with a call
  346. // to INetCfgBindingPath::EnumBindingInterfaces to get the enumerator.
  347. //
  348. class CIterNetCfgBindingInterface : public CIEnumIter<IEnumNetCfgBindingInterface, INetCfgBindingInterface*>
  349. {
  350. public:
  351. NOTHROW CIterNetCfgBindingInterface (INetCfgBindingPath* pncbp);
  352. NOTHROW ~CIterNetCfgBindingInterface () { ReleaseObj(m_pebi); }
  353. protected:
  354. IEnumNetCfgBindingInterface* m_pebi;
  355. };
  356. //------------------------------------------------------------------------
  357. // CIterNetCfgComponent - iterator for IEnumNetCfgComponent
  358. //
  359. // This class is is a simple wrapper around CIEnumIter with a call
  360. // to INetCfgClass::EnumComponents to get the enumerator.
  361. //
  362. class CIterNetCfgComponent : public CIEnumIter<IEnumNetCfgComponent, INetCfgComponent*>
  363. {
  364. public:
  365. NOTHROW CIterNetCfgComponent (INetCfg* pnc, const GUID* pguid);
  366. NOTHROW CIterNetCfgComponent (INetCfgClass* pncclass);
  367. NOTHROW ~CIterNetCfgComponent () { ReleaseObj(m_pec); }
  368. protected:
  369. IEnumNetCfgComponent* m_pec;
  370. };
  371. inline NOTHROW CIterNetCfgBindingPath::CIterNetCfgBindingPath(INetCfgComponent* pncc)
  372. : CIEnumIter<IEnumNetCfgBindingPath, INetCfgBindingPath*> (NULL)
  373. {
  374. AssertH(pncc);
  375. INetCfgComponentBindings* pnccb;
  376. // If EnumBindingPaths() fails, make sure ReleaseObj() won't die.
  377. m_pebp = NULL;
  378. m_hrLast = pncc->QueryInterface( IID_INetCfgComponentBindings, reinterpret_cast<LPVOID *>(&pnccb) );
  379. if (SUCCEEDED(m_hrLast))
  380. {
  381. // Get the enumerator and set it for the base class.
  382. // Important to set m_hrLast so that if this fails, we'll also
  383. // fail any subsequent calls to HrNext.
  384. m_hrLast = pnccb->EnumBindingPaths(EBP_BELOW, &m_pebp);
  385. if (SUCCEEDED(m_hrLast))
  386. {
  387. SetEnumerator(m_pebp);
  388. }
  389. ReleaseObj( pnccb );
  390. }
  391. TraceHr (ttidError, FAL, m_hrLast, FALSE,
  392. "CIterNetCfgBindingPath::CIterNetCfgBindingPath");
  393. }
  394. inline NOTHROW CIterNetCfgUpperBindingPath::CIterNetCfgUpperBindingPath(INetCfgComponent* pncc)
  395. : CIEnumIter<IEnumNetCfgBindingPath, INetCfgBindingPath*> (NULL)
  396. {
  397. AssertH(pncc);
  398. INetCfgComponentBindings* pnccb;
  399. // If EnumBindingPaths() fails, make sure ReleaseObj() won't die.
  400. m_pebp = NULL;
  401. m_hrLast = pncc->QueryInterface( IID_INetCfgComponentBindings, reinterpret_cast<LPVOID *>(&pnccb) );
  402. if (SUCCEEDED(m_hrLast))
  403. {
  404. // Get the enumerator and set it for the base class.
  405. // Important to set m_hrLast so that if this fails, we'll also
  406. // fail any subsequent calls to HrNext.
  407. m_hrLast = pnccb->EnumBindingPaths(EBP_ABOVE, &m_pebp);
  408. if (SUCCEEDED(m_hrLast))
  409. {
  410. SetEnumerator(m_pebp);
  411. }
  412. ReleaseObj( pnccb );
  413. }
  414. TraceHr (ttidError, FAL, m_hrLast, FALSE,
  415. "CIterNetCfgUpperBindingPath::CIterNetCfgUpperBindingPath");
  416. }
  417. inline NOTHROW CIterNetCfgBindingInterface::CIterNetCfgBindingInterface(INetCfgBindingPath* pncbp)
  418. : CIEnumIter<IEnumNetCfgBindingInterface, INetCfgBindingInterface*> (NULL)
  419. {
  420. AssertH(pncbp);
  421. // If EnumBindingInterfaces() fails, make sure ReleaseObj() won't die.
  422. m_pebi = NULL;
  423. // Get the enumerator and set it for the base class.
  424. // Important to set m_hrLast so that if this fails, we'll also
  425. // fail any subsequent calls to HrNext.
  426. m_hrLast = pncbp->EnumBindingInterfaces(&m_pebi);
  427. if (SUCCEEDED(m_hrLast))
  428. {
  429. SetEnumerator(m_pebi);
  430. }
  431. TraceHr (ttidError, FAL, m_hrLast, FALSE,
  432. "CIterNetCfgBindingInterface::CIterNetCfgBindingInterface");
  433. }
  434. inline NOTHROW CIterNetCfgComponent::CIterNetCfgComponent(INetCfg* pnc, const GUID* pguid)
  435. : CIEnumIter<IEnumNetCfgComponent, INetCfgComponent*> (NULL)
  436. {
  437. AssertH(pnc);
  438. // If EnumComponents() fails, make sure ReleaseObj() won't die.
  439. m_pec = NULL;
  440. INetCfgClass* pncclass;
  441. m_hrLast = pnc->QueryNetCfgClass(pguid, IID_INetCfgClass,
  442. reinterpret_cast<void**>(&pncclass));
  443. if (SUCCEEDED(m_hrLast))
  444. {
  445. // Get the enumerator and set it for the base class.
  446. // Important to set m_hrLast so that if this fails, we'll also
  447. // fail any subsequent calls to HrNext.
  448. m_hrLast = pncclass->EnumComponents(&m_pec);
  449. if (SUCCEEDED(m_hrLast))
  450. {
  451. SetEnumerator(m_pec);
  452. }
  453. ReleaseObj(pncclass);
  454. }
  455. TraceHr (ttidError, FAL, m_hrLast, FALSE,
  456. "CIterNetCfgComponent::CIterNetCfgComponent");
  457. }
  458. inline NOTHROW CIterNetCfgComponent::CIterNetCfgComponent(INetCfgClass* pncclass)
  459. : CIEnumIter<IEnumNetCfgComponent, INetCfgComponent*> (NULL)
  460. {
  461. AssertH(pncclass);
  462. // If EnumComponents() fails, make sure ReleaseObj() won't die.
  463. m_pec = NULL;
  464. // Get the enumerator and set it for the base class.
  465. // Important to set m_hrLast so that if this fails, we'll also
  466. // fail any subsequent calls to HrNext.
  467. m_hrLast = pncclass->EnumComponents(&m_pec);
  468. if (SUCCEEDED(m_hrLast))
  469. {
  470. SetEnumerator(m_pec);
  471. }
  472. TraceHr (ttidError, FAL, m_hrLast, FALSE,
  473. "CIterNetCfgComponent::CIterNetCfgComponent");
  474. }
  475. #endif // _NCNETCFG_H_