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.

  Class Description
Public class AllowReversePInvokeCallsAttribute Allows an unmanaged method to call a managed method.
Public class AutomationProxyAttribute Specifies whether the type should be marshaled using the Automation marshaler or a custom proxy and stub.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps BestFitMappingAttribute Controls whether Unicode characters are converted to the closest matching ANSI characters.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps BStrWrapper Marshals data of type VT_BSTR from managed to unmanaged code. This class cannot be inherited.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps ClassInterfaceAttribute Indicates the type of class interface to be generated for a class exposed to COM, if an interface is generated at all.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps CoClassAttribute Specifies the class identifier of a coclass imported from a type library.
Public class ComAliasNameAttribute Indicates the COM alias for a parameter or field type.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps ComAwareEventInfo Permits late-bound registration of an event handler.
Public class 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.
Public class ComConversionLossAttribute Indicates that information was lost about a class or interface when it was imported from a type library to an assembly.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps ComDefaultInterfaceAttribute Specifies a default interface to expose to COM. This class cannot be inherited.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps 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.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps ComEventsHelper Provides methods that enable .NET Framework delegates that handle events to be added and removed from COM objects.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps COMException The exception that is thrown when an unrecognized HRESULT is returned from a COM method call.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps ComImportAttribute Indicates that the attributed type was previously defined in COM.
Public class ComRegisterFunctionAttribute Specifies the method to call when you register an assembly for use from COM; this enables the execution of user-written code during the registration process.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps ComSourceInterfacesAttribute Identifies a list of interfaces that are exposed as COM event sources for the attributed class.
Public 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.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps ComVisibleAttribute Controls accessibility of an individual managed type or member, or of all types within an assembly, to COM.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps CriticalHandle Represents a wrapper class for handle resources.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps CurrencyWrapper Wraps objects the marshaler should marshal as a VT_CY.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps DefaultCharSetAttribute Specifies the value of the CharSet enumeration. This class cannot be inherited.
Public class Supported in .NET for Windows Store apps DefaultDllImportSearchPathsAttribute Specifies the paths that are used to search for DLLs that provide functions for platform invokes.
Public class Supported in .NET for Windows Store apps DefaultParameterValueAttribute Sets the default value of a parameter when called from a language that supports default parameters. This class cannot be inherited.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps DispatchWrapper Wraps objects the marshaler should marshal as a VT_DISPATCH.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps DispIdAttribute Specifies the COM dispatch identifier (DISPID) of a method, field, or property.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps DllImportAttribute Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps ErrorWrapper Wraps objects the marshaler should marshal as a VT_ERROR.
Public class ExtensibleClassFactory Enables customization of managed objects that extend from unmanaged objects during creation.
Public class ExternalException The base exception type for all COM interop exceptions and structured exception handling (SEH) exceptions.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps FieldOffsetAttribute Indicates the physical position of fields within the unmanaged representation of a class or structure.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps GuidAttribute Supplies an explicit System.Guid when an automatic GUID is undesirable.
Public class Supported in .NET for Windows Store apps HandleCollector Tracks outstanding handles and forces a garbage collection when the specified threshold is reached.
Public class IDispatchImplAttribute Obsolete. Indicates which IDispatch implementation the common language runtime uses when exposing dual interfaces and dispinterfaces to COM.
Public class ImportedFromTypeLibAttribute Indicates that the types defined within an assembly were originally defined in a type library.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps InAttribute Indicates that data should be marshaled from the caller to the callee, but not back to the caller.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps InterfaceTypeAttribute Indicates whether a managed interface is dual, dispatch-only, or IUnknown -only when exposed to COM.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps InvalidComObjectException The exception thrown when an invalid COM object is used.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps InvalidOleVariantTypeException The exception thrown by the marshaler when it encounters an argument of a variant type that can not be marshaled to managed code.
Public class LCIDConversionAttribute Indicates that a method's unmanaged signature expects a locale identifier (LCID) parameter.
Public class Supported by Portable Class Library ManagedToNativeComInteropStubAttribute Provides support for user customization of interop stubs in managed-to-COM interop scenarios.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps 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.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps MarshalAsAttribute Indicates how to marshal the data between managed and unmanaged code.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps MarshalDirectiveException The exception that is thrown by the marshaler when it encounters a MarshalAsAttribute it does not support.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps OptionalAttribute Indicates that a parameter is optional.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps OutAttribute Indicates that data should be marshaled from callee back to caller.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps PreserveSigAttribute Indicates that the HRESULT or retval signature transformation that takes place during COM interop calls should be suppressed.
Public class PrimaryInteropAssemblyAttribute Indicates that the attributed assembly is a primary interop assembly.
Public class ProgIdAttribute Allows the user to specify the ProgID of a class.
Public class RegistrationServices Provides a set of services for registering and unregistering managed assemblies for use from COM.
Public class RuntimeEnvironment Provides a collection of static methods that return information about the common language runtime environment.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps SafeArrayRankMismatchException The exception thrown when the rank of an incoming SAFEARRAY does not match the rank specified in the managed signature.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps SafeArrayTypeMismatchException The exception thrown when the type of the incoming SAFEARRAY does not match the type specified in the managed signature.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps SafeBuffer Provides a controlled memory buffer that can be used for reading and writing. Attempts to access memory outside the controlled buffer (underruns and overruns) raise exceptions.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps SafeHandle Represents a wrapper class for operating system handles. This class must be inherited.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps SEHException Represents structured exception handling (SEH) errors.
Public class SetWin32ContextInIDispatchAttribute Obsolete. This attribute has been deprecated.
Public class StandardOleMarshalObject Replaces the standard common language runtime (CLR) free-threaded marshaler with the standard OLE STA marshaler.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps StructLayoutAttribute Lets you control the physical layout of the data fields of a class or structure in memory.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps TypeIdentifierAttribute Provides support for type equivalence.
Public class TypeLibConverter Provides a set of services that convert a managed assembly to a COM type library and vice versa.
Public class TypeLibFuncAttribute Contains the FUNCFLAGS that were originally imported for this method from the COM type library.
Public class TypeLibImportClassAttribute Specifies which Type exclusively uses an interface. This class cannot be inherited.
Public class TypeLibTypeAttribute Contains the TYPEFLAGS that were originally imported for this type from the COM type library.
Public class TypeLibVarAttribute Contains the VARFLAGS that were originally imported for this field from the COM type library.
Public class TypeLibVersionAttribute Specifies the version number of an exported type library.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps UnknownWrapper Wraps objects the marshaler should marshal as a VT_UNKNOWN.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps UnmanagedFunctionPointerAttribute Controls the marshaling behavior of a delegate signature passed as an unmanaged function pointer to or from unmanaged code. This class cannot be inherited.
Public class Supported by Portable Class Library Supported in .NET for Windows Store apps VariantWrapper Marshals data of type VT_VARIANT | VT_BYREF from managed to unmanaged code. This class cannot be inherited.

  Structure Description
