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.

111 lines
3.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: N C N E T C F G . C P P
  7. //
  8. // Contents: Common routines for dealing with INetCfg interfaces.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 24 Mar 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <stdafx.h>
  16. #pragma hdrstop
  17. #include "netcfgx.h"
  18. #include "assert.h"
  19. //nclude "netcfgn.h"
  20. //nclude "ncdebug.h"
  21. //nclude "ncbase.h"
  22. //nclude "ncmisc.h"
  23. #include "ncnetcfg.h"
  24. //nclude "ncreg.h"
  25. //nclude "ncvalid.h"
  26. //+---------------------------------------------------------------------------
  27. //
  28. // Function: HrFindComponents
  29. //
  30. // Purpose: Find multiple INetCfgComponents with one call. This makes
  31. // the error handling associated with multiple calls to
  32. // QueryNetCfgClass and Find much easier.
  33. //
  34. // Arguments:
  35. // pnc [in] pointer to INetCfg object
  36. // cComponents [in] count of class guid pointers, component id
  37. // pointers, and INetCfgComponent output pointers.
  38. // apguidClass [in] array of class guid pointers.
  39. // apszwComponentId [in] array of component id pointers.
  40. // apncc [out] array of returned INetCfgComponet pointers.
  41. //
  42. // Returns: S_OK or an error code.
  43. //
  44. // Author: shaunco 22 Mar 1997
  45. //
  46. // Notes: cComponents is the count of pointers in all three arrays.
  47. // S_OK will still be returned even if no components were
  48. // found! This is by design.
  49. //
  50. HRESULT
  51. HrFindComponents (
  52. INetCfg* pnc,
  53. ULONG cComponents,
  54. const GUID** apguidClass,
  55. const LPCWSTR* apszwComponentId,
  56. INetCfgComponent** apncc)
  57. {
  58. Assert (pnc);
  59. Assert (cComponents);
  60. Assert (apguidClass);
  61. Assert (apszwComponentId);
  62. Assert (apncc);
  63. // Initialize the output parameters.
  64. //
  65. ZeroMemory (apncc, cComponents * sizeof(*apncc));
  66. // Find all of the components requested.
  67. // Variable initialization is important here.
  68. HRESULT hr = S_OK;
  69. ULONG i;
  70. for (i = 0; (i < cComponents) && SUCCEEDED(hr); i++)
  71. {
  72. // Get the class object for this component.
  73. INetCfgClass* pncclass = NULL;
  74. hr = pnc->QueryNetCfgClass (apguidClass[i], IID_INetCfgClass,
  75. reinterpret_cast<void**>(&pncclass));
  76. if (SUCCEEDED(hr) && pncclass)
  77. {
  78. // Find the component.
  79. hr = pncclass->FindComponent (apszwComponentId[i], &apncc[i]);
  80. AssertSz (SUCCEEDED(hr), "pncclass->Find failed.");
  81. ReleaseObj (pncclass);
  82. pncclass = NULL;
  83. }
  84. }
  85. // On any error, release what we found and set the output to NULL.
  86. if (FAILED(hr))
  87. {
  88. for (i = 0; i < cComponents; i++)
  89. {
  90. ReleaseObj (apncc[i]);
  91. apncc[i] = NULL;
  92. }
  93. }
  94. // Otherwise, normalize the HRESULT. (i.e. don't return S_FALSE)
  95. else
  96. {
  97. hr = S_OK;
  98. }
  99. TraceResult ("HrFindComponents", hr);
  100. return hr;
  101. }