Re: COM object: Store DWORD value right before interface vtable
"Timo Kunze" <TKunze71216@gmx.de> wrote in message
news:Of$F9r5xJHA.1380@TK2MSFTNGP05.phx.gbl
I've created a custom implementation of the IImageList interface.
It's a COM object and derives from CComObjectRootEx, CComCoClass,
IImageList and an internal interface called IImageListPrivate. The
COM map: BEGIN_COM_MAP(CAggregateImageList)
COM_INTERFACE_ENTRY(IImageList)
COM_INTERFACE_ENTRY_IID(IID_IImageListPrivate, IImageListPrivate)
END_COM_MAP()
However, this custom IImageList object can not yet be used like a
regular image list, because comctl32.dll looks for a magic value
(0x4C4D4948). This magic value must be stored right before the
IImageList vtable. How can I achieve this?
Try this:
class MyImageList : public IImageList {
void* operator new(size_t size) {
DWORD* p = (DWORD*)malloc(size + sizeof(DWORD));
p[0] = 0x4C4D4948;
return p + 1;
}
void operator delete(void* p) {
free((DWORD*)p - 1);
}
};
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925