IT-Consultant: José Roca (PBWIN 10+/PBCC 6+) (Archive only) > COM Programming

Releasing/Freeing Objects Received In Event Procedures

<< < (2/2)

Frederick J. Harris:
Thanks a lot Jose.  I'm really trying to understand it but I believe I've got it.  I'll probably have to sleep on it though.  I think I'm making it more difficult than it is.  Looks like some free/release calls that I was suspecting I needed to make aren't necessary.  In the case of this C++ output log code...

--- Code: ---void CEventSink::NavigateComplete2(IDispatch* pDisp, VARIANT* pVariantURL)
 #ifdef MyDebug
 fprintf(fp,"  Entering CEventSink::NavigateComplete2()\n");
 fwprintf(fp,L"    %s\n",pVariantURL->bstrVal);   //VARIANT* pvarVal;  // VT_BYREF|VT_VARIANT. 
 fprintf(fp,"  Leaving CEventSink::NavigateComplete2()\n\n");

--- End code ---

...that has to be correct if this PowerBASIC code is correct...

--- Code: ---' =====================================================================================
   METHOD NavigateComplete2 <252> _
   ( _
     BYVAL prm_pDisp AS IDispatch, _                    ' [in] *pDisp VT_DISPATCH <IDispatch>
     BYREF prm_URL AS VARIANT _                         ' [in] *URL VT_VARIANT <Variant>
   )                                                    ' void
     ' *** Insert your code here ***
' =====================================================================================

--- End code ---

--- Quote ---Because the IDispatch pointer is being passed by value, PB will call AddRef at the beginning
of the method and Release at the end. If it was passed by reference, it will do nothing.

--- End quote ---

That's exactly the effect I've noted many times and caught in output logs where I wrote both
the server and client code with low level COM and was using a PB client.  I hadn't associated it
with my question until you mentioned it.  Thanks for bringing it up.

Yep, I've got to digest this! :)


[0] Message Index

[*] Previous page

Go to full version