Public structure Supported by Portable Class Library Supported in .NET for Windows Store apps ArrayWithOffset Encapsulates an array and an offset within the specified array.
Public structure BIND_OPTS Obsolete. Use System.Runtime.InteropServices.ComTypes.BIND_OPTS instead.
Public structure BINDPTR Obsolete. Use System.Runtime.InteropServices.ComTypes.BINDPTR instead.
Public structure CONNECTDATA Obsolete. Use System.Runtime.InteropServices.ComTypes.CONNECTDATA instead.
Public structure DISPPARAMS Obsolete. Use System.Runtime.InteropServices.ComTypes.DISPPARAMS instead.
Public structure ELEMDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.ELEMDESC instead.
Public structure ELEMDESC.DESCUNION Use System.Runtime.InteropServices.ComTypes.ELEMDESC.DESCUNION instead.
Public structure EXCEPINFO Obsolete. Use System.Runtime.InteropServices.ComTypes.EXCEPINFO instead.
Public structure FILETIME Obsolete. Use System.Runtime.InteropServices.ComTypes.FILETIME instead.
Public structure FUNCDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.FUNCDESC instead.
Public structure Supported by Portable Class Library Supported in .NET for Windows Store apps GCHandle Provides a way to access a managed object from unmanaged memory.
Public structure HandleRef Wraps a managed object holding a handle to a resource that is passed to unmanaged code using platform invoke.
Public structure IDLDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.IDLDESC instead.
Public structure PARAMDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.PARAMDESC instead.
Public structure STATSTG Obsolete. Use System.Runtime.InteropServices.ComTypes.STATSTG instead.
Public structure TYPEATTR Obsolete. Use System.Runtime.InteropServices.ComTypes.TYPEATTR instead.
Public structure TYPEDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.TYPEDESC instead.
Public structure TYPELIBATTR Obsolete. Use System.Runtime.InteropServices.ComTypes.TYPELIBATTR instead.
Public structure VARDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.VARDESC instead.
Public structure VARDESC.DESCUNION Use System.Runtime.InteropServices.ComTypes.VARDESC.DESCUNION instead.

  Interface Description
