Export (0) Print
Expand All
Expand Minimize

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.

  ClassDescription
Public classAllowReversePInvokeCallsAttributeAllows an unmanaged method to call a managed method.
Public classAutomationProxyAttributeSpecifies whether the type should be marshaled using the Automation marshaler or a custom proxy and stub.
Public classBestFitMappingAttributeControls whether Unicode characters are converted to the closest matching ANSI characters.
Public classBStrWrapperMarshals data of type VT_BSTR from managed to unmanaged code. This class cannot be inherited.
Public classClassInterfaceAttributeIndicates the type of class interface to be generated for a class exposed to COM, if an interface is generated at all.
Public classCoClassAttributeSpecifies the class identifier of a coclass imported from a type library.
Public classComAliasNameAttributeIndicates the COM alias for a parameter or field type.
Public classComAwareEventInfoPermits late-bound registration of an event handler.
Public classComCompatibleVersionAttributeIndicates 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 classComConversionLossAttributeIndicates that information was lost about a class or interface when it was imported from a type library to an assembly.
Public classComDefaultInterfaceAttributeSpecifies a default interface to expose to COM. This class cannot be inherited.
Public classComEventInterfaceAttributeIdentifies 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 classComEventsHelperProvides methods that enable .NET Framework delegates that handle events to be added and removed from COM objects.
Public classCOMExceptionThe exception that is thrown when an unrecognized HRESULT is returned from a COM method call.
Public classComImportAttributeIndicates that the attributed type was previously defined in COM.
Public classComRegisterFunctionAttributeSpecifies 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 classComSourceInterfacesAttributeIdentifies a list of interfaces that are exposed as COM event sources for the attributed class.
Public classComUnregisterFunctionAttributeSpecifies 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 classComVisibleAttributeControls accessibility of an individual managed type or member, or of all types within an assembly, to COM.
Public classCriticalHandleRepresents a wrapper class for handle resources.
Public classCurrencyWrapperWraps objects the marshaler should marshal as a VT_CY.
Public classDefaultCharSetAttributeSpecifies the value of the CharSet enumeration. This class cannot be inherited.
Public classDefaultParameterValueAttributeSets the default value of a parameter when called from a language that supports default parameters. This class cannot be inherited.
Public classDispatchWrapperWraps objects the marshaler should marshal as a VT_DISPATCH.
Public classDispIdAttributeSpecifies the COM dispatch identifier (DISPID) of a method, field, or property.
Public classDllImportAttributeIndicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point.
Public classErrorWrapperWraps objects the marshaler should marshal as a VT_ERROR.
Public classExtensibleClassFactoryEnables customization of managed objects that extend from unmanaged objects during creation.
Public classExternalExceptionThe base exception type for all COM interop exceptions and structured exception handling (SEH) exceptions.
Public classFieldOffsetAttributeIndicates the physical position of fields within the unmanaged representation of a class or structure.
Public classGuidAttributeSupplies an explicit System.Guid when an automatic GUID is undesirable.
Public classHandleCollectorTracks outstanding handles and forces a garbage collection when the specified threshold is reached.
Public classIDispatchImplAttribute Obsolete. Indicates which IDispatch implementation the common language runtime uses when exposing dual interfaces and dispinterfaces to COM.
Public classImportedFromTypeLibAttributeIndicates that the types defined within an assembly were originally defined in a type library.
Public classInAttributeIndicates that data should be marshaled from the caller to the callee, but not back to the caller.
Public classInterfaceTypeAttributeIndicates whether a managed interface is dual, dispatch-only, or IUnknown -only when exposed to COM.
Public classInvalidComObjectExceptionThe exception thrown when an invalid COM object is used.
Public classInvalidOleVariantTypeExceptionThe exception thrown by the marshaler when it encounters an argument of a variant type that can not be marshaled to managed code.
Public classLCIDConversionAttributeIndicates that a method's unmanaged signature expects a locale identifier (LCID) parameter.
Public classManagedToNativeComInteropStubAttributeProvides support for user customization of interop stubs in managed-to-COM interop scenarios.
Public classMarshalProvides 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 classMarshalAsAttributeIndicates how to marshal the data between managed and unmanaged code.
Public classMarshalDirectiveExceptionThe exception that is thrown by the marshaler when it encounters a MarshalAsAttribute it does not support.
Public classOptionalAttributeIndicates that a parameter is optional.
Public classOutAttributeIndicates that data should be marshaled from callee back to caller.
Public classPreserveSigAttributeIndicates that the HRESULT or retval signature transformation that takes place during COM interop calls should be suppressed.
Public classPrimaryInteropAssemblyAttributeIndicates that the attributed assembly is a primary interop assembly.
Public classProgIdAttributeAllows the user to specify the ProgID of a class.
Public classRegistrationServicesProvides a set of services for registering and unregistering managed assemblies for use from COM.
Public classRuntimeEnvironmentProvides a collection of static methods that return information about the common language runtime environment.
Public classSafeArrayRankMismatchExceptionThe exception thrown when the rank of an incoming SAFEARRAY does not match the rank specified in the managed signature.
Public classSafeArrayTypeMismatchExceptionThe exception thrown when the type of the incoming SAFEARRAY does not match the type specified in the managed signature.
Public classSafeBufferProvides 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 classSafeHandleRepresents a wrapper class for operating system handles. This class must be inherited.
Public classSEHExceptionRepresents structured exception handling (SEH) errors.
Public classSetWin32ContextInIDispatchAttribute Obsolete. This attribute has been deprecated.
Public classStandardOleMarshalObjectReplaces the standard common language runtime (CLR) free-threaded marshaler with the standard OLE STA marshaler.
Public classStructLayoutAttributeLets you control the physical layout of the data fields of a class or structure.
Public classTypeIdentifierAttributeProvides support for type equivalence.
Public classTypeLibConverterProvides a set of services that convert a managed assembly to a COM type library and vice versa.
Public classTypeLibFuncAttributeContains the FUNCFLAGS that were originally imported for this method from the COM type library.
Public classTypeLibImportClassAttributeSpecifies which Type exclusively uses an interface. This class cannot be inherited.
Public classTypeLibTypeAttributeContains the TYPEFLAGS that were originally imported for this type from the COM type library.
Public classTypeLibVarAttributeContains the VARFLAGS that were originally imported for this field from the COM type library.
Public classTypeLibVersionAttributeSpecifies the version number of an exported type library.
Public classUnknownWrapperWraps objects the marshaler should marshal as a VT_UNKNOWN.
Public classUnmanagedFunctionPointerAttributeControls the marshaling behavior of a delegate signature passed as an unmanaged function pointer to or from unmanaged code. This class cannot be inherited.
Public classVariantWrapperMarshals data of type VT_VARIANT | VT_BYREF from managed to unmanaged code. This class cannot be inherited.

  StructureDescription
