IUnknownImp.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //--------------------------------------------------------------------------------------
  2. // File: IUnknownImp.h
  3. //
  4. // Direct3D 11 Effects Helper for COM interop
  5. //
  6. // Lifetime for most Effects objects is based on the the lifetime of the master
  7. // effect, so the reference count is not used.
  8. //
  9. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  10. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  11. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  12. // PARTICULAR PURPOSE.
  13. //
  14. // Copyright (c) Microsoft Corporation. All rights reserved.
  15. //
  16. // http://go.microsoft.com/fwlink/p/?LinkId=271568
  17. //--------------------------------------------------------------------------------------
  18. #pragma once
  19. #define IUNKNOWN_IMP(Class, Interface, BaseInterface) \
  20. \
  21. HRESULT STDMETHODCALLTYPE Class##::QueryInterface(REFIID iid, _COM_Outptr_ LPVOID *ppv) override \
  22. { \
  23. if( !ppv ) \
  24. return E_INVALIDARG; \
  25. \
  26. *ppv = nullptr; \
  27. if(IsEqualIID(iid, IID_IUnknown)) \
  28. { \
  29. *ppv = (IUnknown*)((Interface*)this); \
  30. } \
  31. else if(IsEqualIID(iid, IID_##Interface)) \
  32. { \
  33. *ppv = (Interface *)this; \
  34. } \
  35. else if(IsEqualIID(iid, IID_##BaseInterface)) \
  36. { \
  37. *ppv = (BaseInterface *)this; \
  38. } \
  39. else \
  40. { \
  41. return E_NOINTERFACE; \
  42. } \
  43. \
  44. return S_OK; \
  45. } \
  46. \
  47. ULONG STDMETHODCALLTYPE Class##::AddRef() override \
  48. { \
  49. return 1; \
  50. } \
  51. \
  52. ULONG STDMETHODCALLTYPE Class##::Release() override \
  53. { \
  54. return 0; \
  55. }