MarshalAs Attribute

   
MarshalAs Attribute

Class

System.Runtime.InteropServices.MarshalAsAttribute

Applies to

Field, Parameter, ReturnValue

Description

Defines the correct type conversion between managed and unmanaged code. Unmanaged types are defined by the UnmanagedType enumeration, which is shown in the following table:

UnmanagedType

Value

Description

AnsiBStr

35

An ANSI BSTR (a character string whose first byte indicates the string length).

AsAny

40

Dynamic type determination at runtime.

Bool

2

4-byte Boolean ( True <> 0, False = 0).

BStr

19

A Unicode BSTR (a character string whose first 2 bytes indicates the string length).

ByValArray

30

An array passed by value. An array that is a field in a structure must have this attribute. The SixeConst field must be set to the number of array elements, and the ArraySubType field can optionally be set to the unmanaged data type of the array.

ByValTStr

23

An inline fixed-length character array within a structure. The character type is determined by the CharSet argument of the containing structure's <StructLayout> attribute.

Currency

15

A COM Currency data type. Used on the VB.NET and .NET Decimal data type.

CustomMarshaler

44

A custom marshaler class. The class is defined by the MarshalType or MarshelTypeRef field. Additional information can be passed to the custom marshaler by the MarshalCookie field.

Error

45

An HRESULT . The native .NET type should be a 4-byte signed or unsigned integer.

FunctionPtr

38

A function pointer.

I1

3

A 1-byte signed integer.

I2

5

A 2-byte signed integer.

I4

7

A 4-byte signed integer.

I8

9

An 8-byte signed integer.

IDispatch

26

A COM IDispatch pointer.

Interface

28

A COM interface pointer.

IUnknown

25

A COM IUnknown pointer.

LPArray

42

A C-style array. Its length is indicated by the SizeConst and SizeParamIndex fields. Optionally, the ArraySubType field can indicate the unmanaged type of string elements within the array.

LPStr

20

An ANSI (single-byte) character string.

LPStruct

43

A pointer to a structure.

LPTStr

32

A platform-dependent character string (ANSI on WIndows 9x, Unicode on WIndows NT/2000/XP). LPTStr is supported only for platform invoke, and not for COM interop.

LPWStr

21

A Unicode (double-byte) character string.

R4

11

A 4-byte floating point number.

R8

12

An 8-byte floating point number.

SafeArray

29

A SafeArray (a self-describing array that includes information on its type, dimension, and bounds).

Struct

27

A C-style structure used to marshal .NET formatted classes and value types.

SysInt

31

A platform-dependent integer (4 bytes on 32-bit Windows, 8 bytes on 64-bit Windows).

SysUInt

32

The hardware's natural sized unsigned integer.

TBStr

36

A length-prefixed, platform-dependent character string (ANSI in Windows 9x, Unicode on Windows NT/2000/XP).

U1

4

A 1-byte unsigned integer.

U2

6

A 2-byte unsigned integer.

U4

8

A 4-byte unsigned integer.

U8

10

An 8-byte unsigned integer.

VariantBool

37

A 2-byte OLE-defined Boolean value ( True = -1, False = 0).

VBByRefStr

34

Allows Visual Basic to change a string in unmanaged code and reflect the changed skin in managed code.

Constructor

 New(   unmanagedType   ) 
unmanagedType (Short or UnmanagedType enumeration)

Indicates the COM (unmanaged) data type to which the data is to be converted. unmanagedType can either be a constant of the UnmanagedType enumeration or its corresponding Short value, as shown in the previous table.

Properties

Value ( UnmanagedType enumeration)

The COM (unmanaged) data type that the .NET (managed) data is to be marshaled as.

Fields

ArraySubType ( UnmanagedType enumeration)

The subtype of an array of type ByValArray or LPArray . It is used when an array contains strings so that the runtime knows how to marshal a string array to COM.

MarshalCookie (String)

An undefined field that can be used to pass user -defined data to a custom marshaler. The value of the MarshalCookie field as passed to the custom marshaler's GetInstance method.

MarshalType (String)

The fully qualified name of a custom marshaler. It is required if the Value property is CustomMarshaler .

MarshalTypeRef (Type)

Implements the MarshalType value as a Type, rather than a string.

SafeArraySubType ( VarEnum enumeration)

The data type of a SafeArray. Possible values are the members of the VarEnum enumeration, which is shown in the following table:

Constant

Description

VT_ARRAY

A SAFEARRAY pointer

VT_BLOB

A length-prefixed collection of bytes

VT_BLOB_OBJECT

A VT_BLOB containing an object

VT_BOOL

A Boolean value

VT_BSTR

A string of type BSTR

VT_BYREF

A value passed by reference

VT_CARRAY

A C-style array

VT_CF

Clipboard format

VT_CLSID

A class identifier (CLSID)

VT_CY

A currency value

VT_DATE

A date value

VT_DECIMAL

A decimal value

VT_DISPATCH

An IDispatch pointer

VT_EMPTY

A value was not specified

VT_ERROR

An SCODE

VT_FILETIME

A FILETIME value

VT_HRESULT

An HRESULT

VT_I1

A char value

VT_I2

A short (two-byte) integer

VT_I4

A long (4-byte) integer

VT_I8

A 64-bit integer

VT_INT

An integer value

VT_LPSTR

A null- terminated string

VT_LPWSTR

A null-terminated Unicode string

VT_NULL

A null reference ( Nothing )

VT_PTR

A pointer

VT_R4

A floating-point value

VT_R8

A double value

VT_RECORD

A user-defined type

VT_SAFEARRAY

A SAFEARRAY

VT_STORAGE

A named storage

VT_STORED_OBJECT

Storage containing an object

VT_STREAM

A named stream

VT_STREAMED_OBJECT

A Stream containing an object

VT_UI1

An unsigned byte

VT_UI2

An unsigned (2-byte) short

VT_UI4

An unsigned (4-byte) long

VT_UI8

A 64-bit unsigned integer

VT_UINT

An unsigned integer

VT_UNKNOWN

An IUnknown pointer

VT_USERDEFINED

A user-defined type

VT_VARIANT

A VARIANT far pointer

VT_VECTOR

A simple counted array

VT_VOID

A C-style void

SafeArrayUserDefinedSubType (Type object)

The user-defined type of the SAFEARRAY . This field is used only if the value of the SafeArraySubType field is VT_UNKNOWN , VT_DISPATCH , or VT_RECORD .

SizeConst (Integer)

The number of elements in a fixed-length array

SizeParamIndex (Short)

Indicates which zero-based parameter contains a count of array elements

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net