Click here to Skip to main content
15,905,785 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Pure Virtual Functions Pin
Roger Allen9-Apr-02 4:42
Roger Allen9-Apr-02 4:42 
QuestionHow to make my window transparent while dragged (code inside) Pin
John O'Byrne9-Apr-02 4:30
John O'Byrne9-Apr-02 4:30 
AnswerRe: How to make my window transparent while dragged (code inside) Pin
Roger Allen9-Apr-02 4:46
Roger Allen9-Apr-02 4:46 
GeneralRe: How to make my window transparent while dragged (code inside) Pin
John O'Byrne9-Apr-02 4:55
John O'Byrne9-Apr-02 4:55 
GeneralRe: How to make my window transparent while dragged (code inside) Pin
Roger Allen9-Apr-02 5:20
Roger Allen9-Apr-02 5:20 
GeneralRe: How to make my window transparent while dragged (code inside) Pin
John O'Byrne9-Apr-02 5:37
John O'Byrne9-Apr-02 5:37 
General*LPUNKOWN Pin
Braulio Dez9-Apr-02 4:05
Braulio Dez9-Apr-02 4:05 
GeneralRe: *LPUNKOWN Pin
Tim Smith9-Apr-02 4:25
Tim Smith9-Apr-02 4:25 
Yes and yes. Both are correct.

Here are some general rules about addref/release. A lot of it is based on the idea of borrowing an interface and owning an interface.

1. When an interface is passed to another routine, the routine need not invoke AddRef UNLESS the interface is going to be saved and later used outside of the scope of the invocation.

The idea here is that the calling routine already owns the object (by having a ref). Thus, the routine being called temporarily borrows ownership of the object while it is executing.

2. When an interface is returned to a calling routine, the routine returning the interface MUST AddRef the object. Then when the calling routine is done with the interface he should Release unless the interface is being saved for later use.

The idea in this case is that when the routine being called returns, he must either give the ownership of the object to the calling routine (by not calling AddRef) or share ownership with himself and the caller by invoking AddRef.


You code is a perfect example of point #2. The routine being called AddRefs the object to be returned. The calling routine saves a copy of the object (which due to how CComQIPtr works also does an AddRef) and then releases the returned interface.

So after all is said and done, _pXMLClonedDoc in both objects still maintain a reference.

Tim Smith

I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
GeneralRe: *LPUNKOWN Pin
Braulio Dez9-Apr-02 4:45
Braulio Dez9-Apr-02 4:45 
GeneralRe: *LPUNKOWN Pin
Niklas L9-Apr-02 4:35
Niklas L9-Apr-02 4:35 
GeneralRe: *LPUNKOWN Pin
Braulio Dez9-Apr-02 4:50
Braulio Dez9-Apr-02 4:50 
GeneralC++ question Pin
Rajveer9-Apr-02 3:46
Rajveer9-Apr-02 3:46 
GeneralRe: C++ question Pin
Paul M Watt9-Apr-02 3:56
mentorPaul M Watt9-Apr-02 3:56 
GeneralRe: C++ question Pin
Rajveer9-Apr-02 4:37
Rajveer9-Apr-02 4:37 
GeneralRe: C++ question Pin
Paul M Watt9-Apr-02 5:25
mentorPaul M Watt9-Apr-02 5:25 
GeneralRe: C++ question Pin
woods139-Apr-02 4:28
woods139-Apr-02 4:28 
GeneralRe: C++ question Pin
PJ Arends9-Apr-02 5:16
professionalPJ Arends9-Apr-02 5:16 
QuestionHow can I retrieve a system small icon? Pin
AmarB9-Apr-02 3:36
AmarB9-Apr-02 3:36 
AnswerRe: How can I retrieve a system small icon? Pin
Alexandru Savescu9-Apr-02 3:54
Alexandru Savescu9-Apr-02 3:54 
GeneralRe: How can I retrieve a system small icon? Pin
AmarB9-Apr-02 4:52
AmarB9-Apr-02 4:52 
AnswerRe: How can I retrieve a system small icon? Pin
Shog99-Apr-02 5:22
sitebuilderShog99-Apr-02 5:22 
GeneralRe: How can I retrieve a system small icon? Pin
AmarB9-Apr-02 6:17
AmarB9-Apr-02 6:17 
GeneralRe: How can I retrieve a system small icon? Pin
Shog99-Apr-02 7:21
sitebuilderShog99-Apr-02 7:21 
GeneralRe: How can I retrieve a system small icon? Pin
AmarB9-Apr-02 7:59
AmarB9-Apr-02 7:59 
AnswerRe: How can I retrieve a system small icon? Pin
lszyn10-May-02 16:23
lszyn10-May-02 16:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.