System.Runtime.InteropServices.UnmanagedType Enumeration

Assembly: Mscorlib.dll
Namespace: System.Runtime.InteropServices
Summary
Identifies how parameters or fields should be marshaled to unmanaged code.
C# Syntax:
[Serializable]
public enum UnmanagedType
Example
using System;
using System.Runtime.InteropServices;

namespace MyModule
{
	// If you do not have a type library for an interface
	// you can redeclare it using ComImportAttribute.

	// This is how the interface would look in an idl file.

	//[
	//object,
	//uuid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26"),
	//dual,	helpstring("IMyStorage Interface"),
	//pointer_default(unique)
	//]
	//interface IMyStorage : IDispatch
	//{
	//	[id(1)]
	//	HRESULT GetItem([in] BSTR bstrName, [out, retval] IDispatch ** ppItem);
	//	[id(2)]
	//	HRESULT GetItems([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT)* pItems);
	//	[id(3)]
	//	HRESULT GetItemDescriptions([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT) ** ppItems);
	//	[id(4), propget]
	//	HRESULT get_IsEmpty([out, retval] BOOL * pfEmpty);
	//};

	// This is the managed declaration.

	[ComImport]
	[Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26")]
	public interface IMyStorage  
	{
		[DispId(1)]
		[return : MarshalAs( UnmanagedType.Interface )]
		Object GetItem( [In, MarshalAs( UnmanagedType.BStr )] String bstrName );

		[DispId(2)]
		void GetItems( [In, MarshalAs( UnmanagedType.BStr )] String bstrLocation, 
			[Out, MarshalAs( UnmanagedType.SafeArray, 
					  SafeArraySubType = VarEnum.VT_VARIANT )] out Object[] Items );
                
                
		[DispId(3)]
		void GetItemDescriptions( [In] String bstrLocation, 
			[In, Out, MarshalAs( UnmanagedType.SafeArray )] ref Object[] varDescriptions );

		bool IsEmpty 
		{
			[DispId(4)]
			[return : MarshalAs( UnmanagedType.VariantBool )]
			get;
		}
	}
}

    
See also:
System.Runtime.InteropServices Namespace

System.Runtime.InteropServices.UnmanagedType Member List:

Public Fields
AsAny Dynamic type that determines the Type of an object at runtime and marshals the object as that Type.
Bool 4-byte Boolean value (true!= 0, false = 0).
ByValArray When MarshalAsAttribute.Value is set to ByValArray the MarshalAsAttribute.SizeConst must be set to indicate the number of elements in the array. The MarshalAsAttribute.ArraySubType field may optionally contain the UnmanagedType of the array elements when it is necessary to differentiate among string types. Also, this UnmanagedType can only be used on an array that appear as fields in a structure.
ByValTStr Used for in-line fixed length character arrays that appear within a structure. The character type used with ByValTStr is determined by the CharSet argument of the StructLayoutAttribute applied to the containing structure.
Currency Used on a Decimal to marshal the decimal value as a COM currency type instead of as a Decimal.
CustomMarshaler Specifies the custom marshaler class when used with MarshalAsAttribute.MarshalType or MarshalAsAttribute.MarshalTypeRef. The MarshalAsAttribute.MarshalCookie field can be used to pass additional information to the custom marshaler.
Error This native type associated with an UnmanagedType.I4 or a UnmanagedType.U4 will cause the parameter to be exported as a HRESULT in the exported type library.
FunctionPtr A function pointer.
I1 1-byte signed integer.
I2 2-byte signed integer.
I4 4-byte signed integer.
I8 8-byte signed integer.
IUnknown
LPArray
LPStr A single byte ANSI character string.
LPStruct A pointer to a C-style structure. Used to marshal managed formatted classes.
LPTStr A platform dependent character string, ANSI on Windows 98, Unicode on Windows NT. This value is only supported for platform invoke, and not COM interop, because exporting a string of type LPTStr is not supported.
LPWStr A double byte Unicode character string.
R4 4-byte floating point number.
R8 8-byte floating point number.
Struct A C-style structure, used to marshal managed formatted classes and value types.
SysInt A platform dependent signed integer. 4-bytes on 32 bit Windows, 8-bytes on 64 bit Windows.
SysUInt Hardware natural sized unsigned integer.
U1 1-byte unsigned integer.
U2 2-byte unsigned integer.
U4 4-byte unsigned integer.
U8 8-byte unsigned integer.

Hierarchy:


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.