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.

173 lines
3.4 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997
  5. //
  6. // File: cclsacc.cxx
  7. //
  8. // Contents: Class factory and IUnknown methods for CClassAccess
  9. //
  10. // Author: DebiM
  11. //
  12. //-------------------------------------------------------------------------
  13. #include "cstore.hxx"
  14. HRESULT __stdcall CClassAccess::QueryInterface(REFIID riid, void * * ppvObject)
  15. {
  16. IUnknown *pUnkTemp = NULL;
  17. SCODE sc = S_OK;
  18. if( IsEqualIID( IID_IUnknown, riid ) )
  19. {
  20. pUnkTemp = (IUnknown *)(IClassAccess *)this;
  21. }
  22. else if( IsEqualIID( IID_IClassAccess, riid ) )
  23. {
  24. pUnkTemp = (IUnknown *)(IClassAccess *)this;
  25. }
  26. /*
  27. else if( IsEqualIID( IID_IClassRefresh, riid ) )
  28. {
  29. pUnkTemp = (IUnknown *)(IClassRefresh *)this;
  30. }
  31. */
  32. else
  33. {
  34. sc = (E_NOINTERFACE);
  35. }
  36. if((pUnkTemp != NULL) && (SUCCEEDED(sc)))
  37. {
  38. *ppvObject = (void * )pUnkTemp;
  39. pUnkTemp->AddRef();
  40. }
  41. return(sc);
  42. }
  43. ULONG __stdcall CClassAccess::AddRef()
  44. {
  45. InterlockedIncrement(( long * )&m_uRefs );
  46. return m_uRefs;
  47. }
  48. ULONG __stdcall CClassAccess::Release()
  49. {
  50. unsigned long uTmp = InterlockedDecrement((long *)&m_uRefs);
  51. unsigned long cRef = m_uRefs;
  52. // 0 is the only valid value to check
  53. if (uTmp == 0)
  54. {
  55. delete this;
  56. }
  57. return(cRef);
  58. }
  59. //
  60. // Constructor
  61. //
  62. unsigned long gulcClassFactory = 0;
  63. CClassAccessCF::CClassAccessCF()
  64. {
  65. m_uRefs = 1;
  66. InterlockedIncrement((long *) &gulcClassFactory );
  67. }
  68. //
  69. // Destructor
  70. //
  71. CClassAccessCF::~CClassAccessCF()
  72. {
  73. InterlockedDecrement((long *) &gulcClassFactory );
  74. }
  75. HRESULT __stdcall CClassAccessCF::QueryInterface(REFIID riid, void * * ppvObject)
  76. {
  77. IUnknown *pUnkTemp = NULL;
  78. SCODE sc = S_OK;
  79. if( IsEqualIID( IID_IUnknown, riid ) )
  80. {
  81. pUnkTemp = (IUnknown *)(ITypeLib *)this;
  82. }
  83. else if( IsEqualIID( IID_IClassFactory, riid ) )
  84. {
  85. pUnkTemp = (IUnknown *)(IClassFactory *)this;
  86. }
  87. else
  88. {
  89. sc = (E_NOINTERFACE);
  90. }
  91. if((pUnkTemp != NULL) && (SUCCEEDED(sc)))
  92. {
  93. *ppvObject = (void * )pUnkTemp;
  94. pUnkTemp->AddRef();
  95. }
  96. return(sc);
  97. }
  98. ULONG __stdcall CClassAccessCF::AddRef()
  99. {
  100. InterlockedIncrement(( long * )&m_uRefs );
  101. return m_uRefs;
  102. }
  103. ULONG __stdcall CClassAccessCF::Release()
  104. {
  105. unsigned long uTmp = InterlockedDecrement((long *)&m_uRefs);
  106. unsigned long cRef = m_uRefs;
  107. // 0 is the only valid value to check
  108. if (uTmp == 0)
  109. {
  110. delete this;
  111. }
  112. return(cRef);
  113. }
  114. //
  115. // IClassFactory Overide
  116. //
  117. HRESULT __stdcall CClassAccessCF::CreateInstance(IUnknown * pUnkOuter, REFIID riid, void * * ppvObject)
  118. {
  119. CClassAccess * pIUnk = NULL;
  120. SCODE sc = S_OK;
  121. if( pUnkOuter == NULL )
  122. {
  123. if( (pIUnk = new CClassAccess()) != NULL)
  124. {
  125. sc = pIUnk->QueryInterface( riid , ppvObject );
  126. if(FAILED(sc))
  127. {
  128. sc = E_UNEXPECTED;
  129. }
  130. pIUnk->Release();
  131. }
  132. else
  133. sc = E_OUTOFMEMORY;
  134. }
  135. else
  136. {
  137. return E_INVALIDARG;
  138. }
  139. return (sc);
  140. }
  141. HRESULT __stdcall CClassAccessCF::LockServer(BOOL fLock)
  142. {
  143. if(fLock)
  144. { InterlockedIncrement((long *) &gulcClassFactory ); }
  145. else
  146. { InterlockedDecrement((long *) &gulcClassFactory ); }
  147. return(S_OK);
  148. }