Pokazywanie postów oznaczonych etykietą do_GetInterface. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą do_GetInterface. Pokaż wszystkie posty

piątek, 13 listopada 2009

nsCOMPtr: AddRef, Release and QueryInterface

Here's the ultimate tutorial for nsCOMPtr: Using nsCOMPtr - Getting Started Guide

Vars:Assignment:Output parameters (GetFoo() adds reference itself, so tell nsFoo not to):Return values (CreateFoo() adds reference itself, so tell nsFoo not to):Four ways to QueryInterface:QueryInterface and GetInterface:
getInterface is very similar to QueryInterface. The main difference is that interfaces returned from getInterface are not required to provide a way back to the object implementing nsIInterfaceRequestor. The semantics of QueryInterface dictate that given an interface A that you QueryInterface on to get to interface B, you must be able to QueryInterface on B to get back to A. nsIInterfaceRequestor, however, allows you to obtain an interface C from A that may (or most likely) will not have the ability to get back to A.
Helper: do_GetInterface()

Caution: most frequent leaks are caused by assigning a raw pointer you have already AddRefed: