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.

107 lines
1.7 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: iclassfact.cpp
  3. //
  4. // Desc: Implements the class factory for the UI.
  5. //
  6. // Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8. #include "common.hpp"
  9. //QI
  10. STDMETHODIMP CFactory::QueryInterface(REFIID riid, LPVOID* ppv)
  11. {
  12. //null the put parameter
  13. *ppv = NULL;
  14. if ((riid == IID_IUnknown) || (riid == IID_IClassFactory))
  15. {
  16. *ppv = this;
  17. AddRef();
  18. return S_OK;
  19. }
  20. return E_NOINTERFACE;
  21. }
  22. //AddRef
  23. STDMETHODIMP_(ULONG) CFactory::AddRef()
  24. {
  25. return InterlockedIncrement(&m_cRef);
  26. }
  27. //Release
  28. STDMETHODIMP_(ULONG) CFactory::Release()
  29. {
  30. if (InterlockedDecrement(&m_cRef) == 0)
  31. {
  32. delete this;
  33. return 0;
  34. }
  35. return m_cRef;
  36. }
  37. //CreateInstance
  38. STDMETHODIMP CFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid, LPVOID *ppv)
  39. {
  40. HRESULT hr = S_OK;
  41. //can't aggregate
  42. if (pUnkOuter != NULL)
  43. {
  44. return CLASS_E_NOAGGREGATION;
  45. }
  46. //create component
  47. CDirectInputActionFramework* pDIActionFramework = new CDirectInputActionFramework();
  48. if (pDIActionFramework == NULL)
  49. {
  50. return E_OUTOFMEMORY;
  51. }
  52. //get the requested interface
  53. hr = pDIActionFramework->QueryInterface(riid, ppv);
  54. //release IUnknown
  55. pDIActionFramework->Release();
  56. return hr;
  57. }
  58. //LockServer
  59. STDMETHODIMP CFactory::LockServer(BOOL bLock)
  60. {
  61. HRESULT hr = S_OK;
  62. if (bLock)
  63. {
  64. InterlockedIncrement(&g_cServerLocks);
  65. }
  66. else
  67. {
  68. InterlockedDecrement(&g_cServerLocks);
  69. }
  70. return hr;
  71. }
  72. //constructor
  73. CFactory::CFactory()
  74. {
  75. m_cRef = 1;
  76. }
  77. //destructor
  78. CFactory::~CFactory()
  79. {
  80. }