DispatchWrapper Class
Collapse the table of content
Expand the table of content

DispatchWrapper Class


Wraps objects the marshaler should marshal as a VT_DISPATCH.

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)


public sealed class DispatchWrapper


Initializes a new instance of the DispatchWrapper class with the object being wrapped.


Gets the object wrapped by the DispatchWrapper.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

Use to wrap objects the marshaler should marshal as a VT_DISPATCH. This wrapper will force objects to be marshaled out as VT_DISPATCH. If the object does not support IDispatch then an exception will be thrown.

using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;

public class App
	private enum RegKind
		RegKind_Default = 0,
		RegKind_Register = 1,
		RegKind_None = 2

	[ DllImport( "oleaut32.dll", CharSet = CharSet.Unicode, PreserveSig = false )]
	private static extern void LoadTypeLibEx( String strTypeLibName, RegKind regKind, 
		[ MarshalAs( UnmanagedType.Interface )] out Object typeLib );

	public static void Main()
		Object typeLib;
		LoadTypeLibEx( "SHDocVw.dll", RegKind.RegKind_None, out typeLib ); 

		if( typeLib == null )
			Console.WriteLine( "LoadTypeLibEx failed." );

		TypeLibConverter converter = new TypeLibConverter();
		ConversionEventHandler eventHandler = new ConversionEventHandler();
		AssemblyBuilder asm = converter.ConvertTypeLibToAssembly( typeLib, "ExplorerLib.dll", 0, eventHandler, null, null, null, null );	
		asm.Save( "ExplorerLib.dll" );

public class ConversionEventHandler : ITypeLibImporterNotifySink
	public void ReportEvent( ImporterEventKind eventKind, int eventCode, string eventMsg )
		// handle warning event here...

	public Assembly ResolveRef( object typeLib )
		// resolve reference here and return a correct assembly...
		return null; 

For more information on VT_DISPATCH, please see the existing documentation for VARENUM::VT_DISPATCH in the MSDN library.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2015 Microsoft