Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

ErrorWrapper Class

Wraps objects the marshaler should marshal as a VT_ERROR.

System.Object
  System.Runtime.InteropServices.ErrorWrapper

Namespace:  System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)
[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class ErrorWrapper

The ErrorWrapper type exposes the following members.

  NameDescription
Public methodErrorWrapper(Exception)Initializes a new instance of the ErrorWrapper class with the HRESULT that corresponds to the exception supplied.
Public methodErrorWrapper(Int32)Initializes a new instance of the ErrorWrapper class with the HRESULT of the error.
Public methodErrorWrapper(Object)Initializes a new instance of the ErrorWrapper class with an object containing the HRESULT of the error.
Top
  NameDescription
Public propertyErrorCodeGets the error code of the wrapper.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

By default, Object type arguments are marshaled as a VARIANT type, where the object type determines the VARTYPE value of the VARIANT.

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.

The following table illustrates marshaling in a managed call to a native function, using platform invoke.

Managed signature parameter

pArr value

Marshaled as

ErrorWrapper[] pArr

ErrorWrapper[10] of ErrorWrapper(77)

Int[10]

Object[] pArr

ErrorWrapper[10] of ErrorWrapper(77)

VARIANT[10] of VT_ERROR

Object[] pArr

Object[10] of ErrorWrapper(77)

VARIANT[10] of VT_ERROR

The following table illustrates marshaling data in a managed call to a native function, using COM runtime callable wrappers (RCW).

Managed signature parameter

pArr value

Marshaled as

ErrorWrapper[] pArr

ErrorWrapper[10] of ErrorWrapper(77)

Int[10]

Object[] pArr

ErrorWrapper[10] of ErrorWrapper(77)

SafeArrayTypeMismatch exception

Object[] pArr

Object[10] of ErrorWrapper(77)

SAFEARRAY(VARIANT)

Note that ErrorWrapper objects are not marshaled as type VT_ERROR after they are passed back from COM. A single value is marshaled back from COM as type VT_I4, while arrays are marshaled back from COM as type VT_UI4.

For more information on VT_ERROR, please see the existing documentation for VARENUM::VT_ERROR in the MSDN library.

The following code example first demonstrates a lone Int32 object marshaled back from COM as an Int32 object. 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;

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.