| Platform SDK: Transaction Server | 
ITransactionContextEx::Abort, ITransactionContextEx::Commit Methods Example
[This product will work only on Windows NT 4.0 versions and earlier. For Windows 2000 and later, see COM+ (Component Services).]
#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();