Leaked source code of windows server 2003
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.

200 lines
3.3 KiB

  1. /*
  2. * factory.cxx
  3. */
  4. #include "server.hxx"
  5. #include "factory.hxx"
  6. #include "classes.hxx"
  7. //
  8. // MyFactory methods.
  9. //
  10. MyFactory::MyFactory()
  11. {
  12. Refs = 0;
  13. }
  14. MyFactory::~MyFactory()
  15. {
  16. }
  17. HRESULT STDMETHODCALLTYPE
  18. MyFactory::QueryInterface (
  19. REFIID iid,
  20. void ** ppv )
  21. {
  22. HRESULT hr = E_NOINTERFACE;
  23. *ppv = 0;
  24. if ((memcmp(&iid, &IID_IUnknown, sizeof(IID)) == 0) ||
  25. (memcmp(&iid, &IID_IClassFactory, sizeof(IID)) == 0))
  26. {
  27. *ppv = this;
  28. AddRef();
  29. hr = S_OK;
  30. }
  31. return hr;
  32. }
  33. ULONG STDMETHODCALLTYPE
  34. MyFactory::AddRef()
  35. {
  36. Refs++;
  37. return Refs;
  38. }
  39. ULONG STDMETHODCALLTYPE
  40. MyFactory::Release()
  41. {
  42. unsigned long Count;
  43. Count = --Refs;
  44. if ( Count == 0 )
  45. {
  46. delete this;
  47. }
  48. return Count;
  49. }
  50. HRESULT STDMETHODCALLTYPE
  51. MyFactory::CreateInstance(
  52. IUnknown * punkOuter,
  53. REFIID riid,
  54. void ** ppv )
  55. {
  56. // Should never be called.
  57. *ppv = 0;
  58. return E_FAIL;
  59. }
  60. HRESULT STDMETHODCALLTYPE
  61. MyFactory::LockServer(
  62. BOOL fLock )
  63. {
  64. return S_OK;
  65. }
  66. //
  67. // FactoryLocal methods.
  68. //
  69. HRESULT STDMETHODCALLTYPE
  70. FactoryLocal::CreateInstance(
  71. IUnknown * punkOuter,
  72. REFIID riid,
  73. void ** ppv )
  74. {
  75. HRESULT hr = E_OUTOFMEMORY;
  76. MyObject * pObject;
  77. *ppv = 0;
  78. pObject = new MyObject( LOCAL );
  79. if ( ! pObject )
  80. return hr;
  81. //
  82. // Increment the object count.
  83. // The object count will keep this process alive until all objects are released.
  84. //
  85. ObjectCount++;
  86. hr = pObject->QueryInterface(riid, ppv);
  87. return hr;
  88. }
  89. //
  90. // FactoryRemote methods.
  91. //
  92. HRESULT STDMETHODCALLTYPE
  93. FactoryRemote::CreateInstance(
  94. IUnknown * punkOuter,
  95. REFIID riid,
  96. void ** ppv )
  97. {
  98. HRESULT hr = E_OUTOFMEMORY;
  99. MyObject * pObject;
  100. *ppv = 0;
  101. pObject = new MyObject( REMOTE );
  102. if ( ! pObject )
  103. return hr;
  104. //
  105. // Increment the object count.
  106. // The object count will keep this process alive until all objects are released.
  107. //
  108. ObjectCount++;
  109. hr = pObject->QueryInterface(riid, ppv);
  110. return hr;
  111. }
  112. //
  113. // FactoryRemote methods.
  114. //
  115. HRESULT STDMETHODCALLTYPE
  116. FactoryAtStorage::CreateInstance(
  117. IUnknown * punkOuter,
  118. REFIID riid,
  119. void ** ppv )
  120. {
  121. HRESULT hr = E_OUTOFMEMORY;
  122. MyObject * pObject;
  123. *ppv = 0;
  124. pObject = new MyObject( ATBITS );
  125. if ( ! pObject )
  126. return hr;
  127. //
  128. // Increment the object count.
  129. // The object count will keep this process alive until all objects are released.
  130. //
  131. ObjectCount++;
  132. hr = pObject->QueryInterface(riid, ppv);
  133. return hr;
  134. }
  135. //
  136. // FactoryInproc methods.
  137. //
  138. HRESULT STDMETHODCALLTYPE
  139. FactoryInproc::CreateInstance(
  140. IUnknown * punkOuter,
  141. REFIID riid,
  142. void ** ppv )
  143. {
  144. HRESULT hr = E_OUTOFMEMORY;
  145. MyObject * pObject;
  146. *ppv = 0;
  147. pObject = new MyObject( INPROC );
  148. if ( ! pObject )
  149. return hr;
  150. //
  151. // Increment the object count.
  152. // The object count will keep this process alive until all objects are released.
  153. //
  154. ObjectCount++;
  155. hr = pObject->QueryInterface(riid, ppv);
  156. return hr;
  157. }
  158.