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.

199 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name :
  4. cofact.cxx
  5. Abstract:
  6. class factory
  7. Author:
  8. Johnson Apacible (JohnsonA) 02-April-1997
  9. --*/
  10. #include "precomp.hxx"
  11. #define INITGUID
  12. #undef DEFINE_GUID // Added for NT 5 migration
  13. #include "comlog.hxx"
  14. ULONG g_dwRefCount = 0;
  15. CINETLOGSrvFactory::CINETLOGSrvFactory(
  16. VOID
  17. )
  18. {
  19. m_dwRefCount=0;
  20. }
  21. CINETLOGSrvFactory::~CINETLOGSrvFactory(
  22. VOID
  23. )
  24. {
  25. }
  26. HRESULT
  27. CINETLOGSrvFactory::CreateInstance(
  28. IUnknown *pUnkOuter,
  29. REFIID riid,
  30. void ** ppObject
  31. )
  32. {
  33. HRESULT hresReturn = E_NOINTERFACE;
  34. if (pUnkOuter != NULL)
  35. {
  36. return CLASS_E_NOAGGREGATION;
  37. }
  38. if (m_ClsId == CLSID_InetLogPublic)
  39. {
  40. CInetLogPublic *pInetLogPublic = new CInetLogPublic();
  41. if( pInetLogPublic == NULL )
  42. {
  43. hresReturn = E_OUTOFMEMORY;
  44. }
  45. else
  46. {
  47. hresReturn = pInetLogPublic->QueryInterface(riid, ppObject);
  48. if( FAILED(hresReturn) )
  49. {
  50. DBGPRINTF( (DBG_CONTEXT,
  51. "[CINETLOGSrvFactory::CreateInstance] no I/F\n"));
  52. delete pInetLogPublic;
  53. }
  54. }
  55. }
  56. else if (m_ClsId == CLSID_InetLogInformation)
  57. {
  58. CInetLogInformation *pInetLogInfo = new CInetLogInformation();
  59. if( pInetLogInfo == NULL )
  60. {
  61. hresReturn = E_OUTOFMEMORY;
  62. }
  63. else
  64. {
  65. hresReturn = pInetLogInfo->QueryInterface(riid, ppObject);
  66. if( FAILED(hresReturn) )
  67. {
  68. DBGPRINTF( (DBG_CONTEXT,
  69. "[CINETLOGSrvFactory::CreateInstance] no I/F\n"));
  70. delete pInetLogInfo;
  71. }
  72. }
  73. }
  74. return hresReturn;
  75. }
  76. HRESULT
  77. CINETLOGSrvFactory::LockServer(
  78. IN BOOL fLock
  79. )
  80. {
  81. if (fLock) {
  82. InterlockedIncrement((long *)&g_dwRefCount);
  83. } else {
  84. InterlockedDecrement((long *)&g_dwRefCount);
  85. }
  86. return NO_ERROR;
  87. }
  88. HRESULT
  89. CINETLOGSrvFactory::QueryInterface(
  90. REFIID riid,
  91. void **ppObject
  92. )
  93. {
  94. if (riid==IID_IUnknown || riid == IID_IClassFactory) {
  95. *ppObject = (IClassFactory *) this;
  96. }
  97. else {
  98. return E_NOINTERFACE;
  99. }
  100. AddRef();
  101. return NO_ERROR;
  102. }
  103. ULONG
  104. CINETLOGSrvFactory::AddRef(
  105. )
  106. {
  107. DWORD dwRefCount;
  108. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  109. return dwRefCount;
  110. }
  111. ULONG
  112. CINETLOGSrvFactory::Release()
  113. {
  114. DWORD dwRefCount;
  115. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  116. if (dwRefCount == 0) {
  117. delete this;
  118. }
  119. return dwRefCount;
  120. }
  121. STDAPI
  122. DllGetClassObject(
  123. REFCLSID rclsid,
  124. REFIID riid,
  125. void** ppObject)
  126. {
  127. *ppObject = NULL;
  128. if ((rclsid != CLSID_InetLogInformation) &&
  129. (rclsid != CLSID_InetLogPublic)
  130. )
  131. {
  132. DBGPRINTF( (DBG_CONTEXT, "[CINETLOGSrvFactory::DllGetClassObject] bad class\n" ) );
  133. return CLASS_E_CLASSNOTAVAILABLE;
  134. }
  135. CINETLOGSrvFactory *pFactory = new CINETLOGSrvFactory;
  136. if( pFactory == NULL )
  137. {
  138. return E_OUTOFMEMORY;
  139. }
  140. pFactory->m_ClsId = rclsid;
  141. if (FAILED(pFactory->QueryInterface(riid, ppObject)))
  142. {
  143. delete pFactory;
  144. DBGPRINTF( (DBG_CONTEXT, "[CINETLOGSrvFactory::DllGetClassObject] no I/F\n" ) );
  145. return E_INVALIDARG;
  146. }
  147. return NO_ERROR;
  148. }
  149. HRESULT
  150. _stdcall
  151. DllCanUnloadNow(
  152. VOID
  153. )
  154. {
  155. if (g_dwRefCount != 0) {
  156. return S_FALSE;
  157. } else {
  158. return S_OK;
  159. }
  160. } // DllCanUnloadNow
  161.