Export (0) Print
Expand All

TypeLibConverter.ConvertTypeLibToAssembly Method

Converts a COM type library to an assembly.

Overload List

Converts a COM type library to an assembly.

[Visual Basic] Overloads Public Overridable Function ConvertTypeLibToAssembly(Object, String, Integer, ITypeLibImporterNotifySink, Byte(), StrongNameKeyPair, Boolean) As AssemblyBuilder Implements ITypeLibConverter.ConvertTypeLibToAssembly
[C#] public virtual AssemblyBuilder ConvertTypeLibToAssembly(object, string, int, ITypeLibImporterNotifySink, byte[], StrongNameKeyPair, bool);
[C++] public: virtual AssemblyBuilder* ConvertTypeLibToAssembly(Object*, String*, int, ITypeLibImporterNotifySink*, unsigned char __gc[], StrongNameKeyPair*, bool);
[JScript] public function ConvertTypeLibToAssembly(Object, String, int, ITypeLibImporterNotifySink, Byte[], StrongNameKeyPair, Boolean) : AssemblyBuilder;

Converts a COM type library to an assembly.

[Visual Basic] Overloads Public Overridable Function ConvertTypeLibToAssembly(Object, String, TypeLibImporterFlags, ITypeLibImporterNotifySink, Byte(), StrongNameKeyPair, String, Version) As AssemblyBuilder Implements ITypeLibConverter.ConvertTypeLibToAssembly
[C#] public virtual AssemblyBuilder ConvertTypeLibToAssembly(object, string, TypeLibImporterFlags, ITypeLibImporterNotifySink, byte[], StrongNameKeyPair, string, Version);
[C++] public: virtual AssemblyBuilder* ConvertTypeLibToAssembly(Object*, String*, TypeLibImporterFlags, ITypeLibImporterNotifySink*, unsigned char __gc[], StrongNameKeyPair*, String*, Version*);
[JScript] public function ConvertTypeLibToAssembly(Object, String, TypeLibImporterFlags, ITypeLibImporterNotifySink, Byte[], StrongNameKeyPair, String, Version) : AssemblyBuilder;

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of ConvertTypeLibToAssembly. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Runtime.InteropServices

Public Class App
    Private Enum RegKind
        RegKind_Default = 0
        RegKind_Register = 1
        RegKind_None = 2
    End Enum 'RegKind

    <DllImport("oleaut32.dll", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
    Private Shared Sub LoadTypeLibEx(ByVal strTypeLibName As [String], ByVal regKind As RegKind, <MarshalAs(UnmanagedType.Interface)> ByRef typeLib As [Object])
    End Sub

    Public Shared Sub Main()
        Dim typeLib As [Object]
        LoadTypeLibEx("SHDocVw.dll", RegKind.RegKind_None, typeLib)

        If typeLib Is Nothing Then
            Console.WriteLine("LoadTypeLibEx failed.")
            Return
        End If

        Dim converter As New TypeLibConverter()
        Dim eventHandler As New ConversionEventHandler()
        Dim asm As AssemblyBuilder = converter.ConvertTypeLibToAssembly(typeLib, "ExplorerLib.dll", 0, eventHandler, Nothing, Nothing, Nothing, Nothing)
        asm.Save("ExplorerLib.dll")
    End Sub 'Main
End Class 'App
 _

Public Class ConversionEventHandler
    Implements ITypeLibImporterNotifySink

    Public Sub ReportEvent(ByVal eventKind As ImporterEventKind, ByVal eventCode As Integer, ByVal eventMsg As String) Implements ITypeLibImporterNotifySink.ReportEvent
        ' handle warning event here...
    End Sub 'ReportEvent

    Public Function ResolveRef(ByVal typeLib As Object) As [Assembly] Implements ITypeLibImporterNotifySink.ResolveRef
        ' resolve reference here and return a correct assembly...
        Return Nothing
    End Function 'ResolveRef
End Class 'ConversionEventHandler

[C#] 
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." );
            return;
        }
            
        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; 
    }    
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
using namespace System::Runtime::InteropServices;

typedef enum tagREGKIND
{
   REGKIND_DEFAULT,
   REGKIND_REGISTER,
   REGKIND_NONE
} REGKIND;

__gc class ConversionEventHandler : public ITypeLibImporterNotifySink {
public:
   void ReportEvent(ImporterEventKind eventKind, int eventCode, String* eventMsg) {
      // handle warning event here...
   }

   Assembly* ResolveRef(Object* typeLib) {
      // resolve reference here and return a correct assembly...
      return 0;
   }
};

[ DllImport(S"oleaut32.dll", CharSet = CharSet::Unicode, PreserveSig = false)]
extern void LoadTypeLibEx(String *strTypeLibName,
                          REGKIND regkind,
                          [MarshalAs(UnmanagedType::Interface)] [out] Object ** typeLib); 

int main() {

   Object* typeLib = new Object();

   LoadTypeLibEx(S"SHDocVw.dll", REGKIND_NONE,  & typeLib);  

   if (typeLib == 0) {
      Console::WriteLine(S"LoadTypeLibEx failed.");
      return 0;
   }

   TypeLibConverter* converter = new TypeLibConverter();
   ConversionEventHandler* eventHandler = new ConversionEventHandler();
   AssemblyBuilder*  asmb = 
      converter->ConvertTypeLibToAssembly(
         typeLib,
         S"ExplorerLib.dll",
         (System::Runtime::InteropServices::TypeLibImporterFlags)0,
         eventHandler, 0, 0, 0, 0);
   asmb->Save(S"ExplorerLib.dll");
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

TypeLibConverter Class | TypeLibConverter Members | System.Runtime.InteropServices Namespace

Show:
© 2014 Microsoft