|
|
Home | Loader API | Interfaces | File List | Index | |
Like VALIDATEIF() but meant for use with p6ComPtr<> This macro attempts to provide compile time type safety when assigning interface pointers via getters and prevents leaks by using the p6ComPtr's addressOfWithRelease() method. 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 without crashing or leaking. someInterface->queryInterface(VALIDATECOMPTR(p6IConsole,cpConsole)); Definition at line 392 of file p6comptr.h. |