]> git.saurik.com Git - wxWidgets.git/commitdiff
Always create new OLE objects with reference count of 1, not 0.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 24 Oct 2010 22:41:41 +0000 (22:41 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 24 Oct 2010 22:41:41 +0000 (22:41 +0000)
There are no real changes but ensure that the new objects of classes using
DECLARE_OLE_UNKNOWN() macro are created with valid reference count of 1
instead of being created in phantom state with reference count of 0.

Remove the now unnecessary AddRef() and add the now required DecRef() calls.

See #11566.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65912 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/ole/activex.cpp

index 743689bbb07e146e4110ce4a2dee1a6155785b77..71bbed04508a21acff9a1c54d5cf5fa5801423d0 100644 (file)
@@ -54,7 +54,7 @@ wxDEFINE_EVENT( wxEVT_ACTIVEX, wxActiveXEvent );
     {\
         public:\
         LONG l;\
-        TAutoInitInt() : l(0) {}\
+        TAutoInitInt() : l(1) {}\
     };\
     TAutoInitInt refCount, lockCount;\
     static void _GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc);\
@@ -928,7 +928,6 @@ void wxActiveXContainer::CreateActiveX(REFIID iid, IUnknown* pUnk)
 
     // FrameSite
     m_frameSite = new FrameSite(m_realparent, this);
-    m_frameSite->AddRef();
     // oleClientSite
     hret = m_clientSite.QueryInterface(
         IID_IOleClientSite, (IDispatch *) m_frameSite);
@@ -1031,8 +1030,15 @@ void wxActiveXContainer::CreateActiveX(REFIID iid, IUnknown* pUnk)
 
                 if ( cp )
                 {
-                    hret = cp->Advise(new wxActiveXEvents(this, ta->guid),
-                                      &adviseCookie);
+                    wxActiveXEvents * const
+                        events = new wxActiveXEvents(this, ta->guid);
+                    hret = cp->Advise(events, &adviseCookie);
+
+                    // We don't need this object any more and cp will keep a
+                    // reference to it if it needs it, i.e. if Advise()
+                    // succeeded.
+                    events->Release();
+
                     CHECK_HR(hret);
                 }
             }