Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
    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();
    }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }