public static void RunComServer(IEnumerable <Type> comObjectTypes)
        {
            if (comObjectTypes == null)
            {
                throw new ArgumentNullException(nameof(comObjectTypes));
            }

            RegistrationServices services            = new RegistrationServices();
            List <int>           registrationCookies = new List <int>();

            try
            {
                foreach (var type in comObjectTypes)
                {
                    if (!type.IsSubclassOf(typeof(OutOfProcessComObject)))
                    {
                        throw new ArgumentException($"Out-of-process COM type {type.FullName} must subclass {nameof(OutOfProcessComObject)}.");
                    }

                    int cookie = services.RegisterTypeForComClients(type, RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse);
                    registrationCookies.Add(cookie);
                }

                ServerRunning = true;
                Application.Run();
            }
            finally
            {
                ServerRunning = false;
                foreach (var cookie in registrationCookies)
                {
                    services.UnregisterTypeForComClients(cookie);
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            const int UpgradedVersion = 49;  // increment every release

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
#if DEBUG
            MessageBox.Show("Debug me", "DigiRite.exe");
#endif
            int settingsVersion = Properties.Settings.Default.SavedVersion;
            if (settingsVersion < UpgradedVersion)
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.SavedVersion = UpgradedVersion;
            }
            CustomColors.CommonBackgroundColor = Properties.Settings.Default.Background;
            CustomColors.TxBackgroundColor     = Properties.Settings.Default.TxBackground;
            if ((args.Length >= 1) && args[0].ToUpper() == "-EMBEDDING")
            {
                var regServices = new RegistrationServices();
                int cookie      = regServices.RegisterTypeForComClients(
                    typeof(Ft8Auto),
                    RegistrationClassContext.LocalServer,
                    RegistrationConnectionType.SingleUse);
                applicationContext = new NoShowFormAppContext();
                Application.Run(applicationContext);
                regServices.UnregisterTypeForComClients(cookie);
            }
            else
            {
                Application.Run(new MainForm(1));
            }
        }
 public static void Uninitialize()
 {
     if (cookie != -1 && regService != null)
     {
         regService.UnregisterTypeForComClients(cookie);
     }
 }
Beispiel #4
0
        static void RunComServer()
        {
            Console.WriteLine("Starting Service");
            try
            {
                _cookie = _reg_services.RegisterTypeForComClients(
                    typeof(COMService),
                    RegistrationClassContext.LocalServer,
                    RegistrationConnectionType.MultipleUse);

                // Remove SD to simulate a more privileged process.
                RawSecurityDescriptor sd = new RawSecurityDescriptor("D:");
                byte[] sd_bytes          = new byte[sd.BinaryLength];
                sd.GetBinaryForm(sd_bytes, 0);
                if (!SetKernelObjectSecurity(new IntPtr(-1), DACL_SECURITY_INFORMATION, sd_bytes))
                {
                    throw new Win32Exception();
                }

                Console.WriteLine("Registered COM Class {0}", typeof(COMService).GUID);
                Console.ReadLine();
                _reg_services.UnregisterTypeForComClients(_cookie);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
            }
        }
Beispiel #5
0
 public static void Unregist()
 {
     if (ComObject.cookie != -1)
     {
         RegistrationServices registrationServices = new RegistrationServices();
         registrationServices.UnregisterTypeForComClients(ComObject.cookie);
     }
 }
Beispiel #6
0
 public static void Uninitialize()
 {
     if (cookie != -1)
     {
         regService?.UnregisterTypeForComClients(cookie);
     }
     UnregisterAppForNotificationSupport();
 }
Beispiel #7
0
        private static void UnregisterActivator()
        {
            if (cookie == null)
            {
                return;
            }
            RegistrationServices regService = new RegistrationServices();

            regService.UnregisterTypeForComClients((int)cookie);
            cookie = null;
        }
 public static void Disable()
 {
     if (RegistrationServices == null || Cookie == COOKIE_NONE)
     {
         return;
     }
     try
     {
         RegistrationServices.UnregisterTypeForComClients(Cookie);
     }
     finally
     {
         RegistrationServices = null;
         Cookie = COOKIE_NONE;
     }
 }