Public interface _Activator Exposes the System.Activator class to unmanaged code.
Public interface _Assembly Exposes the public members of the System.Reflection.Assembly class to unmanaged code.
Public interface _AssemblyBuilder Exposes the System.Reflection.Emit.AssemblyBuilder class to unmanaged code.
Public interface _AssemblyName Exposes the AssemblyName class to unmanaged code.
Public interface _Attribute Exposes the System.Attribute class to unmanaged code.
Public interface _ConstructorBuilder Exposes the System.Reflection.Emit.ConstructorBuilder class to unmanaged code.
Public interface _ConstructorInfo Exposes the public members of the System.Reflection.ConstructorInfo class to unmanaged code.
Public interface _CustomAttributeBuilder Exposes the System.Reflection.Emit.CustomAttributeBuilder class to unmanaged code.
Public interface _EnumBuilder Exposes the System.Reflection.Emit.EnumBuilder class to unmanaged code.
Public interface _EventBuilder Exposes the System.Reflection.Emit.EventBuilder class to unmanaged code.
Public interface _EventInfo Exposes the public members of the System.Reflection.EventInfo class to unmanaged code.
Public interface _Exception Exposes the public members of the System.Exception class to unmanaged code.
Public interface _FieldBuilder Exposes the System.Reflection.Emit.FieldBuilder class to unmanaged code.
Public interface _FieldInfo Exposes the public members of the System.Reflection.FieldInfo class to unmanaged code.
Public interface _ILGenerator Exposes the System.Reflection.Emit.ILGenerator class to unmanaged code.
Public interface _LocalBuilder Exposes the System.Reflection.Emit.LocalBuilder class to unmanaged code.
Public interface _MemberInfo Exposes the public members of the System.Reflection.MemberInfo class to unmanaged code.
Public interface _MethodBase Exposes the public members of the System.Reflection.MethodBase class to unmanaged code.
Public interface _MethodBuilder Exposes the MethodBuilder class to unmanaged code.
Public interface _MethodInfo Exposes the public members of the System.Reflection.MethodInfo class to unmanaged code.
Public interface _MethodRental Exposes the System.Reflection.Emit.MethodRental class to unmanaged code.
Public interface _Module Exposes the Module class to unmanaged code.
Public interface _ModuleBuilder Exposes the System.Reflection.Emit.ModuleBuilder class to unmanaged code.
Public interface _ParameterBuilder Exposes the System.Reflection.Emit.ParameterBuilder class to unmanaged code.
Public interface _ParameterInfo Exposes the System.Reflection.ParameterInfo class to unmanaged code.
Public interface _PropertyBuilder Exposes the System.Reflection.Emit.PropertyBuilder class to unmanaged code.
Public interface _PropertyInfo Exposes the public members of the System.Reflection.PropertyInfo class to unmanaged code.
Public interface _SignatureHelper Exposes the System.Reflection.Emit.SignatureHelper class to unmanaged code.
Public interface _Thread Exposes the System.Threading.Thread class to unmanaged code.
Public interface _Type Exposes the public members of the System.Type class to the unmanaged code.
Public interface _TypeBuilder Exposes the System.Reflection.Emit.TypeBuilder class to unmanaged code.
Public interface Supported by Portable Class Library Supported in .NET for Windows Store apps ICustomAdapter Provides a way for clients to access the actual object, rather than the adapter object handed out by a custom marshaler.
Public interface ICustomFactory Enables users to write activation code for managed objects that extend MarshalByRefObject.
Public interface Supported by Portable Class Library ICustomMarshaler Provides custom wrappers for handling method calls.
Public interface Supported by Portable Class Library Supported in .NET for Windows Store apps ICustomQueryInterface Enables developers to provide a custom, managed implementation of the IUnknown::QueryInterface(REFIID riid, void **ppvObject) method.
Public interface IRegistrationServices Provides a set of services for registering and unregistering managed assemblies for use from COM.
Public interface ITypeLibConverter Provides a set of services that convert a managed assembly to a COM type library and vice versa.
Public interface ITypeLibExporterNameProvider Provides control over the casing of names when exported to a type library.
Public interface 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.
Public interface 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.
Public interface UCOMIBindCtx Obsolete. Use System.Runtime.InteropServices.ComTypes.BIND_OPTS instead.
Public interface UCOMIConnectionPoint Obsolete. Use System.Runtime.InteropServices.ComTypes.IConnectionPoint instead.
Public interface UCOMIConnectionPointContainer Obsolete. Use System.Runtime.InteropServices.ComTypes.IConnectionPointContainer instead.
Public interface UCOMIEnumConnectionPoints Obsolete. Use System.Runtime.InteropServices.ComTypes.IEnumConnectionPoints instead.
Public interface UCOMIEnumConnections Obsolete. Use System.Runtime.InteropServices.ComTypes.IEnumConnections instead.
Public interface UCOMIEnumMoniker Obsolete. Use System.Runtime.InteropServices.ComTypes.IEnumMoniker instead.
Public interface UCOMIEnumString Obsolete. Use System.Runtime.InteropServices.ComTypes.IEnumString instead.
Public interface UCOMIEnumVARIANT Obsolete. Use System.Runtime.InteropServices.ComTypes.IEnumVARIANT instead.
Public interface UCOMIMoniker Obsolete. Use System.Runtime.InteropServices.ComTypes.IMoniker instead.
Public interface UCOMIPersistFile Obsolete. Use System.Runtime.InteropServices.ComTypes.IPersistFile instead.
Public interface UCOMIRunningObjectTable Obsolete. Use System.Runtime.InteropServices.ComTypes.IRunningObjectTable instead.
Public interface UCOMIStream Obsolete. Use System.Runtime.InteropServices.ComTypes.IStream instead.
Public interface UCOMITypeComp Obsolete. Use System.Runtime.InteropServices.ComTypes.ITypeComp instead.
Public interface UCOMITypeInfo Obsolete. Use System.Runtime.InteropServices.ComTypes.ITypeInfo instead.
Public interface UCOMITypeLib Obsolete. Use System.Runtime.InteropServices.ComTypes.ITypeLib instead.

  Delegate Description
