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.

164 lines
3.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998 - 2001
  5. //
  6. // File : utils.cpp
  7. //
  8. // Contents : Common utilities required by helper.
  9. //
  10. // Notes :
  11. //
  12. // Author : Raghu Gatta (rgatta) 11 May 2001
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. BOOL g_fInitCom = TRUE;
  18. HRESULT
  19. HrInitializeHomenetConfig(
  20. BOOL* pfInitCom,
  21. IHNetCfgMgr** pphnc
  22. )
  23. /*++
  24. Routine Description
  25. Cocreate and initialize the root IHNetCfgMgr object. This will
  26. optionally initialize COM for the caller too.
  27. Arguments
  28. pfInitCom [in,out] TRUE to call CoInitialize before creating.
  29. returns TRUE if COM was successfully
  30. initialized FALSE if not.
  31. If NULL, means don't initialize COM.
  32. pphnc [out] The returned IHNetCfgMgr object.
  33. Return Value
  34. S_OK or an error code.
  35. --*/
  36. {
  37. HRESULT hr;
  38. //
  39. // Initialize the output parameter.
  40. //
  41. *pphnc = NULL;
  42. //
  43. // Initialize COM if the caller requested.
  44. //
  45. hr = S_OK;
  46. if (pfInitCom && *pfInitCom)
  47. {
  48. hr = CoInitializeEx(
  49. NULL,
  50. COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED
  51. );
  52. if (RPC_E_CHANGED_MODE == hr)
  53. {
  54. //
  55. // we have already been initialized in a different model
  56. //
  57. hr = S_OK;
  58. *pfInitCom = FALSE;
  59. }
  60. }
  61. if (SUCCEEDED(hr))
  62. {
  63. //
  64. // Create Homenet Configuration Manager COM Instance
  65. //
  66. hr = CoCreateInstance(
  67. CLSID_HNetCfgMgr,
  68. NULL,
  69. CLSCTX_INPROC_SERVER,
  70. IID_PPV_ARG(IHNetCfgMgr, pphnc)
  71. );
  72. if (SUCCEEDED(hr))
  73. {
  74. //
  75. // great! dont need to anything more here...
  76. //
  77. }
  78. //
  79. // If we failed anything above, and we've initialized COM,
  80. // be sure an uninitialize it.
  81. //
  82. if (FAILED(hr) && pfInitCom && *pfInitCom)
  83. {
  84. CoUninitialize();
  85. }
  86. }
  87. return hr;
  88. }
  89. //+---------------------------------------------------------------------------
  90. //
  91. // Function: HrUninitializeHomenetConfig
  92. //
  93. // Purpose: Unintialize and release an IHNetCfgMgr object. This will
  94. // optionally uninitialize COM for the caller too.
  95. //
  96. // Arguments:
  97. // fUninitCom [in] TRUE to uninitialize COM after the IHNetCfgMgr is
  98. // uninitialized and released.
  99. // phnc [in] The IHNetCfgMgr object.
  100. //
  101. // Returns: S_OK or an error code.
  102. //
  103. // Author: rgatta 11 May 2001
  104. //
  105. //----------------------------------------------------------------------------
  106. HRESULT
  107. HrUninitializeHomenetConfig(
  108. BOOL fUninitCom,
  109. IHNetCfgMgr* phnc
  110. )
  111. /*++
  112. Routine Description
  113. Arguments
  114. Return Value
  115. --*/
  116. {
  117. assert(phnc);
  118. HRESULT hr = S_OK;
  119. if (phnc)
  120. {
  121. phnc->Release();
  122. }
  123. phnc = NULL;
  124. if (fUninitCom)
  125. {
  126. CoUninitialize ();
  127. }
  128. return hr;
  129. }