SafeRef Function Example

#include <mtx.h>


IMyInterface* pSafeMyObject = NULL;
IAnotherObject* pOtherObject = NULL;
HRESULT hr;

// Get a safe reference.
pSafeMyObject = SafeRef(IID_IMyInterface,
    (IUnknown*)this);

// Invoke a method on another object, passing the
// safe reference so it can call back.
hr = pOtherObject->CallMeBack(pSafeMyObject);

// Release the safe reference.
safeMyObject->Release();