Public delegate ObjectCreationDelegate Creates a COM object.

  Enumeration Description
Public enumeration AssemblyRegistrationFlags Defines a set of flags used when registering assemblies.
Public enumeration CALLCONV Obsolete. Use System.Runtime.InteropServices.ComTypes.CALLCONV instead.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps CallingConvention Specifies the calling convention required to call methods implemented in unmanaged code.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps CharSet Dictates which character set marshaled strings should use.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps ClassInterfaceType Identifies the type of class interface that is generated for a class.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps ComInterfaceType Identifies how to expose an interface to COM.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps ComMemberType Describes the type of a COM member.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps CustomQueryInterfaceMode Indicates whether the GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) method's IUnknown::QueryInterface calls can use the ICustomQueryInterface interface.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps CustomQueryInterfaceResult Provides return values for the GetInterface method.
Public enumeration DESCKIND Obsolete. Use System.Runtime.InteropServices.ComTypes.DESCKIND instead.
Public enumeration Supported in .NET for Windows Store apps DllImportSearchPath Specifies the paths that are used to search for DLLs that provide functions for platform invokes.
Public enumeration ExporterEventKind Describes the callbacks that the type library exporter makes when exporting a type library.
Public enumeration FUNCFLAGS Obsolete. Use System.Runtime.InteropServices.ComTypes.FUNCFLAGS instead.
Public enumeration FUNCKIND Obsolete. Use System.Runtime.InteropServices.ComTypes.FUNCKIND instead.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps GCHandleType Represents the types of handles the GCHandle class can allocate.
Public enumeration IDispatchImplType Obsolete. Indicates which IDispatch implementation to use for a particular class.
Public enumeration IDLFLAG Obsolete. Use System.Runtime.InteropServices.ComTypes.IDLFLAG instead.
Public enumeration IMPLTYPEFLAGS Obsolete. Use System.Runtime.InteropServices.ComTypes.IMPLTYPEFLAGS instead.
Public enumeration ImporterEventKind Describes the callbacks that the type library importer makes when importing a type library.
Public enumeration INVOKEKIND Obsolete. Use System.Runtime.InteropServices.ComTypes.INVOKEKIND instead.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps LayoutKind Controls the layout of an object when exported to unmanaged code.
Public enumeration LIBFLAGS Obsolete. Use System.Runtime.InteropServices.ComTypes.LIBFLAGS instead.
Public enumeration PARAMFLAG Obsolete. Use System.Runtime.InteropServices.ComTypes.PARAMFLAG instead.
Public enumeration RegistrationClassContext Specifies the set of execution contexts in which a class object will be made available for requests to construct instances.
Public enumeration RegistrationConnectionType Defines the types of connections to a class object.
Public enumeration SYSKIND Obsolete. Use System.Runtime.InteropServices.ComTypes.SYSKIND instead.
Public enumeration TYPEFLAGS Obsolete. Use System.Runtime.InteropServices.ComTypes.TYPEFLAGS instead.
Public enumeration TYPEKIND Obsolete. Use System.Runtime.InteropServices.ComTypes.TYPEKIND instead.
Public enumeration TypeLibExporterFlags Indicates how a type library should be produced.
Public enumeration TypeLibFuncFlags Describes the original settings of the FUNCFLAGS in the COM type library from where this method was imported.
Public enumeration TypeLibImporterFlags Indicates how an assembly should be produced.
Public enumeration TypeLibTypeFlags Describes the original settings of the TYPEFLAGS in the COM type library from which the type was imported.
Public enumeration TypeLibVarFlags Describes the original settings of the VARFLAGS in the COM type library from which the variable was imported.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps UnmanagedType Identifies how to marshal parameters or fields to unmanaged code.
Public enumeration Supported by Portable Class Library Supported in .NET for Windows Store apps VarEnum Indicates how to marshal the array elements when an array is marshaled from managed to unmanaged code as a UnmanagedType.SafeArray.
Public enumeration VARFLAGS Obsolete. Use System.Runtime.InteropServices.ComTypes.VARFLAGS instead.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft