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.

87 lines
1.6 KiB

  1. //***************************************************************************
  2. //
  3. // CLASSFAC.CPP
  4. //
  5. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //***************************************************************************
  8. #include <precomp.h>
  9. #include "classfac.h"
  10. #include "methods.h"
  11. CMethodsFactory::CMethodsFactory()
  12. {
  13. m_cRef=0L;
  14. return;
  15. }
  16. CMethodsFactory::~CMethodsFactory(void)
  17. {
  18. return;
  19. }
  20. STDMETHODIMP CMethodsFactory::QueryInterface(REFIID riid
  21. , LPVOID * ppv)
  22. {
  23. *ppv = NULL;
  24. if(IID_IUnknown==riid || IID_IClassFactory==riid) *ppv = this;
  25. if(NULL != *ppv){
  26. AddRef();
  27. return NOERROR;
  28. }
  29. return E_NOINTERFACE;
  30. }
  31. STDMETHODIMP_(ULONG) CMethodsFactory::AddRef(void)
  32. {
  33. return ++m_cRef;
  34. }
  35. STDMETHODIMP_(ULONG) CMethodsFactory::Release(void)
  36. {
  37. ULONG nNewCount = InterlockedDecrement((long*)&m_cRef);
  38. if (0L == nNewCount) delete this;
  39. return nNewCount;
  40. }
  41. STDMETHODIMP CMethodsFactory::CreateInstance(LPUNKNOWN pUnkOuter
  42. , REFIID riid, LPVOID * ppvObj)
  43. {
  44. CMethods *pObj;
  45. HRESULT hr = S_OK;
  46. *ppvObj = NULL;
  47. hr = E_OUTOFMEMORY;
  48. // This object doesnt support aggregation.
  49. if(NULL != pUnkOuter) return CLASS_E_NOAGGREGATION;
  50. // Create the object.
  51. pObj = new CMethods();
  52. if(NULL == pObj) return E_OUTOFMEMORY;
  53. hr = pObj->QueryInterface(riid, ppvObj);
  54. //Kill the object if initial creation or Init failed.
  55. if(FAILED(hr)) delete pObj;
  56. return hr;
  57. }
  58. STDMETHODIMP CMethodsFactory::LockServer(BOOL fLock)
  59. {
  60. if(fLock) InterlockedIncrement(&g_cLock);
  61. else InterlockedDecrement(&g_cLock);
  62. return NOERROR;
  63. }