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.

54 lines
855 B

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Helper classes for implementing IUnknown.
  4. //
  5. #include "stdinc.h"
  6. #include "unkhelp.h"
  7. #include "dll.h"
  8. ComRefCount::ComRefCount()
  9. : m_cRef(1)
  10. {
  11. LockModule(true);
  12. }
  13. STDMETHODIMP_(ULONG)
  14. ComRefCount::AddRef()
  15. {
  16. return InterlockedIncrement(&m_cRef);
  17. }
  18. STDMETHODIMP_(ULONG)
  19. ComRefCount::Release()
  20. {
  21. if (!InterlockedDecrement(&m_cRef))
  22. {
  23. delete this;
  24. LockModule(false);
  25. return 0;
  26. }
  27. return m_cRef;
  28. }
  29. STDMETHODIMP
  30. ComSingleInterface::QueryInterface(const IID &iid, void **ppv, const IID&iidExpected, void *pvInterface)
  31. {
  32. V_INAME(ComSingleInterface::QueryInterface);
  33. V_PTRPTR_WRITE(ppv);
  34. V_REFGUID(iid);
  35. if (iid == IID_IUnknown || iid == iidExpected)
  36. {
  37. *ppv = pvInterface;
  38. }
  39. else
  40. {
  41. *ppv = NULL;
  42. return E_NOINTERFACE;
  43. }
  44. this->AddRef();
  45. return S_OK;
  46. }