Sdílet prostřednictvím


Customizing Standard Wrappers

This topic describes the processes you use to customize standard runtime callable wrappers and COM callable wrappers.

Runtime Callable Wrappers

When a .NET client activates a COM object, the runtime generates an instance of the runtime callable wrapper (RCW) to wrap the COM type. As the following illustration shows, the runtime uses metadata obtained from an imported COM type library to generate the RCW. The wrapper marshals data according to the rules established by the interop marshaling service.

RCW generation and method calls

Customizing standard wrappers

There are two ways to customize an RCW. If you can modify the Interface Definition Language (IDL) source, you can apply type library file (TLB) attributes and import the type library. Alternatively, you can apply interop-specific attributes to imported types and generate a new assembly. Support for customizing standard RCWs is limited by these attributes. For instructions, see How to: Customize Runtime Callable Wrappers.

COM Callable Wrappers

A COM callable wrapper (CCW) exposes .NET Framework objects to COM. By compiling a managed project into an assembly DLL, you automatically create the metadata required to describe each type in the assembly. The runtime uses this metadata to generate a CCW whenever a COM client activates managed object.

To customize a CCW, apply interop-specific attributes to your managed source code and compile the source into an assembly, as shown in the following illustration. In this example, Tlbexp.exe converts managed types to COM.

CCW generation and method calls

Customizing standard wrappers

By applying attributes to your code, you can alter interface and data marshaling behavior within the confines of the interop marshaling service. For example, you can control the format of the data passed as an argument to a method. You can also control which types in an assembly are exposed to COM.

See Also

Tasks

How to: Customize Runtime Callable Wrappers

Reference

Tlbimp.exe (Type Library Importer)

Ildasm.exe (MSIL Disassembler)

Concepts

COM Wrappers

Runtime Callable Wrapper

COM Callable Wrapper

Applying Interop Attributes

Other Resources

Type Library to Assembly Conversion Summary

Assembly to Type Library Conversion Summary