Customizing Runtime Callable Wrappers
The common language runtime produces a runtime callable wrapper (RCW) from the metadata in an interop assembly. Unlike other assemblies, interop assemblies are generated by importing type libraries. Although the import process generally produces accurate interop assemblies, there are cases when you can (or must) modify the interop assembly to produce a custom RCW.
There are several reasons why you might customize an RCW, such as:
One or more types require additional marshaling information.
A type library contains many specialized types that are unrecognizable to the marshaler.
A large type library can include types that are unnecessary for an application. You can eliminate the need to deploy unnecessary types by creating an interop assembly from managed source code.
Having RCW source code that contains a portion of the types in a large type library can eliminate the need to deploy unnecessary types.
As the following illustration shows, you can import a type library as a managed DLL without customizing the wrapper (shown on the left). Or you can create a custom wrapper.
Marshaling information in imported type libraries
If you must customize the runtime callable wrapper with additional or different marshaling instructions, you have two choices:
Edit the interop assembly, searching for problematic syntax and replacing it with alternative syntax. This option is best for minor marshaling changes.
Create a wrapper manually, based on an existing Interface Definition Language (IDL) file or type library. Declaring COM types manually is a difficult activity that requires working knowledge of the Type Library Importer (Tlbimp.exe), the default behavior of the interop marshaler, and COM. This approach is best used when you have an entire library of specialized types or require the RCW source code.
How to: Edit Interop Assemblies
How to: Create Wrappers Manually
Customizing COM Callable Wrappers