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.

42 lines
1.3 KiB

  1. #ifndef COMMONIMAGELIST_H
  2. #define COMMONIMAGELIST_H
  3. class CImageListValidation
  4. {
  5. public:
  6. DWORD wMagic;
  7. CImageListValidation() : wMagic(IMAGELIST_SIG) { }
  8. // it is critical that we zero out wMagic in the destructor
  9. // Yes, the memory is theoretically being freed, but setting
  10. // it to zero ensures that CImageListBase::IsValid()
  11. // will never mistake a freed imagelist for a valid one
  12. ~CImageListValidation() {wMagic = 0; }
  13. };
  14. // CImageListBase must begin with CImageListValidation for compat reasons
  15. // We put the IUnknown immediately afterwards so all the people who derive
  16. // from it will agree on where to find QueryInterface et al.
  17. class CImageListBase : public IUnknown, public CImageListValidation
  18. {
  19. public:
  20. BOOL IsValid()
  21. {
  22. return this && !IsBadWritePtr(this, sizeof(*this)) && wMagic == IMAGELIST_SIG;
  23. }
  24. };
  25. #ifndef offsetofclass
  26. // (Magic stolen from atlbase.h because we don't use ATL2.1 any more)
  27. #define offsetofclass(base, derived) ((ULONG_PTR)(static_cast<base*>((derived*)8))-8)
  28. #endif
  29. // Since we know that IUnknown is implemented on CImageListBase, we find out where exactly
  30. // the validation layer is by this macro.
  31. #define FindImageListBase(punk) (CImageListBase*)(CImageListValidation*)((UINT_PTR)punk - offsetofclass(CImageListValidation, CImageListBase));
  32. #endif