Beispiel #1
0
        public static void UnregisterControl(Type t)
        {
            try
            {
                if (t == null)
                {
                    throw new ArgumentNullException(nameof(t));
                }

                if (!typeof(Control).IsAssignableFrom(t))
                {
                    throw new ArgumentException("Type argument must be a Windows Forms control.");
                }

                // CLSID
                string key = $"CLSID\\{t.GUID:B}";
                Registry.ClassesRoot.DeleteSubKeyTree(key);
                EventLogWrapper.Log($"Control unregistered for {Bitness} applications: {t.FullName}, {key}",
                                    EventLogEntryType.Information, 200);
            }
            catch (Exception ex)
            {
                EventLogWrapper.Log($"Control was not unregistered: {t.FullName}\n{ex}", EventLogEntryType.Error, 500);
            }
        }
        private static void ConfigureLogging()
        {
            LoggerProvider.Instance.Level = SourceLevels.Information;
            LoggerProvider.Instance.FileLoggingEnabled = true;
            string outputFile = Path.GetFullPath("dotnetbrowser.log");

            LoggerProvider.Instance.OutputFile = outputFile;
            EventLogWrapper.Log($"DotNetBrowser logs can be found at {outputFile}", EventLogEntryType.Information, 202);
        }
 public ComBrowserView()
 {
     try
     {
         ConfigureLogging();
         InitializeComponent();
         _engineWrapper = new EngineWrapper();
         _engineWrapper.Initialize();
         Browser = _engineWrapper.CreateBrowser();
         InitializeFrom(Browser);
         Browser.LoadUrl("teamdev.com/dotnetbrowser");
         EventLogWrapper.Log("ComBrowserView initialized", EventLogEntryType.Information, 201);
     }
     catch (Exception e)
     {
         EventLogWrapper.Log(e.ToString(), EventLogEntryType.Error, 500);
         throw;
     }
 }
Beispiel #4
0
        public static void RegisterControl(Type t, int iconResourceIndex = 101)
        {
            try
            {
                if (t == null)
                {
                    throw new ArgumentNullException(nameof(t));
                }

                if (!typeof(Control).IsAssignableFrom(t))
                {
                    throw new ArgumentException("Type argument must be a Windows Forms control.");
                }


                string key = $"CLSID\\{t.GUID:B}";

                using (RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(key, true))
                {
                    // InprocServer32

                    using (RegistryKey inprocServerKey = registryKey?.OpenSubKey("InprocServer32", true))
                    {
                        //Override the default value - to make sure that the applications will be able to locate the DLL
                        inprocServerKey?.SetValue(null, $@"{Environment.SystemDirectory}\mscoree.dll");
                        // Create the CodeBase entry - needed if not string named and GACced.
                        inprocServerKey?.SetValue("CodeBase", t.Assembly.CodeBase);
                    }

                    // Control
                    // Create the 'Control' key - this allows our control to show up in
                    // the ActiveX control container
                    RegistryKey controlKey = registryKey?.CreateSubKey("Control");
                    controlKey?.Close();

                    // MiscStatus
                    using (RegistryKey miscKey = registryKey?.CreateSubKey("MiscStatus"))
                    {
                        const int miscStatusValue = OLEMISC_RECOMPOSEONRESIZE
                                                    + OLEMISC_CANTLINKINSIDE
                                                    + OLEMISC_INSIDEOUT
                                                    + OLEMISC_ACTIVATEWHENVISIBLE
                                                    + OLEMISC_SETCLIENTSITEFIRST;

                        miscKey?.SetValue("", miscStatusValue.ToString(), RegistryValueKind.String);
                    }

                    // ToolBoxBitmap32
                    using (RegistryKey bitmapKey = registryKey?.CreateSubKey("ToolboxBitmap32"))
                    {
                        bitmapKey?.SetValue("", $"{t.Assembly.Location}, {iconResourceIndex}",
                                            RegistryValueKind.String);
                    }

                    // TypeLib
                    using (RegistryKey typeLibKey = registryKey?.CreateSubKey("TypeLib"))
                    {
                        Guid libId = Marshal.GetTypeLibGuidForAssembly(t.Assembly);
                        typeLibKey?.SetValue("", libId.ToString("B"), RegistryValueKind.String);
                    }

                    // Version
                    using (RegistryKey versionKey = registryKey?.CreateSubKey("Version"))
                    {
                        int major, minor;
                        Marshal.GetTypeLibVersionForAssembly(t.Assembly, out major, out minor);
                        versionKey?.SetValue("", $"{major}.{minor}");
                    }
                }

                EventLogWrapper.Log($"Control registered for {Bitness} applications: {t.FullName}, {key}",
                                    EventLogEntryType.Information, 200);
            }
            catch (Exception ex)
            {
                EventLogWrapper.Log($"Control was not registered: {t.FullName}\n{ex}", EventLogEntryType.Error, 500);
            }
        }
 void IComBrowserView.Dispose()
 {
     _engineWrapper.Dispose();
     EventLogWrapper.Log("ComBrowserView disposed", EventLogEntryType.Information, 201);
 }