internal static UCOMITypeLib DoExportAndRegister(Assembly asm, String strTypeLibName) { // Create the TypeLibConverter. ITypeLibConverter TLBConv = new TypeLibConverter(); // Convert the assembly. ExporterCallback callback = new ExporterCallback(); UCOMITypeLib Tlb = (UCOMITypeLib)TLBConv.ConvertAssemblyToTypeLib(asm, strTypeLibName, s_Options.m_Flags, callback); // Persist the typelib. try { UCOMICreateITypeLib CreateTlb = (UCOMICreateITypeLib)Tlb; CreateTlb.SaveAllChanges(); } catch (Exception e) { ThrowAppException(Resource.FormatString("Err_TypelibSaveFailed"), e); } // Register the typelib. try { RegisterTypeLib(Tlb, strTypeLibName, Path.GetDirectoryName(strTypeLibName)); } catch (Exception e) { ThrowAppException(Resource.FormatString("Err_TypelibRegisterFailed"), e); } return(Tlb); }
/// <summary> /// Helper method - exports a type library for an assembly. Returns true if succeeded. /// </summary> private bool ExportTypeLib(Assembly asm, string typeLibFileName) { _typeLibExportFailed = false; ITypeLib convertedTypeLib = null; try { // Create a converter and run the conversion ITypeLibConverter tlbConverter = new TypeLibConverter(); convertedTypeLib = (ITypeLib)tlbConverter.ConvertAssemblyToTypeLib(asm, typeLibFileName, 0, this); if (convertedTypeLib == null || _typeLibExportFailed) { return(false); } // Persist the type library UCOMICreateITypeLib createTypeLib = (UCOMICreateITypeLib)convertedTypeLib; createTypeLib.SaveAllChanges(); } finally { if (convertedTypeLib != null) { Marshal.ReleaseComObject((ITypeLib)convertedTypeLib); } } return(!_typeLibExportFailed); }
public static void Main() { Assembly asm = Assembly.LoadFrom("MyAssembly.dll"); TypeLibConverter converter = new TypeLibConverter(); ConversionEventHandler eventHandler = new ConversionEventHandler(); UCOMICreateITypeLib typeLib = (UCOMICreateITypeLib)converter.ConvertAssemblyToTypeLib(asm, "MyTypeLib.dll", 0, eventHandler); typeLib.SaveAllChanges(); }
internal static UCOMITypeLib GenerateTypeLib(Assembly asm, ref String strTlbName) { ITypeLibConverter tlbConv = new TypeLibConverter(); ExporterCallback callback = new ExporterCallback(); UCOMITypeLib tlb = (UCOMITypeLib)tlbConv.ConvertAssemblyToTypeLib(asm, strTlbName, 0, callback); // Persist the typelib. UCOMICreateITypeLib createTlb = (UCOMICreateITypeLib)tlb; createTlb.SaveAllChanges(); return(tlb); }
public static UCOMITypeLib DoExport(Assembly asm, String strTypeLibName) { // Create the TypeLibConverter. ITypeLibConverter TLBConv = new TypeLibConverter(); // Convert the assembly. ExporterCallback callback = new ExporterCallback(); UCOMITypeLib Tlb = (UCOMITypeLib)TLBConv.ConvertAssemblyToTypeLib(asm, strTypeLibName, 0, callback); // Persist the typelib. try { UCOMICreateITypeLib CreateTlb = (UCOMICreateITypeLib)Tlb; CreateTlb.SaveAllChanges(); } catch (Exception e) { ThrowAppException(Resource.FormatString("Err_ErrorSavingTypeLib"), e); } return(Tlb); }