Public structureArrayWithOffsetEncapsulates an array and an offset within the specified array.
Public structureBIND_OPTS Obsolete. Use System.Runtime.InteropServices.ComTypes.BIND_OPTS instead.
Public structureBINDPTR Obsolete. Use System.Runtime.InteropServices.ComTypes.BINDPTR instead.
Public structureCONNECTDATA Obsolete. Use System.Runtime.InteropServices.ComTypes.CONNECTDATA instead.
Public structureDISPPARAMS Obsolete. Use System.Runtime.InteropServices.ComTypes.DISPPARAMS instead.
Public structureELEMDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.ELEMDESC instead.
Public structureELEMDESC.DESCUNIONUse System.Runtime.InteropServices.ComTypes.ELEMDESC.DESCUNION instead.
Public structureEXCEPINFO Obsolete. Use System.Runtime.InteropServices.ComTypes.EXCEPINFO instead.
Public structureFILETIME Obsolete. Use System.Runtime.InteropServices.ComTypes.FILETIME instead.
Public structureFUNCDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.FUNCDESC instead.
Public structureGCHandleProvides a way to access a managed object from unmanaged memory.
Public structureHandleRefWraps a managed object holding a handle to a resource that is passed to unmanaged code using platform invoke.
Public structureIDLDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.IDLDESC instead.
Public structurePARAMDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.PARAMDESC instead.
Public structureSTATSTG Obsolete. Use System.Runtime.InteropServices.ComTypes.STATSTG instead.
Public structureTYPEATTR Obsolete. Use System.Runtime.InteropServices.ComTypes.TYPEATTR instead.
Public structureTYPEDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.TYPEDESC instead.
Public structureTYPELIBATTR Obsolete. Use System.Runtime.InteropServices.ComTypes.TYPELIBATTR instead.
Public structureVARDESC Obsolete. Use System.Runtime.InteropServices.ComTypes.VARDESC instead.
Public structureVARDESC.DESCUNIONUse System.Runtime.InteropServices.ComTypes.VARDESC.DESCUNION instead.

  InterfaceDescription
