CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1

    Exclamation CRichEditCtrl OLE object Cleanup

    I have a rich edit control which I am streaming RTF data in and out of quite frequently.
    this RTF data contains Bitmap Objects.
    The Rich Edit control never seems to release any memory, it just keeps growing and growing and growing.
    This looks like a bad Memory Leak Problem!
    Even if I manually delete all the objects from the RichEdit control, Task Manager still shows that the memory has not been released!
    When I debug my application, the debugger does not detect any memory leaks at all!

    Why is Task Manager showing the memory as not being released?
    Is Task Manager Correct?
    Why does the debugger not catch these memory leaks?

    Please help!
    This is the OLE Object Cleanup method I am using...

    void CMsgRichEdit::FreeObjMemory()
            HRESULT hr = 0;
            // Start by getting the total number of objects in the control.
            int objectCount = m_pRichEditOle->GetObjectCount();
            // Loop through each object in the control and if active
            // deactivate, and if open, close.
            for (int i = 0; i < objectCount; i++)
    			REOBJECT reObj;
    				ZeroMemory(&reObj, sizeof(REOBJECT));
    			reObj.cbStruct  = sizeof(REOBJECT);
    			// Get the Nth object
    			hr = m_pRichEditOle->GetObject(i,&reObj,REO_GETOBJ_POLEOBJ);
    				// If active, deactivate.
    				if (reObj.dwFlags && REO_INPLACEACTIVE)
    				// If the object is open, close it.
    					hr = reObj.poleobj->Close(OLECLOSE_NOSAVE);

  2. #2

    Exclamation Re: CRichEditCtrl OLE object Cleanup

    Are there any experts out there that have the answer to this???
    Please help...

  3. #3
    Join Date
    Apr 2014

    Re: CRichEditCtrl OLE object Cleanup

    After struggling with the issue for almost a week I found the Problem and a solution. It is in the Riched20.dll that provides the Rich Edit. It really never Releases the Memory.

    Solution - use msftedit.dll instead.

    Steer clear of AfxInitRichEdit and use Windows API LoadLibrary to load it.

    Note: I am not using MFC for my Project. I initialize my Rich Edit directly through the Windows API with CreateWindowEx and control it with SendMessage.

    In my case I had to pass MSFTEDIT_CLASS instead of RICHEDIT_CLASSW to CreateWindowEx.

    Worst case Scenario for users of CRichEditCtrl - you have to reimplement it using Windows API as I do not know whether it is possible to create a CRichEditCtrl like you normally would but make it use MSFTEDIT_CLASS instead of RICHEDIT_CLASSW.

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)