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.

186 lines
4.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997
  5. //
  6. // File: wbclassf.cxx
  7. //
  8. // Contents: Word Breaker class factory
  9. //
  10. // History: weibz, 10-Nov-1997 created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #include "wbclassf.hxx"
  15. #include "iwbreak.hxx"
  16. extern long gulcInstances;
  17. //+-------------------------------------------------------------------------
  18. //
  19. // Method: CWordBreakerCF::CWordBreakerCF
  20. //
  21. // Synopsis: Word Breaker class factory constructor
  22. //
  23. //--------------------------------------------------------------------------
  24. CWordBreakerCF::CWordBreakerCF( LCID lcid )
  25. : _cRefs( 1 ), _lcid( lcid )
  26. {
  27. InterlockedIncrement( &gulcInstances );
  28. }
  29. //+-------------------------------------------------------------------------
  30. //
  31. // Method: CWordBreakerCF::~CWordBreakerCF
  32. //
  33. // Synopsis: Word Breaker class factory destructor
  34. //
  35. //--------------------------------------------------------------------------
  36. CWordBreakerCF::~CWordBreakerCF()
  37. {
  38. InterlockedDecrement( &gulcInstances );
  39. }
  40. //+-------------------------------------------------------------------------
  41. //
  42. // Method: CWordBreakerCF::QueryInterface
  43. //
  44. // Synopsis: Rebind to other interface
  45. //
  46. // Arguments: [riid] -- IID of new interface
  47. // [ppvObject] -- New interface * returned here
  48. //
  49. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  50. //
  51. //--------------------------------------------------------------------------
  52. SCODE STDMETHODCALLTYPE CWordBreakerCF::QueryInterface( REFIID riid,
  53. void ** ppvObject )
  54. {
  55. if ( 0 == ppvObject )
  56. return E_INVALIDARG;
  57. *ppvObject = 0;
  58. if ( IID_IClassFactory == riid )
  59. *ppvObject = (IUnknown *)(IClassFactory *)this;
  60. else if ( IID_IUnknown == riid )
  61. *ppvObject = (IUnknown *)this;
  62. else
  63. return E_NOINTERFACE;
  64. AddRef();
  65. return S_OK;
  66. }
  67. //+-------------------------------------------------------------------------
  68. //
  69. // Method: CWordBreakerCF::AddRef
  70. //
  71. // Synopsis: Increments refcount
  72. //
  73. //--------------------------------------------------------------------------
  74. ULONG STDMETHODCALLTYPE CWordBreakerCF::AddRef()
  75. {
  76. return InterlockedIncrement( &_cRefs );
  77. }
  78. //+-------------------------------------------------------------------------
  79. //
  80. // Method: CWordBreakerCF::Release
  81. //
  82. // Synopsis: Decrement refcount. Delete if necessary.
  83. //
  84. //--------------------------------------------------------------------------
  85. ULONG STDMETHODCALLTYPE CWordBreakerCF::Release()
  86. {
  87. unsigned long uTmp = InterlockedDecrement( &_cRefs );
  88. if ( 0 == uTmp )
  89. delete this;
  90. return(uTmp);
  91. }
  92. //+-------------------------------------------------------------------------
  93. //
  94. // Method: CWordBreakerCF::CreateInstance
  95. //
  96. // Synopsis: Creates new CWordBreaker object
  97. //
  98. // Arguments: [pUnkOuter] -- 'Outer' IUnknown
  99. // [riid] -- Interface to bind
  100. // [ppvObject] -- Interface returned here
  101. //
  102. //--------------------------------------------------------------------------
  103. SCODE STDMETHODCALLTYPE
  104. CWordBreakerCF::CreateInstance(
  105. IUnknown * pUnkOuter,
  106. REFIID riid,
  107. void * * ppvObject )
  108. {
  109. CWordBreaker *pIUnk = 0;
  110. SCODE sc = S_OK;
  111. if (NULL != pUnkOuter && !IsEqualIID(riid, IID_IUnknown)) {
  112. return E_NOINTERFACE;
  113. }
  114. __try
  115. {
  116. pIUnk = new CWordBreaker( _lcid );
  117. if (pIUnk)
  118. {
  119. sc = pIUnk->QueryInterface( riid , ppvObject );
  120. pIUnk->Release(); // Release extra refcount from QueryInterface
  121. }
  122. else
  123. {
  124. sc = E_UNEXPECTED;
  125. }
  126. }
  127. __except(1)
  128. {
  129. Assert( 0 == pIUnk );
  130. sc = E_UNEXPECTED;
  131. }
  132. return (sc);
  133. }
  134. //+-------------------------------------------------------------------------
  135. //
  136. // Method: CWordBreakerCF::LockServer
  137. //
  138. // Synopsis: Force class factory to remain loaded
  139. //
  140. // Arguments: [fLock] -- TRUE if locking, FALSE if unlocking
  141. //
  142. // Returns: S_OK
  143. //
  144. //--------------------------------------------------------------------------
  145. SCODE STDMETHODCALLTYPE
  146. CWordBreakerCF::LockServer(
  147. BOOL fLock)
  148. {
  149. if(fLock)
  150. InterlockedIncrement( &gulcInstances );
  151. else
  152. InterlockedDecrement( &gulcInstances );
  153. return(S_OK);
  154. }