ITransactionContextEx::Abort, ITransactionContextEx::Commit Methods Example

#include <Txctx.h>

ITransactionContextEx* pTransactionContext = NULL;
IMyObject* pMyObject = NULL;
boolean bUserCanceled = FALSE;
HRESULT hr;

// Get TransactionContextEx.
hr = CoCreateInstance(CLSID_ITransactionContextEx, 
    NULL, CLSCTX_INPROC, IID_ITransactionContextEx, 
    (void**) &pTransactionContext);

// Create an instance of MyObject.
hr = pTransactionContext->CreateInstance 
    (CLSID_CMyObject, IID_IMyObject, 
    (void**) &pMyObject);

// Do some work here.

// If something goes wrong, abort the transaction.
if (bUserCanceled) 
    pTransactionContext->Abort();

// Otherwise, commit it.
else
    pTransactionContext->Commit();