Public interface_ActivatorExposes the System.Activator class to unmanaged code.
Public interface_AssemblyExposes the public members of the System.Reflection.Assembly class to unmanaged code.
Public interface_AssemblyBuilderExposes the System.Reflection.Emit.AssemblyBuilder class to unmanaged code.
Public interface_AssemblyNameExposes the AssemblyName class to unmanaged code.
Public interface_AttributeExposes the System.Attribute class to unmanaged code.
Public interface_ConstructorBuilderExposes the System.Reflection.Emit.ConstructorBuilder class to unmanaged code.
Public interface_ConstructorInfoExposes the public members of the System.Reflection.ConstructorInfo class to unmanaged code.
Public interface_CustomAttributeBuilderExposes the System.Reflection.Emit.CustomAttributeBuilder class to unmanaged code.
Public interface_EnumBuilderExposes the System.Reflection.Emit.EnumBuilder class to unmanaged code.
Public interface_EventBuilderExposes the System.Reflection.Emit.EventBuilder class to unmanaged code.
Public interface_EventInfoExposes the public members of the System.Reflection.EventInfo class to unmanaged code.
Public interface_ExceptionExposes the public members of the System.Exception class to unmanaged code.
Public interface_FieldBuilderExposes the System.Reflection.Emit.FieldBuilder class to unmanaged code.
Public interface_FieldInfoExposes the public members of the System.Reflection.FieldInfo class to unmanaged code.
Public interface_ILGeneratorExposes the System.Reflection.Emit.ILGenerator class to unmanaged code.
Public interface_LocalBuilderExposes the System.Reflection.Emit.LocalBuilder class to unmanaged code.
Public interface_MemberInfoExposes the public members of the System.Reflection.MemberInfo class to unmanaged code.
Public interface_MethodBaseExposes the public members of the System.Reflection.MethodBase class to unmanaged code.
Public interface_MethodBuilderExposes the MethodBuilder class to unmanaged code.
Public interface_MethodInfoExposes the public members of the System.Reflection.MethodInfo class to unmanaged code.
Public interface_MethodRentalExposes the System.Reflection.Emit.MethodRental class to unmanaged code.
Public interface_ModuleExposes the Module class to unmanaged code.
Public interface_ModuleBuilderExposes the System.Reflection.Emit.ModuleBuilder class to unmanaged code.
Public interface_ParameterBuilderExposes the System.Reflection.Emit.ParameterBuilder class to unmanaged code.
Public interface_ParameterInfoExposes the System.Reflection.ParameterInfo class to unmanaged code.
Public interface_PropertyBuilderExposes the System.Reflection.Emit.PropertyBuilder class to unmanaged code.
Public interface_PropertyInfoExposes the public members of the System.Reflection.PropertyInfo class to unmanaged code.
Public interface_SignatureHelperExposes the System.Reflection.Emit.SignatureHelper class to unmanaged code.
Public interface_ThreadExposes the System.Threading.Thread class to unmanaged code.
Public interface_TypeExposes the public members of the System.Type class to the unmanaged code.
Public interface_TypeBuilderExposes the System.Reflection.Emit.TypeBuilder class to unmanaged code.
Public interfaceICustomAdapterProvides a way for clients to access the actual object, rather than the adapter object handed out by a custom marshaler.
Public interfaceICustomFactoryEnables users to write activation code for managed objects that extend MarshalByRefObject.
Public interfaceICustomMarshalerProvides custom wrappers for handling method calls.
Public interfaceICustomQueryInterfaceEnables developers to provide a custom, managed implementation of the IUnknown::QueryInterface(REFIID riid, void **ppvObject) method.
Public interfaceIRegistrationServicesProvides a set of services for registering and unregistering managed assemblies for use from COM.
Public interfaceITypeLibConverterProvides a set of services that convert a managed assembly to a COM type library and vice versa.
Public interfaceITypeLibExporterNameProviderProvides control over the casing of names when exported to a type library.
Public interfaceITypeLibExporterNotifySinkProvides 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 interfaceITypeLibImporterNotifySinkProvides 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 interfaceUCOMIBindCtx Obsolete. Use System.Runtime.InteropServices.ComTypes.BIND_OPTS instead.
Public interfaceUCOMIConnectionPoint Obsolete. Use System.Runtime.InteropServices.ComTypes.IConnectionPoint instead.
Public interfaceUCOMIConnectionPointContainer Obsolete. Use System.Runtime.InteropServices.ComTypes.IConnectionPointContainer instead.
Public interfaceUCOMIEnumConnectionPoints Obsolete. Use System.Runtime.InteropServices.ComTypes.IEnumConnectionPoints instead.
Public interfaceUCOMIEnumConnections Obsolete. Use System.Runtime.InteropServices.ComTypes.IEnumConnections instead.
Public interfaceUCOMIEnumMoniker Obsolete. Use System.Runtime.InteropServices.ComTypes.IEnumMoniker instead.
Public interfaceUCOMIEnumString Obsolete. Use System.Runtime.InteropServices.ComTypes.IEnumString instead.
Public interfaceUCOMIEnumVARIANT Obsolete. Use System.Runtime.InteropServices.ComTypes.IEnumVARIANT instead.
Public interfaceUCOMIMoniker Obsolete. Use System.Runtime.InteropServices.ComTypes.IMoniker instead.
Public interfaceUCOMIPersistFile Obsolete. Use System.Runtime.InteropServices.ComTypes.IPersistFile instead.
Public interfaceUCOMIRunningObjectTable Obsolete. Use System.Runtime.InteropServices.ComTypes.IRunningObjectTable instead.
Public interfaceUCOMIStream Obsolete. Use System.Runtime.InteropServices.ComTypes.IStream instead.
Public interfaceUCOMITypeComp Obsolete. Use System.Runtime.InteropServices.ComTypes.ITypeComp instead.
Public interfaceUCOMITypeInfo Obsolete. Use System.Runtime.InteropServices.ComTypes.ITypeInfo instead.
Public interfaceUCOMITypeLib Obsolete. Use System.Runtime.InteropServices.ComTypes.ITypeLib instead.

  DelegateDescription
