Example #1
0
        /// <summary>
        /// This method creates (and saves) a COM type library given a .NET 
        /// assembly.
        /// </summary>
        public static UCOMITypeLib GenerateTLBFromAsm(string pathToAssmebly)
        {
            UCOMITypeLib managedITypeLib = null;
            ExporterNotiferSink sink = new ExporterNotiferSink();

            // Load the assembly to convert.
            Assembly asm = Assembly.LoadFrom(pathToAssmebly);
            if (asm != null)
            {
                try
                {
                    // Create name of type library based on .NET assembly.
                    string tlbname = asm.GetName().Name + ".tlb";

                    // Convert the assembly.
                    ITypeLibConverter TLBConv = new TypeLibConverter();
                    managedITypeLib = (UCOMITypeLib)TLBConv.ConvertAssemblyToTypeLib(asm, tlbname, 0, sink);
                    try
                    {
                        UCOMICreateTypeLib managedICreateITypeLib = (UCOMICreateTypeLib)managedITypeLib;
                        managedICreateITypeLib.SaveAllChanges();
                    }
                    catch (COMException e)
                    {
                        throw new Exception("Error saving the typeLib : "
                            + e.ErrorCode.ToString("x"));
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Error Converting assembly" + e);
                }
            }
            return managedITypeLib;
        }
Example #2
0
        /// <summary>
        /// This method creates (and saves) a COM type library given a .NET
        /// assembly.
        /// </summary>
        public static UCOMITypeLib GenerateTLBFromAsm(string pathToAssmebly)
        {
            UCOMITypeLib        managedITypeLib = null;
            ExporterNotiferSink sink            = new ExporterNotiferSink();

            // Load the assembly to convert.
            Assembly asm = Assembly.LoadFrom(pathToAssmebly);

            if (asm != null)
            {
                try
                {
                    // Create name of type library based on .NET assembly.
                    string tlbname = asm.GetName().Name + ".tlb";

                    // Convert the assembly.
                    ITypeLibConverter TLBConv = new TypeLibConverter();
                    managedITypeLib = (UCOMITypeLib)TLBConv.ConvertAssemblyToTypeLib(asm, tlbname, 0, sink);
                    try
                    {
                        UCOMICreateTypeLib managedICreateITypeLib = (UCOMICreateTypeLib)managedITypeLib;
                        managedICreateITypeLib.SaveAllChanges();
                    }
                    catch (COMException e)
                    {
                        throw new Exception("Error saving the typeLib : "
                                            + e.ErrorCode.ToString("x"));
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Error Converting assembly" + e);
                }
            }
            return(managedITypeLib);
        }