ErrorWrapper 類別

定義

警告

此 API 現已淘汰。

包裝封送處理器應將其當做 VT_ERROR 來封送處理的物件。Wraps objects the marshaler should marshal as a VT_ERROR.

public ref class ErrorWrapper sealed
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
[System.Obsolete("ErrorWrapper and support for marshalling to the VARIANT type may be unavailable in future releases.")]
public sealed class ErrorWrapper
type ErrorWrapper = class
Public NotInheritable Class ErrorWrapper
繼承
ErrorWrapper
屬性

範例

下列程式碼範例會先示範以 Int32 物件的形式從 COM 封送回的一個 Int32 物件。The following code example first demonstrates a lone Int32 object marshaled back from COM as an Int32 object. 然後,它會示範從 COM 封送回的 Int32 陣列,做為 UInt32 陣列。It then demonstrates an Int32 array marshaled back from COM as a UInt32 array.

// Scenario 1:  
// Pass a single value.  
Int32 x = 3;  
Object o = new ErrorWrapper(x);  
// Pass 'o' to COM.  
// On the return trip, 'o' has been unwrapped and is still an Int32 object.  
Int32 y = (Int32)o;  
Scenario 2:  
// Pass an array of values.  
Int32[] arr = new Int32[3];  
Object o = new ErrorWrapper(arr);  
// Pass 'o' to COM.  
// On the return trip, 'o' has been unwrapped and is now a UInt32[] array.  
UInt32[ ] arr2 = (UInt32[])o;  

備註

根據預設,Object 型別引數會封送處理為 VARIANT 型別,其中物件型別會決定 VARIANTVARTYPE 值。By default, Object type arguments are marshaled as a VARIANT type, where the object type determines the VARTYPE value of the VARIANT.

ErrorWrapper 型別必須當做 Object 型別傳遞,以當做 VT_ERROR型別的 VARIANT 封送處理,否則 ErrorWrapper 型別會封送處理為整數。The ErrorWrapper type must to be passed as an Object type to be marshaled as a VARIANT of type VT_ERROR, otherwise the ErrorWrapper type is marshaled as an integer.

下表說明使用平台叫用,在原生函式的 managed 呼叫中進行封送處理。The following table illustrates marshaling in a managed call to a native function, using platform invoke.

Managed 簽章參數Managed signature parameter pArr 值pArr value 封送處理為Marshaled as
ErrorWrapper[] pArrErrorWrapper[] pArr ErrorWrapper [10] of ErrorWrapper (77)ErrorWrapper[10] of ErrorWrapper(77) Int[10]
Object [] pArrObject[] pArr ErrorWrapper [10] of ErrorWrapper (77)ErrorWrapper[10] of ErrorWrapper(77) VARIANT[10]VT_ERRORVARIANT[10] of VT_ERROR
Object [] pArrObject[] pArr ErrorWrapper 的物件 [10] (77)Object[10] of ErrorWrapper(77) VARIANT[10]VT_ERRORVARIANT[10] of VT_ERROR

下表說明使用 COM 執行時間可呼叫包裝函式(RCW),將 managed 呼叫中的資料封送處理至原生函式。The following table illustrates marshaling data in a managed call to a native function, using COM runtime callable wrappers (RCW).

Managed 簽章參數Managed signature parameter pArr 值pArr value 封送處理為Marshaled as
ErrorWrapper[] pArrErrorWrapper[] pArr ErrorWrapper [10] of ErrorWrapper (77)ErrorWrapper[10] of ErrorWrapper(77) Int[10]
Object [] pArrObject[] pArr ErrorWrapper [10] of ErrorWrapper (77)ErrorWrapper[10] of ErrorWrapper(77) SafeArrayTypeMismatch 例外狀況SafeArrayTypeMismatch exception
Object [] pArrObject[] pArr ErrorWrapper 的物件 [10] (77)Object[10] of ErrorWrapper(77) SAFEARRAY(VARIANT)

請注意,ErrorWrapper 物件從 COM 傳回之後,不會封送處理為類型 VT_ERRORNote that ErrorWrapper objects are not marshaled as type VT_ERROR after they are passed back from COM. 單一值會從 COM 封送回做為類型 VT_I4,而陣列則會從 COM 封送回做為類型 VT_UI4A single value is marshaled back from COM as type VT_I4, while arrays are marshaled back from COM as type VT_UI4.

如需 VT_ERROR的詳細資訊,請參閱 MSDN library 中 VARENUM::VT_ERROR 的現有檔。For more information on VT_ERROR, please see the existing documentation for VARENUM::VT_ERROR in the MSDN library.

建構函式

ErrorWrapper(Exception)

使用與所提供之例外狀況 (Exception) 對應的 HRESULT,初始化 ErrorWrapper 類別的新執行個體。Initializes a new instance of the ErrorWrapper class with the HRESULT that corresponds to the exception supplied.

ErrorWrapper(Int32)

使用錯誤的 HRESULT 來初始化 ErrorWrapper 類別的新執行個體。Initializes a new instance of the ErrorWrapper class with the HRESULT of the error.

ErrorWrapper(Object)

使用包含錯誤的 HRESULT 的物件,初始化 ErrorWrapper 類別的新執行個體。Initializes a new instance of the ErrorWrapper class with an object containing the HRESULT of the error.

屬性

ErrorCode

取得包裝函式的錯誤碼。Gets the error code of the wrapper.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於