Public delegateObjectCreationDelegateCreates a COM object.

  EnumerationDescription
Public enumerationAssemblyRegistrationFlagsDefines a set of flags used when registering assemblies.
Public enumerationCALLCONV Obsolete. Use System.Runtime.InteropServices.ComTypes.CALLCONV instead.
Public enumerationCallingConventionSpecifies the calling convention required to call methods implemented in unmanaged code.
Public enumerationCharSetDictates which character set marshaled strings should use.
Public enumerationClassInterfaceTypeIdentifies the type of class interface that is generated for a class.
Public enumerationComInterfaceTypeIdentifies how to expose an interface to COM.
Public enumerationComMemberTypeDescribes the type of a COM member.
Public enumerationCustomQueryInterfaceModeIndicates whether the GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) method's IUnknown::QueryInterface calls can use the ICustomQueryInterface interface.
Public enumerationCustomQueryInterfaceResultProvides return values for the GetInterface method.
Public enumerationDESCKIND Obsolete. Use System.Runtime.InteropServices.ComTypes.DESCKIND instead.
Public enumerationExporterEventKindDescribes the callbacks that the type library exporter makes when exporting a type library.
Public enumerationFUNCFLAGS Obsolete. Use System.Runtime.InteropServices.ComTypes.FUNCFLAGS instead.
Public enumerationFUNCKIND Obsolete. Use System.Runtime.InteropServices.ComTypes.FUNCKIND instead.
Public enumerationGCHandleTypeRepresents the types of handles the GCHandle class can allocate.
Public enumerationIDispatchImplType Obsolete. Indicates which IDispatch implementation to use for a particular class.
Public enumerationIDLFLAG Obsolete. Use System.Runtime.InteropServices.ComTypes.IDLFLAG instead.
Public enumerationIMPLTYPEFLAGS Obsolete. Use System.Runtime.InteropServices.ComTypes.IMPLTYPEFLAGS instead.
Public enumerationImporterEventKindDescribes the callbacks that the type library importer makes when importing a type library.
Public enumerationINVOKEKIND Obsolete. Use System.Runtime.InteropServices.ComTypes.INVOKEKIND instead.
Public enumerationLayoutKindControls the layout of an object when it is exported to unmanaged code.
Public enumerationLIBFLAGS Obsolete. Use System.Runtime.InteropServices.ComTypes.LIBFLAGS instead.
Public enumerationPARAMFLAG Obsolete. Use System.Runtime.InteropServices.ComTypes.PARAMFLAG instead.
Public enumerationRegistrationClassContextSpecifies the set of execution contexts in which a class object will be made available for requests to construct instances.
Public enumerationRegistrationConnectionTypeDefines the types of connections to a class object.
Public enumerationSYSKIND Obsolete. Use System.Runtime.InteropServices.ComTypes.SYSKIND instead.
Public enumerationTYPEFLAGS Obsolete. Use System.Runtime.InteropServices.ComTypes.TYPEFLAGS instead.
Public enumerationTYPEKIND Obsolete. Use System.Runtime.InteropServices.ComTypes.TYPEKIND instead.
Public enumerationTypeLibExporterFlagsIndicates how a type library should be produced.
Public enumerationTypeLibFuncFlagsDescribes the original settings of the FUNCFLAGS in the COM type library from where this method was imported.
Public enumerationTypeLibImporterFlagsIndicates how an assembly should be produced.
Public enumerationTypeLibTypeFlagsDescribes the original settings of the TYPEFLAGS in the COM type library from which the type was imported.
Public enumerationTypeLibVarFlagsDescribes the original settings of the VARFLAGS in the COM type library from which the variable was imported.
Public enumerationUnmanagedTypeIdentifies how to marshal parameters or fields to unmanaged code.
Public enumerationVarEnumIndicates how to marshal the array elements when an array is marshaled from managed to unmanaged code as a UnmanagedType.SafeArray.
Public enumerationVARFLAGS Obsolete. Use System.Runtime.InteropServices.ComTypes.VARFLAGS instead.

Community Additions

ADD
Show:
© 2014 Microsoft