I'm developing a text editor class (for a chat application) based on CRichEditCtrl (MFC) with emoticon support.
After I load the emoticon's bitmap, I use the function OleCreateStaticFromData to insert it into CRichEditCtrl. After that I just delete the bitmap object allocated by myself. I can verify (using a GDIView utility) that all resources I allocate have been properly released.
This works perfectly: the bitmap (emoticon) is drawn on the CRichEditCtrl window and is handled just like a character.
My problem is that I don't know how to deallocate the memory (internal) allocated by OleCreateStaticFromData to manage the bitmap (emoticon). The memory allocated for any emoticon used is never released, even if I delete the CRichEditCtrl object. I'd like to know how to fix that issue. Is that a MFC's issue or I'm doing something wrong ?
OleCreateStaticFromData returns a COM pointer which you pass to the Rich Edit control. This COM pointer has had an AddRef applied to it, so you must call Release once you have passed it to the control, to signify that you no longer will be accessing it directly. The control will also do a Release when it is destroyed which should result in the COM object being deleted.
You might also store the returned pointer in a smart pointer class _com_ptr_t or CComPtr and it will Release it automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With