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.

202 lines
4.1 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: MODULE.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 4/11/2000
  12. *
  13. * DESCRIPTION:
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include <initguid.h>
  19. #include <itranspl.h>
  20. #include <uicommon.h>
  21. #include "postplug.h"
  22. // DLL reference counters
  23. static LONG g_nServerLocks = 0;
  24. static LONG g_nComponents = 0;
  25. // DLL instance
  26. HINSTANCE g_hInstance;
  27. //
  28. // {81ED8E37-5938-46BF-B504-3539FB345419}
  29. //
  30. DEFINE_GUID(CLSID_HttpPostPlugin,0x81ED8E37,0x5938,0x46BF,0xB5,0x04,0x35,0x39,0xFB,0x34,0x54,0x19);
  31. void DllAddRef()
  32. {
  33. InterlockedIncrement(&g_nComponents);
  34. }
  35. void DllRelease()
  36. {
  37. InterlockedDecrement(&g_nComponents);
  38. }
  39. class CHttpPostPluginClassFactory : public IClassFactory
  40. {
  41. private:
  42. LONG m_cRef;
  43. public:
  44. // IUnknown
  45. STDMETHODIMP QueryInterface( const IID &iid, void **ppv);
  46. STDMETHODIMP_(ULONG) AddRef(void);
  47. STDMETHODIMP_(ULONG) Release(void);
  48. // IClassFactory
  49. STDMETHODIMP CreateInstance( IUnknown *pUnknownOuter, const IID &iid, void **ppvObject );
  50. STDMETHODIMP LockServer( BOOL bLock );
  51. CHttpPostPluginClassFactory()
  52. : m_cRef(1)
  53. {
  54. }
  55. ~CHttpPostPluginClassFactory(void)
  56. {
  57. }
  58. };
  59. STDMETHODIMP CHttpPostPluginClassFactory::QueryInterface( const IID &iid, void **ppvObject )
  60. {
  61. if ((iid==IID_IUnknown) || (iid==IID_IClassFactory))
  62. {
  63. *ppvObject = static_cast<LPVOID>(this);
  64. }
  65. else
  66. {
  67. *ppvObject = NULL;
  68. return(E_NOINTERFACE);
  69. }
  70. reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
  71. return(S_OK);
  72. }
  73. STDMETHODIMP_(ULONG) CHttpPostPluginClassFactory::AddRef(void)
  74. {
  75. return(InterlockedIncrement(&m_cRef));
  76. }
  77. STDMETHODIMP_(ULONG) CHttpPostPluginClassFactory::Release(void)
  78. {
  79. if (InterlockedDecrement(&m_cRef)==0)
  80. {
  81. delete this;
  82. return 0;
  83. }
  84. return(m_cRef);
  85. }
  86. STDMETHODIMP CHttpPostPluginClassFactory::CreateInstance( IUnknown *pUnknownOuter, const IID &iid, void **ppvObject )
  87. {
  88. // No aggregation supported
  89. if (pUnknownOuter)
  90. {
  91. return(CLASS_E_NOAGGREGATION);
  92. }
  93. CHttpPostPlugin *pHttpPostPlugin = new CHttpPostPlugin();
  94. if (!pHttpPostPlugin)
  95. {
  96. return(E_OUTOFMEMORY);
  97. }
  98. HRESULT hr = pHttpPostPlugin->QueryInterface( iid, ppvObject );
  99. pHttpPostPlugin->Release();
  100. return (hr);
  101. }
  102. STDMETHODIMP CHttpPostPluginClassFactory::LockServer(BOOL bLock)
  103. {
  104. if (bLock)
  105. {
  106. InterlockedIncrement(&g_nServerLocks);
  107. }
  108. else
  109. {
  110. InterlockedDecrement(&g_nServerLocks);
  111. }
  112. return(S_OK);
  113. }
  114. extern "C" BOOL WINAPI DllMain( HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved )
  115. {
  116. switch (dwReason)
  117. {
  118. case DLL_PROCESS_ATTACH:
  119. g_hInstance = hinst;
  120. DisableThreadLibraryCalls(hinst);
  121. break;
  122. }
  123. return(TRUE);
  124. }
  125. extern "C" STDMETHODIMP DllRegisterServer(void)
  126. {
  127. return WiaUiUtil::InstallInfFromResource( g_hInstance, "RegDllCommon" );
  128. }
  129. extern "C" STDMETHODIMP DllUnregisterServer(void)
  130. {
  131. return WiaUiUtil::InstallInfFromResource( g_hInstance, "UnregDllCommon" );
  132. }
  133. extern "C" STDMETHODIMP DllCanUnloadNow(void)
  134. {
  135. if (g_nServerLocks == 0 && g_nComponents == 0)
  136. {
  137. return S_OK;
  138. }
  139. else
  140. {
  141. return S_FALSE;
  142. }
  143. }
  144. extern "C" STDAPI DllGetClassObject( const CLSID &clsid, const IID &iid, void **ppvObject )
  145. {
  146. // Make sure we've got a valid ppvObject
  147. if (!ppvObject)
  148. {
  149. return(E_INVALIDARG);
  150. }
  151. // Make sure this component is supplied by this server
  152. if (clsid != CLSID_HttpPostPlugin)
  153. {
  154. return (CLASS_E_CLASSNOTAVAILABLE);
  155. }
  156. // Create class factory
  157. CHttpPostPluginClassFactory *pHttpPostPluginClassFactory = new CHttpPostPluginClassFactory;
  158. if (!pHttpPostPluginClassFactory)
  159. {
  160. return (E_OUTOFMEMORY);
  161. }
  162. HRESULT hr = pHttpPostPluginClassFactory->QueryInterface( iid, ppvObject );
  163. pHttpPostPluginClassFactory->Release();
  164. return (hr);
  165. }