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.

211 lines
5.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: B I N D O B J . C P P
  7. //
  8. // Contents: Implementation of base class for RAS binding objects.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 11 Jun 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #pragma hdrstop
  17. #include "bindobj.h"
  18. #include "ncnetcfg.h"
  19. #include "assert.h"
  20. #include "ncutil.h"
  21. //nclude "ncreg.h"
  22. //nclude "ncsvc.h"
  23. extern const TCHAR c_szBiNdisCoWan[];
  24. extern const TCHAR c_szBiNdisWan[];
  25. extern const TCHAR c_szBiNdisWanAsync[];
  26. extern const TCHAR c_szBiNdisWanAtalk[];
  27. extern const TCHAR c_szBiNdisWanBh[];
  28. extern const TCHAR c_szBiNdisWanIp[];
  29. extern const TCHAR c_szBiNdisWanIpx[];
  30. extern const TCHAR c_szBiNdisWanNbf[];
  31. extern const TCHAR c_szInfId_MS_AppleTalk[];
  32. extern const TCHAR c_szInfId_MS_NWIPX[];
  33. extern const TCHAR c_szInfId_MS_NdisWanIpArp[];
  34. extern const TCHAR c_szInfId_MS_NdisWan[];
  35. extern const TCHAR c_szInfId_MS_NetBEUI[];
  36. extern const TCHAR c_szInfId_MS_NetMon[];
  37. extern const TCHAR c_szInfId_MS_RasCli[];
  38. extern const TCHAR c_szInfId_MS_RasRtr[];
  39. extern const TCHAR c_szInfId_MS_RasSrv[];
  40. extern const TCHAR c_szInfId_MS_TCPIP[];
  41. extern const TCHAR c_szInfId_MS_Wanarp[];
  42. extern const TCHAR c_szRegValWanEndpoints[] = TEXT("WanEndpoints");
  43. const GUID GUID_DEVCLASS_NETSERVICE ={0x4D36E974,0xE325,0x11CE,{0xbf,0xc1,0x08,0x00,0x2b,0xe1,0x03,0x18}};
  44. const GUID GUID_DEVCLASS_NETTRANS ={0x4D36E975,0xE325,0x11CE,{0xbf,0xc1,0x08,0x00,0x2b,0xe1,0x03,0x18}};
  45. //----------------------------------------------------------------------------
  46. // Data used for finding the other components we have to deal with.
  47. //
  48. const GUID* CRasBindObject::c_apguidComponentClasses [c_cOtherComponents] =
  49. {
  50. &GUID_DEVCLASS_NETSERVICE, // RasCli
  51. &GUID_DEVCLASS_NETSERVICE, // RasSrv
  52. &GUID_DEVCLASS_NETSERVICE, // RasRtr
  53. &GUID_DEVCLASS_NETTRANS, // Ip
  54. &GUID_DEVCLASS_NETTRANS, // Ipx
  55. &GUID_DEVCLASS_NETTRANS, // Nbf
  56. &GUID_DEVCLASS_NETTRANS, // Atalk
  57. &GUID_DEVCLASS_NETTRANS, // NetMon
  58. &GUID_DEVCLASS_NETTRANS, // NdisWan
  59. };
  60. const LPCTSTR CRasBindObject::c_apszComponentIds [c_cOtherComponents] =
  61. {
  62. c_szInfId_MS_RasCli,
  63. c_szInfId_MS_RasSrv,
  64. c_szInfId_MS_RasRtr,
  65. c_szInfId_MS_TCPIP,
  66. c_szInfId_MS_NWIPX,
  67. c_szInfId_MS_NetBEUI,
  68. c_szInfId_MS_AppleTalk,
  69. c_szInfId_MS_NetMon,
  70. c_szInfId_MS_NdisWan,
  71. };
  72. //+---------------------------------------------------------------------------
  73. //
  74. // Function: ReleaseAll
  75. //
  76. // Purpose: Releases an array of IUnknown pointers.
  77. //
  78. // Arguments:
  79. // cpunk [in] count of pointers to release
  80. // apunk [in] array of pointers to release
  81. //
  82. // Returns: Nothing
  83. //
  84. // Author: shaunco 23 Mar 1997
  85. //
  86. // Notes: Any of the pointers in the array can be NULL.
  87. //
  88. VOID
  89. ReleaseAll (
  90. ULONG cpunk,
  91. IUnknown** apunk) NOTHROW
  92. {
  93. Assert (cpunk);
  94. Assert (apunk);
  95. while (cpunk--)
  96. {
  97. ReleaseObj (*apunk);
  98. *apunk = NULL;
  99. apunk++;
  100. }
  101. }
  102. //+---------------------------------------------------------------------------
  103. //
  104. // Member: CRasBindObject::CRasBindObject
  105. //
  106. // Purpose: Constructor
  107. //
  108. // Arguments:
  109. // (none)
  110. //
  111. // Returns: Nothing.
  112. //
  113. // Author: shaunco 28 Jul 1997
  114. //
  115. // Notes:
  116. //
  117. CRasBindObject::CRasBindObject ()
  118. {
  119. m_ulOtherComponents = 0;
  120. m_pnc = NULL;
  121. }
  122. //+---------------------------------------------------------------------------
  123. //
  124. // Member: CRasBindObject::HrFindOtherComponents
  125. //
  126. // Purpose: Find the components listed in our OTHER_COMPONENTS enum.
  127. //
  128. // Arguments:
  129. // (none)
  130. //
  131. // Returns: S_OK or an error code.
  132. //
  133. // Author: shaunco 28 Jul 1997
  134. //
  135. // Notes: We ref-count this action. If called again (before
  136. // ReleaseOtherComponents) we increment a refcount.
  137. //
  138. //
  139. HRESULT
  140. CRasBindObject::HrFindOtherComponents ()
  141. {
  142. AssertSz (c_cOtherComponents == celems(c_apguidComponentClasses),
  143. "Uhh...you broke something.");
  144. AssertSz (c_cOtherComponents == celems(c_apszComponentIds),
  145. "Uhh...you broke something.");
  146. AssertSz (c_cOtherComponents == celems(m_apnccOther),
  147. "Uhh...you broke something.");
  148. HRESULT hr = S_OK;
  149. if (!m_ulOtherComponents)
  150. {
  151. hr = HrFindComponents (
  152. m_pnc, c_cOtherComponents,
  153. c_apguidComponentClasses,
  154. c_apszComponentIds,
  155. m_apnccOther);
  156. }
  157. if (SUCCEEDED(hr))
  158. {
  159. m_ulOtherComponents++;
  160. }
  161. TraceResult ("CRasBindObject::HrFindOtherComponents", hr);
  162. return hr;
  163. }
  164. //+---------------------------------------------------------------------------
  165. //
  166. // Member: CRasBindObject::ReleaseOtherComponents
  167. //
  168. // Purpose: Releases the components found by a previous call to
  169. // HrFindOtherComponents. (But only if the refcount is zero.)
  170. //
  171. // Arguments:
  172. // (none)
  173. //
  174. // Returns: Nothing.
  175. //
  176. // Author: shaunco 28 Jul 1997
  177. //
  178. // Notes:
  179. //
  180. void
  181. CRasBindObject::ReleaseOtherComponents () NOTHROW
  182. {
  183. AssertSz (m_ulOtherComponents,
  184. "You have not called HrFindOtherComponents yet or you have "
  185. "called ReleaseOtherComponents too many times.");
  186. if (0 == --m_ulOtherComponents)
  187. {
  188. ReleaseAll (c_cOtherComponents, (IUnknown**)m_apnccOther);
  189. }
  190. }