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.

99 lines
1.3 KiB

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