riched20: Don't create too many IRichEditOle interface for a RichEdit.

This commit is contained in:
Jactry Zeng 2014-07-01 00:08:28 +08:00 committed by Alexandre Julliard
parent 87f214c7ff
commit 6ea4da4038
3 changed files with 30 additions and 3 deletions

View File

@ -2886,6 +2886,11 @@ static void ME_DestroyEditor(ME_TextEditor *editor)
if(editor->lpOleCallback)
IRichEditOleCallback_Release(editor->lpOleCallback);
ITextHost_Release(editor->texthost);
if (editor->reOle)
{
IRichEditOle_Release(editor->reOle);
editor->reOle = NULL;
}
OleUninitialize();
FREE_OBJ(editor->pBuffer);
@ -4467,8 +4472,12 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
}
case EM_GETOLEINTERFACE:
{
LPVOID *ppvObj = (LPVOID*) lParam;
return CreateIRichEditOle(editor, ppvObj);
if (!editor->reOle)
if (!CreateIRichEditOle(editor, (LPVOID *)&editor->reOle))
return 0;
*(LPVOID *)lParam = editor->reOle;
IRichEditOle_AddRef(editor->reOle);
return 1;
}
case EM_GETPASSWORDCHAR:
{

View File

@ -388,6 +388,7 @@ typedef struct tagME_TextEditor
{
HWND hWnd, hwndParent;
ITextHost *texthost;
IRichEditOle *reOle;
BOOL bEmulateVersion10;
ME_TextBuffer *pBuffer;
ME_Cursor *pCursors;

View File

@ -92,15 +92,22 @@ static void release_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **tx
ITextSelection_Release(*txtSel);
}
static ULONG get_refcount(IUnknown *iface)
{
IUnknown_AddRef(iface);
return IUnknown_Release(iface);
}
static void test_Interfaces(void)
{
IRichEditOle *reOle = NULL;
IRichEditOle *reOle = NULL, *reOle1 = NULL;
ITextDocument *txtDoc = NULL;
ITextSelection *txtSel = NULL;
IUnknown *punk;
HRESULT hres;
LRESULT res;
HWND w;
ULONG refcount;
w = new_richedit(NULL);
if (!w) {
@ -111,6 +118,14 @@ static void test_Interfaces(void)
res = SendMessageA(w, EM_GETOLEINTERFACE, 0, (LPARAM)&reOle);
ok(res, "SendMessage\n");
ok(reOle != NULL, "EM_GETOLEINTERFACE\n");
refcount = get_refcount((IUnknown *)reOle);
ok(refcount == 2, "got wrong ref count: %d\n", refcount);
res = SendMessageA(w, EM_GETOLEINTERFACE, 0, (LPARAM)&reOle1);
ok(res == 1, "SendMessage\n");
ok(reOle1 == reOle, "Should not return a new IRichEditOle interface\n");
refcount = get_refcount((IUnknown *)reOle);
ok(refcount == 3, "got wrong ref count: %d\n", refcount);
hres = IRichEditOle_QueryInterface(reOle, &IID_ITextDocument,
(void **) &txtDoc);
@ -142,6 +157,8 @@ static void test_Interfaces(void)
ITextDocument_Release(txtDoc);
IRichEditOle_Release(reOle);
refcount = IRichEditOle_Release(reOle);
ok(refcount == 1, "got wrong ref count: %d\n", refcount);
DestroyWindow(w);
/* Methods should return CO_E_RELEASED if the backing document has