ITransactionContextEx::Abort 方法 (comsvcs.h)

中止參與目前交易之所有 COM 物件的工作。 交易會在此方法傳回時結束。

Syntax

HRESULT Abort();

傳回值

這個方法可以傳回標準傳回值E_INVALIDARG、E_OUTOFMEMORY和E_UNEXPECTED,以及下列值。

傳回碼 描述
S_OK
交易已中止。
E_FAIL
TransactionContextEx 物件未在 COM+ 進程下執行,可能表示 TransactionContextEx 元件的登錄專案損毀。

備註

呼叫 Abort 會在方法傳回時結束交易,並自動停用所有參與的物件。 交易中登記的每個資源管理員都會回復代表這些物件執行的作業。

範例

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

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

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

// Do some work here.

// If something goes wrong, abort the transaction.
if (bUserCanceled) {
    hr = pTransactionContext->Abort();
    if (FAILED(hr)) throw(hr);

// Otherwise, commit it.
} else {
    hr = pTransactionContext->Commit();
    if (FAILED(hr)) throw(hr);
}


規格需求

需求
最低支援的用戶端 Windows 2000 Professional [僅限傳統型應用程式]
最低支援的伺服器 Windows 2000 Server [僅限桌面應用程式]
目標平台 Windows
標頭 comsvcs.h

另請參閱

ITransactionContextEx