Click here to Skip to main content
15,884,176 members
Articles / Desktop Programming / Windows Forms

BizDraw framework for .NET

Rate me:
Please Sign up or sign in to vote.
4.80/5 (21 votes)
30 May 20075 min read 127.7K   3.2K   102  
A small framework to design and print documents containing shapes, text, images, bar codes...
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace BizDraw.Interop
{
    public class ComRegistration
    {
        public static void RegisterControl(Type t)
        {
            // Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
            string key = @"CLSID\" + t.GUID.ToString("B");

            // Open the CLSID\{guid} key for write access
            RegistryKey k = Registry.ClassesRoot.OpenSubKey(key, true);
            if (k == null)
                k = Registry.ClassesRoot.CreateSubKey(key);
            if (k == null) return;

            // And create the 'Control' key - this allows it to show up in 
            // the ActiveX control container 
            RegistryKey ctrl = k.CreateSubKey("Control");
            if (ctrl !=null)
                ctrl.Close();

            RegistryKey misc = k.CreateSubKey("MiscStatus");
            if (misc != null)
            {
                misc.SetValue("", "131457", RegistryValueKind.String);
                misc.Close();
            }

            RegistryKey typelibkey = k.CreateSubKey("TypeLib");
            if (typelibkey != null)
            {
                Guid libId = System.Runtime.InteropServices.Marshal.GetTypeLibGuidForAssembly(t.Assembly);
                typelibkey.SetValue("", libId.ToString("B"), RegistryValueKind.String);
                typelibkey.Close();
            }

            RegistryKey versionkey = k.CreateSubKey("Version");
            if (versionkey != null)
            {
                int major;
                int minor;

                System.Runtime.InteropServices.Marshal.GetTypeLibVersionForAssembly(t.Assembly, out major, out minor);

                versionkey.SetValue("", String.Format("{0}.{1}", major, minor));
                versionkey.Close();
            }
            //RegistryKey toolBoxKey = k.CreateSubKey("ToolBoxBitmap32");
            //toolBoxKey.SetValue("", t.Assembly.Location + "\\app.ico");
            //toolBoxKey.Close();

            // Next create the CodeBase entry - needed if not string named and GACced.
            RegistryKey inprocServer32 = k.CreateSubKey ("InprocServer32");
            if (inprocServer32 != null)
            {
                inprocServer32.SetValue("CodeBase", t.Assembly.CodeBase);
                inprocServer32.Close();
            }
            // Finally close the main key
            k.Close();
        }
        public static void UnRegisterControl(Type t)
        {
            string key = @"CLSID\" + t.GUID.ToString("B");

            Registry.ClassesRoot.DeleteSubKeyTree(key);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
France France
MCSD Asp.Net certified developer

Comments and Discussions