Re: [PATCH] riched20: Don't create too many IRichEditOle interfaces for a RichEdit. (try 2)
On Wed, Jun 25, 2014 at 06:56:00PM +0800, Jactry Zeng wrote:
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 2af2582..65e70fa 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -4468,6 +4468,13 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, case EM_GETOLEINTERFACE: { LPVOID *ppvObj = (LPVOID*) lParam; + if (editor->reOle) + { + *ppvObj = editor->reOle; + IRichEditOle_AddRef(*ppvObj); + return 1; + } + return CreateIRichEditOle(editor, ppvObj); } case EM_GETPASSWORDCHAR:
Better to assign editor->reOle here too. That will be one ref, then every returned iface should add another ref. So the first iface returned will have refcount of 2 and then your tests will pass. You release the final ref in the editor destructor.
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h index f139c29..3722c82 100644 --- a/dlls/riched20/editstr.h +++ b/dlls/riched20/editstr.h @@ -388,6 +388,7 @@ typedef struct tagME_TextEditor { HWND hWnd, hwndParent; ITextHost *texthost; + LPVOID reOle;
Needs correct type. Huw.
Hi Huw, 2014-06-25 19:18 GMT+08:00 Huw Davies <huw(a)codeweavers.com>:
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 2af2582..65e70fa 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -4468,6 +4468,13 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor,
UINT msg, WPARAM wParam,
case EM_GETOLEINTERFACE: { LPVOID *ppvObj = (LPVOID*) lParam; + if (editor->reOle) + { + *ppvObj = editor->reOle; + IRichEditOle_AddRef(*ppvObj); + return 1; + } + return CreateIRichEditOle(editor, ppvObj); } case EM_GETPASSWORDCHAR:
Better to assign editor->reOle here too. That will be one ref, then every returned iface should add another ref. So the first iface returned will have refcount of 2 and then your tests will pass.
You release the final ref in the editor destructor.
Is this the right way? : @@ -4468,7 +4468,20 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, case EM_GETOLEINTERFACE: { LPVOID *ppvObj = (LPVOID*) lParam; - return CreateIRichEditOle(editor, ppvObj); + if (editor->reOle) + { + *ppvObj = editor->reOle; + IRichEditOle_AddRef(*ppvObj); + return 1; + } + + if (CreateIRichEditOle(editor, ppvObj)) + { + editor->reOle = *ppvObj; + IRichEditOle_AddRef(*ppvObj); + return 1; + } + return 0; } ref will be one when created, and will increase every time returned iface. And in this way, IRichEditOle_fnRelease also should be modified: @@ -126,12 +126,13 @@ IRichEditOle_fnRelease(IRichEditOle *me) TRACE ("%p ref=%u\n", This, ref); - if (!ref) + if (ref == 1) { TRACE ("Destroying %p\n", This); This->txtSel->reOle = NULL; ITextSelection_Release(&This->txtSel->ITextSelection_iface); IOleClientSite_Release(&This->clientSite->IOleClientSite_iface); + This->editor->reOle = NULL; heap_free(This); } return ref;
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h index f139c29..3722c82 100644 --- a/dlls/riched20/editstr.h +++ b/dlls/riched20/editstr.h @@ -388,6 +388,7 @@ typedef struct tagME_TextEditor { HWND hWnd, hwndParent; ITextHost *texthost; + LPVOID reOle;
Needs correct type.
@@ -388,6 +388,7 @@ typedef struct tagME_TextEditor { HWND hWnd, hwndParent; ITextHost *texthost; + IRichEditOle *reOle; BOOL bEmulateVersion10; ME_TextBuffer *pBuffer; ME_Cursor *pCursors; Thanks again! -- Regards, Jactry Zeng
participants (2)
-
Huw Davies -
Jactry Zeng