System.Runtime.InteropServices Namespace
The System.Runtime.InteropServices namespace provides a wide variety of members that support COM interop and platform invoke services. If you are unfamiliar with these services, see Interoperating with Unmanaged Code.
Members of this namespace provide several categories of functionality, as shown in the following table. Attributes control marshaling behavior, such as how to arrange structures or how to represent strings. The most important attributes are DllImportAttribute, which you use to define platform invoke methods for accessing unmanaged APIs, and MarshalAsAttribute, which you use to specify how data is marshaled between managed and unmanaged memory.
Classes
| Class | Description |
|---|---|
| AutomationProxyAttribute | Specifies whether the type should be marshaled using the Automation marshaler or a custom proxy and stub. |
| BestFitMappingAttribute | Controls whether Unicode characters are converted to the closest matching ANSI characters. |
| ClassInterfaceAttribute | Indicates the type of class interface to be generated for a class exposed to COM, if an interface is generated at all. |
| CoClassAttribute | Specifies the class identifier of a coclass imported from a type library. |
| ComAliasNameAttribute | Indicates the COM alias for a parameter or field type. |
| ComCompatibleVersionAttribute | Indicates to a COM client that all classes in the current version of an assembly are compatible with classes in an earlier version of the assembly. |
| ComConversionLossAttribute | Indicates that information was lost about a class or interface when it was imported from a type library to an assembly. |
| ComEventInterfaceAttribute | Identifies the source interface and the class that implements the methods of the event interface that is generated when a coclass is imported from a COM type library. |
| COMException | The exception that is thrown when an unrecognized HRESULT is returned from a COM method call. |
| ComImportAttribute | Indicates that the attributed type was previously defined in COM. |
| ComRegisterFunctionAttribute | Specifies the method to call when you register an assembly for use from COM; this allows for the execution of user-written code during the registration process. |
| ComSourceInterfacesAttribute | Identifies a list of interfaces that are exposed as COM event sources for the attributed class. |
| ComUnregisterFunctionAttribute | Specifies the method to call when you unregister an assembly for use from COM; this allows for the execution of user-written code during the unregistration process. |
| ComVisibleAttribute | Controls accessibility of an individual managed type or member, or of all types within an assembly, to COM. |
| CurrencyWrapper | Wraps objects the marshaler should marshal as a VT_CY. |
| DispatchWrapper | Wraps objects the marshaler should marshal as a VT_DISPATCH. |
| DispIdAttribute | Specifies the COM dispatch identifier (DISPID) of a method, field, or property. |
| DllImportAttribute | Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point. |
| ErrorWrapper | Wraps objects the marshaler should marshal as a VT_ERROR. |
| ExtensibleClassFactory | Enables customization of managed objects that extend from unmanaged objects during creation. |
| ExternalException | The base exception type for all COM interop exceptions and structured exception handling (SEH) exceptions. |
| FieldOffsetAttribute | Indicates the physical position of fields within the unmanaged representation of a class or structure. |
| GuidAttribute | Supplies an explicit System.Guid when an automatic GUID is undesirable. |
| IDispatchImplAttribute | Indicates which IDispatch implementation the common language runtime uses when exposing dual interfaces and dispinterfaces to COM. |
| ImportedFromTypeLibAttribute | Indicates that the types defined within an assembly were originally defined in a type library. |
| InAttribute | Indicates that data should be marshaled from the caller to the callee, but not back to the caller. |
| InterfaceTypeAttribute | Indicates whether a managed interface is dual, dispatch-only, or IUnknown-only when exposed to COM. |
| InvalidComObjectException | The exception thrown when an invalid COM object is used. |
| InvalidOleVariantTypeException | The exception thrown by the marshaler when it encounters an argument of a variant type that can not be marshaled to managed code. |
| LCIDConversionAttribute | Indicates that a method's unmanaged signature expects a locale identifier (LCID) parameter. |
| Marshal | Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks, and converting managed to unmanaged types, as well as other miscellaneous methods used when interacting with unmanaged code. |
| MarshalAsAttribute | Indicates how to marshal the data between managed and unmanaged code. |
| MarshalDirectiveException | The exception that is thrown by the marshaler when it encounters a MarshalAsAttribute it does not support. |
| OptionalAttribute | Indicates that a parameter is optional. |
| OutAttribute | Indicates that data should be marshaled from callee back to caller. |
| PreserveSigAttribute | Indicates that the HRESULT or retval signature transformation that takes place during COM interop calls should be suppressed. |
| PrimaryInteropAssemblyAttribute | Indicates that the attributed assembly is a primary interop assembly. |
| ProgIdAttribute | Allows the user to specify the ProgID of a class. |
| RegistrationServices | Provides a set of services for registering and unregistering managed assemblies for use from COM. |
| RuntimeEnvironment | Provides a collection of static (Shared in Visual Basic) methods that return information about the common language runtime environment. |
| SafeArrayRankMismatchException | The exception thrown when the rank of an incoming SAFEARRAY does not match the rank specified in the managed signature. |
| SafeArrayTypeMismatchException | The exception thrown when the type of the incoming SAFEARRAY does not match the type specified in the managed signature. |
| SEHException | Represents Structured Exception Handler (SEH) errors. |
| StructLayoutAttribute | The StructLayoutAttribute class allows the user to control the physical layout of the data fields of a class or structure. |
| TypeLibConverter | Provides a set of services that convert a managed assembly to a COM type library and vice versa. |
| TypeLibFuncAttribute | Contains the FUNCFLAGS that were originally imported for this method from the COM type library. |
| TypeLibTypeAttribute | Contains the TYPEFLAGS that were originally imported for this type from the COM type library. |
| TypeLibVarAttribute | Contains the VARFLAGS that were originally imported for this field from the COM type library. |
| TypeLibVersionAttribute | Specifies the version number of an exported type library. |
| UnknownWrapper | Wraps objects the marshaler should marshal as a VT_UNKNOWN. |
Interfaces
| Interface | Description |
|---|---|
| ICustomAdapter | Provides a way for clients to access the actual object, rather than the adapter object handed out by a custom marshaler. |
| ICustomFactory | Enables users to write activation code for managed objects that extend MarshalByRefObject. |
| ICustomMarshaler | Designed to provide custom wrappers for handling method calls. |
| IRegistrationServices | Provides a set of services for registering and unregistering managed assemblies for use from COM. |
| ITypeLibConverter | Provides a set of services that convert a managed assembly to a COM type library and vice versa. |
| ITypeLibExporterNameProvider | Provides control over the casing of names when exported to a type library. |
| ITypeLibExporterNotifySink | Provides a callback mechanism for the assembly converter to inform the caller of the status of the conversion, and involve the caller in the conversion process itself. |
| ITypeLibImporterNotifySink | Provides a callback mechanism for the type library converter to inform the caller of the status of the conversion, and involve the caller in the conversion process itself. |
| UCOMIBindCtx | Managed definition of the IBindCtx interface. |
| UCOMIConnectionPoint | Managed definition of the IConnectionPoint interface. |
| UCOMIConnectionPointContainer | Managed definition of the IConnectionPointContainer interface. |
| UCOMIEnumConnectionPoints | Manages the definition of the IEnumConnectionPoints interface. |
| UCOMIEnumConnections | Manages the definition of the IEnumConnections interface. |
| UCOMIEnumMoniker | Manages the definition of the IEnumMoniker interface. |
| UCOMIEnumString | Manages the definition of the IEnumString interface. |
| UCOMIEnumVARIANT | Manages the definition of the IEnumVARIANT interface. |
| UCOMIMoniker | Managed definition of the IMoniker interface, with COM functionality from IPersist and IPersistStream. |
| UCOMIPersistFile | Managed definition of the IPersistFile interface, with functionality from IPersist. |
| UCOMIRunningObjectTable | Managed definition of the IRunningObjectTable interface. |
| UCOMIStream | Managed definition of the IStream interface, with ISequentialStream functionality. |
| UCOMITypeComp | Managed definition of the ITypeComp interface. |
| UCOMITypeInfo | Managed definition of the ITypeInfo interface. |
| UCOMITypeLib | Managed definition of the ITypeLib interface. |
Structures
| Structure | Description |
|---|---|
| ArrayWithOffset | Encapsulates an array and an offset within the specified array. |
| BINDPTR | Contains a pointer to a bound-to FUNCDESC, VARDESC, or an ITypeComp interface. |
| BIND_OPTS | Stores the parameters that are used during a moniker-binding operation. |
| CONNECTDATA | Describes a connection that exists to a given connection point. |
| DISPPARAMS | Contains the arguments passed to a method or property by IDispatch::Invoke. |
| ELEMDESC | Contains the type description and process transfer information for a variable, function, or a function parameter. |
| ELEMDESC.DESCUNION | Contains information about an element. |
| EXCEPINFO | Describes the exceptions that occur during IDispatch::Invoke. |
| FILETIME | This structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601. |
| FUNCDESC | Defines a function description. |
| GCHandle | Provides a means for accessing a managed object from unmanaged memory. |
| HandleRef | Wraps a managed object holding a handle to a resource that is passed to unmanaged code using platform invoke. |
| IDLDESC | Contains information needed for transferring a structure element, parameter, or function return value between processes. |
| PARAMDESC | Contains information about how to transfer a structure element, parameter, or function return value between processes. |
| STATSTG | Contains statistical information about an open storage, stream, or byte-array object. |
| TYPEATTR | Contains attributes of a UCOMITypeInfo. |
| TYPEDESC | Describes the type of a variable, return type of a function, or the type of a function parameter. |
| TYPELIBATTR | Identifies a particular type library and provides localization support for member names. |
| VARDESC | Describes a variable, constant, or data member. |
| VARDESC.DESCUNION | Contains information about a variable. |
Delegates
| Delegate | Description |
|---|---|
| ObjectCreationDelegate | Creates a COM object. |
Enumerations
| Enumeration | Description |
|---|---|
| AssemblyRegistrationFlags | Defines a set of flags used when registering assemblies. |
| CALLCONV | Identifies the calling convention used by a method described in a METHODDATA structure. |
| CallingConvention | Specifies the calling convention required to call methods implemented in unmanaged code. |
| CharSet | Dictates which character set marshaled strings should use. |
| ClassInterfaceType | Identifies the type of class interface that is generated for a class. |
| ComInterfaceType | Identifies how to expose an interface to COM. |
| ComMemberType | Describes the type of a COM member. |
| DESCKIND | Identifies the type description being bound to. |
| ExporterEventKind | Describes the callbacks that the type library exporter makes when exporting a type library. |
| FUNCFLAGS | Identifies the constants that define the properties of a function. |
| FUNCKIND | Defines how to access a function. |
| GCHandleType | Represents the types of handles the GCHandle class can allocate. |
| IDispatchImplType | Indicates which IDispatch implementation to use for a particular class. |
| IDLFLAG | Describes how to transfer a structure element, parameter, or function return value between processes. |
| IMPLTYPEFLAGS | Defines the attributes of an implemented or inherited interface of a type. |
| ImporterEventKind | Describes the callbacks that the type library importer makes when importing a type library. |
| INVOKEKIND | Specifies how to invoke a function by IDispatch::Invoke. |
| LayoutKind | Controls the layout of an object when exported to unmanaged code. |
| LIBFLAGS | Defines flags that apply to type libraries. |
| PARAMFLAG | Describes how to transfer a structure element, parameter, or function return value between processes. |
| SYSKIND | Identifies the target operating system platform. |
| TYPEFLAGS | Defines the properties and attributes of a type description. |
| TYPEKIND | Specifies various types of data and functions. |
| TypeLibExporterFlags | Indicates how a type library should be produced. |
| TypeLibFuncFlags | Describes the original settings of the FUNCFLAGS in the COM type library from where this method was imported. |
| TypeLibImporterFlags | Indicates how an assembly should be produced. |
| TypeLibTypeFlags | Describes the original settings of the TYPEFLAGS in the COM type library from which the type was imported. |
| TypeLibVarFlags | Describes the original settings of the VARFLAGS in the COM type library from which the variable was imported. |
| UnmanagedType | Identifies how to marshal parameters or fields to unmanaged code. |
| VarEnum | Indicates how to marshal the array elements when an array is marshaled from managed to unmanaged code as a UnmanagedType.SafeArray. |
| VARFLAGS | Identifies the constants that define the properties of a variable. |