Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
#define VALIDATECOMPTR (   type,
  smartComPtr 
)    IID_##type, reinterpret_cast<P6R::P6VOID**>(static_cast<type**>((smartComPtr).addressofWithRelease()))

COM interfaces provide many advantages, however, one weakness is the use of void pointers in getters dealing with interface pointers.

To help mitigate the absence of type safety, we have provide this macro to enforce compile time type safety when assigning interface pointers via getters. This macro also helps prevent interface leaks through its use of p6ComPtr's addressOfWithRelease() method when assiging interface pointers. This ensures that any previously assigned interface pointer is released prior to assigning a new pointer. This should be used anywhere that interface pointers are assigned to a p6ComPtr by specifying and interface ID.

Here's and example:

* p6ComPtr<p6IConsole> cpConsole;
*
* // This is valid, but there are two problems. The first is obviously
* // we are querying for an p6ISafeString, but we are storing the result
* // in an p6IConsole smart pointer. The second, is that if cpConsole
* // were to have a previous value, it would be overwritten and as a
* // result would leak. Something p6ComPtr<> is supposed to prevent.
* someInterface->queryInterface(IID_p6ISafeString,&cpConsole);
*
* // Here we have fixed the second problem of a previous value in
* // cpConsole leaking, and the line still compiles fine. However,
* // since we are assigning the wrong interface this will most
* // certainly crash when cpConsole is dereferenced.
* someInterface->queryInterface(IID_p6ISafeString,cpConsole.addressofWithRelease());
*
* // Now using VALIDATECOMPTR() to fix this, a compiler error is generated
* // (something like: cannot convert from 'P6R::p6IConsole **' to 'P6R::p6ISafeString **')
* // and the error is caught at compile time.
* someInterface->queryInterface(VALIDATECOMPTR(p6ISafeString,cpConsole));
*
* // We fix the error and this compiles and runs as expected.
* someInterface->queryInterface(VALIDATECOMPTR(p6IConsole,cpConsole));
*
See Also
VALIDTATEIF()

Definition at line 430 of file p6comptr.h.