// // Remove all traces of this from the registry. // protected static void UnregisterObjects() { if (!IsAdministrator) { ElevateSelf("/unregister"); return; } // // If reached here, we're running elevated // // Local server's DCOM/AppID information // try { Registry.ClassesRoot.DeleteSubKey("APPID\\" + m_sAppId); Registry.ClassesRoot.DeleteSubKey("APPID\\" + Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)); } catch (Exception) { } // // For each of the driver assemblies // foreach (Type type in m_ComObjectTypes) { string clsid = Marshal.GenerateGuidForType(type).ToString("B"); string progid = Marshal.GenerateProgIdForType(type); string devicetype = type.Name; // // Best efforts // // // HKCR\progid // Registry.ClassesRoot.DeleteSubKey(progid + "\\CLSID", false); Registry.ClassesRoot.DeleteSubKey(progid, false); // // HKCR\CLSID\clsid // Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\Implemented Categories\\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}", false); Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\Implemented Categories", false); Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\ProgId", false); Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\LocalServer32", false); Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\Programmable", false); Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid, false); try { // // ASCOM // using (Profile P = new Profile()) { P.DeviceType = devicetype; P.Unregister(progid); } } catch (Exception) { } } }
public void GetComponentInfo(string assemblyPath, out string numComponents, out string componentInfo) { RegistrationServices services = new RegistrationServices(); Assembly assembly = this.LoadAssembly(assemblyPath); Type[] registrableTypesInAssembly = services.GetRegistrableTypesInAssembly(assembly); int num = 0; string str = ""; foreach (Type type in registrableTypesInAssembly) { if (type.IsClass && type.IsSubclassOf(typeof(ServicedComponent))) { num++; string str2 = Marshal.GenerateGuidForType(type).ToString(); string str3 = Marshal.GenerateProgIdForType(type); if ((str2.Length == 0) || (str3.Length == 0)) { throw new COMException(); } string str4 = str; str = str4 + str3 + ",{" + str2 + "},"; } } numComponents = num.ToString(CultureInfo.InvariantCulture); componentInfo = str; }
// // Remove all traces of this from the registry. // // **TODO** If the above does AppID/DCOM stuff, this would have // to remove that stuff too. // private static void UnregisterObjects() { // Ensure that we are running as with admin privilege if (!IsAdministrator) { ElevateSelf("/unregister"); return; } // Remove the local server's DCOM/AppID information Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", s_appId), false); Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)), false); // COM unregister each of the driver assemblies foreach (Type type in s_ComObjectTypes) { TL.LogMessage("RegisterObjects", string.Format("Processing type: {0}, is a COM object: {1}", type.FullName, type.IsCOMObject)); string clsid = Marshal.GenerateGuidForType(type).ToString("B"); string progid = Marshal.GenerateProgIdForType(type); // Remove HKCR\progid Registry.ClassesRoot.DeleteSubKey(String.Format("{0}\\CLSID", progid), false); Registry.ClassesRoot.DeleteSubKey(progid, false); // Remove HKCR\CLSID\clsid Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Implemented Categories\\{{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}}", clsid), false); Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Implemented Categories", clsid), false); Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\ProgId", clsid), false); Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\LocalServer32", clsid), false); Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Programmable", clsid), false); Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}", clsid), false); } }
/// <summary> /// Initializes a new instance of the <see cref="scopefocusServer"/> class. /// Must be public for COM registration. /// </summary> /// public Rotator() { // SharedResources.tl.LogMessage(driverShortName, "Starting initialization"); // connectedState = false; // Initialise connected to false // SharedResources.tl.LogMessage(driverShortName, "Completed initialization"); driverID = Marshal.GenerateProgIdForType(this.GetType()); // 4-27-17 connectedState = false; // SharedResources.tl = new TraceLogger("", "scopefocusServer"); // remd 4-24-17 // ReadProfile(); // Read device configuration from the ASCOM Profile store // added 10-30-2020 // tl.LogMessage("Rotator", "Starting initialisation"); //connectedState = false; // Initialise connected to false //utilities = new Util(); //Initialise util object //astroUtilities = new AstroUtils(); // Initialise astro utilities object ////TODO: Implement your additional construction here // tl.LogMessage("Rotator", "Completed initialisation"); }
/// <summary> /// Initializes a new instance of the <see cref="EqPlatformAdapter"/> class. /// Must be public for COM registration. /// </summary> public Camera() { driverID = Marshal.GenerateProgIdForType(this.GetType()); tl = SharedResources.GetTraceLogger(); tl.LogMessage("Camera", "Starting initialisation"); tl.LogMessage("Camera", "Completed initialisation"); }
public void GenerateProgIdForType_NotRuntimeType_ThrowsNotSupportedException() { AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); Assert.Throws <NotSupportedException>(() => Marshal.GenerateProgIdForType(typeBuilder)); }
// // Remove all traces of this from the registry. // // **TODO** If the above does AppID/DCOM stuff, this would have // to remove that stuff too. // private static void UnregisterObjects() { if (!IsAdministrator) { ElevateSelf("/unregister"); return; } // // Local server's DCOM/AppID information // Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", s_appId), false); Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)), false); // // For each of the driver assemblies // foreach (Type type in s_ComObjectTypes) { string clsid = Marshal.GenerateGuidForType(type).ToString("B"); string progid = Marshal.GenerateProgIdForType(type); string deviceType = type.Name; // // Best efforts // // // HKCR\progid // Registry.ClassesRoot.DeleteSubKey(String.Format("{0}\\CLSID", progid), false); Registry.ClassesRoot.DeleteSubKey(progid, false); // // HKCR\CLSID\clsid // Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Implemented Categories\\{{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}}", clsid), false); Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Implemented Categories", clsid), false); Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\ProgId", clsid), false); Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\LocalServer32", clsid), false); Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Programmable", clsid), false); Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}", clsid), false); /* This is commented out so that profile values are retained when the driver is uninstalled and as part of the upgrade process. * Unfortunately it does mean that drivers will have to be manually deleted from the Profile if they are no longer required. * try * { * // * // ASCOM * // * using (var P = new ASCOM.Utilities.Profile()) * { * P.DeviceType = deviceType; * P.Unregister(progid); * } * } * catch (Exception) { } */ } }
// // Remove all traces of this from the registry. // // **TODO** If the above does AppID/DCOM stuff, this would have // to remove that stuff too. // private static void UnregisterObjects(DriverDiscovery drivers) { if (!IsAdministrator) { ElevateSelf("/unregister"); return; } // // Local server's DCOM/AppID information // Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", s_appId), false); Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)), false); // // For each of the driver assemblies // foreach (var type in drivers.DiscoveredTypes) { var clsid = Marshal.GenerateGuidForType(type).ToString("B"); var progid = Marshal.GenerateProgIdForType(type); var deviceType = type.Name; // // Best efforts // // // HKCR\progid // Registry.ClassesRoot.DeleteSubKey(string.Format("{0}\\CLSID", progid), false); Registry.ClassesRoot.DeleteSubKey(progid, false); // // HKCR\CLSID\clsid // Registry.ClassesRoot.DeleteSubKey( string.Format("CLSID\\{0}\\Implemented Categories\\{{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}}", clsid), false); Registry.ClassesRoot.DeleteSubKey(string.Format("CLSID\\{0}\\Implemented Categories", clsid), false); Registry.ClassesRoot.DeleteSubKey(string.Format("CLSID\\{0}\\ProgId", clsid), false); Registry.ClassesRoot.DeleteSubKey(string.Format("CLSID\\{0}\\LocalServer32", clsid), false); Registry.ClassesRoot.DeleteSubKey(string.Format("CLSID\\{0}\\Programmable", clsid), false); Registry.ClassesRoot.DeleteSubKey(string.Format("CLSID\\{0}", clsid), false); try { // // ASCOM // using (var P = new Profile()) { P.DeviceType = deviceType; P.Unregister(progid); } } catch (Exception) { } } }
// // Remove all traces of this from the registry. // // private static void UnregisterObjects() { if (!IsAdministrator) { ElevateSelf("/unregister"); return; } // // Local server's DCOM/AppID information // Registry.ClassesRoot.DeleteSubKey("APPID\\" + m_sAppId, false); Registry.ClassesRoot.DeleteSubKey("APPID\\" + Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1), false); // // For each of the driver assemblies // foreach (Type type in m_ComObjectTypes) { string clsid = Marshal.GenerateGuidForType(type).ToString("B"); string progid = Marshal.GenerateProgIdForType(type); // // Best efforts // // // HKCR\progid // Registry.ClassesRoot.DeleteSubKey(progid + "\\CLSID", false); Registry.ClassesRoot.DeleteSubKey(progid, false); // // HKCR\CLSID\clsid // Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\Implemented Categories\\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}", false); Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\Implemented Categories", false); Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\ProgId", false); Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\LocalServer32", false); Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\Programmable", false); Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid, false); try { // // ASCOM // Profile P = new Profile(); P.DeviceType = progid.Substring(progid.LastIndexOf('.') + 1); // Requires Helper 5.0.3 or later P.Unregister(progid); try // In case Helper becomes native .NET { Marshal.ReleaseComObject(P); } catch (Exception) { } P = null; } catch (Exception) { } } }
public void TestGenerateProgIdForType() { string output; output = Marshal.GenerateProgIdForType(typeof(TestCoClass)); Assert.AreEqual("MonoTests.System.Runtime.InteropServices.TestCoClass", output, "#1"); output = Marshal.GenerateProgIdForType(typeof(TestCoClassWithProgId)); Assert.AreEqual("CoClassWithProgId", output, "#2"); }
// DOCUMENT: We register ComVisible types that // (implement IRtdServer OR are in ExternalLibraries marked ComServer='true' static public void GetComClassTypes(ExportedAssembly assembly, Type type, object[] attributes, bool isRtdServer, List <ExcelComClassType> comClassTypes) { if (!Marshal.IsTypeVisibleFromCom(type)) { return; } if (isRtdServer || assembly.ComServer) { string progId; Guid clsId; // Check for public default constructor if (type.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null) == null) { // No use to us here - won't be able to construct. return; } if (assembly.IsDynamic) { // Check that we have an explicit Guid attribute object[] attrs = type.GetCustomAttributes(typeof(GuidAttribute), false); if (attrs.Length == 0) { // No Guid attribute - skip this type. return; } else { GuidAttribute guidAtt = (GuidAttribute)attrs[0]; clsId = new Guid(guidAtt.Value); } } else { clsId = Marshal.GenerateGuidForType(type); } progId = Marshal.GenerateProgIdForType(type); ExcelComClassType comClassType = new ExcelComClassType { Type = type, ClsId = clsId, ProgId = progId, IsRtdServer = isRtdServer, TypeLibPath = assembly.TypeLibPath }; comClassTypes.Add(comClassType); Logger.Initialization.Verbose("GetComClassTypes - Found type {0}, with ProgId {1}", type.FullName, progId); } }
/// <summary> /// Initializes a new instance of the <see cref="Simulator"/> class. /// Must be public for COM registration. /// </summary> public Switch() { driverID = Marshal.GenerateProgIdForType(this.GetType()); ReadProfile(); // Read device configuration from the ASCOM Profile store tl = new TraceLogger("", "Simulator"); tl.Enabled = traceState; tl.LogMessage("Switch", "Starting initialisation"); connectedState = false; // Initialise connected to false //TODO: Implement your additional construction here tl.LogMessage("Switch", "Completed initialisation"); }
/// <summary> /// Initializes a new instance of the <see cref="OpenAstroTracker"/> class. /// Must be public for COM registration. /// </summary> public Focuser() { _driverId = Marshal.GenerateProgIdForType(this.GetType()); logMessage = SharedResources.LogMessageCallback; logMessage(LoggingFlags.Focuser, "Starting initialisation"); utilities = new Util(); //Initialise util object astroUtilities = new AstroUtils(); // Initialise astro-utilities object logMessage(LoggingFlags.Focuser, "Completed initialisation"); }
// // Remove all traces of this from the registry. // // **TODO** If the above does AppID/DCOM stuff, this would have // to remove that stuff too. // private static void UnregisterObjects() { if (!IsAdministrator) { ElevateSelf("/unregister"); return; } // // Local server's DCOM/AppID information // var exePath = Path.GetFileName(Application.ExecutablePath); var appIdRoot = Registry.LocalMachine.OpenSubKey(@"Software\Classes\APPID", writable: true); appIdRoot?.DeleteSubKey(s_appId, false); appIdRoot?.DeleteSubKey(exePath, false); // // For each of the driver assemblies // foreach (var type in s_ComObjectTypes) { var clsid = Marshal.GenerateGuidForType(type).ToString("B"); var progid = Marshal.GenerateProgIdForType(type); var deviceType = type.Name; // Best efforts // HKLM\Software\Classes\{progid} var classesRoot = Registry.LocalMachine.OpenSubKey(@"Software\Classes"); classesRoot.DeleteSubKeyTree(progid, throwOnMissingSubKey: false); // HKLM\Software\Classes\CLSID\{clsid} classesRoot.DeleteSubKeyTree($@"CLSID\{clsid}", throwOnMissingSubKey: false); try { // // ASCOM // using (var P = new Profile()) { P.DeviceType = deviceType; P.Unregister(progid); } } catch (Exception) { // Fail silently } } }
/// <summary> /// Initializes a new instance of the <see cref="EqPlatformAdapter"/> class. /// Must be public for COM registration. /// </summary> public Telescope() { driverID = Marshal.GenerateProgIdForType(this.GetType()); tl = SharedResources.GetTraceLogger(); tl.LogMessage("Telescope", "Starting initialisation"); utilities = new Util(); //Initialise util object astroUtilities = new AstroUtils(); // Initialise astro utilities object transform = new Transform(); tl.LogMessage("Telescope", "Completed initialisation"); }
/// <summary> /// Initializes a new instance of the <see cref="OpenAstroTracker"/> class. /// Must be public for COM registration. /// </summary> public Focuser() { _driverId = Marshal.GenerateProgIdForType(this.GetType()); _tl = SharedResources.tl; _tl.Enabled = Profile.TraceState; _tl.LogMessage("Focuser", "Starting initialisation"); utilities = new Util(); //Initialise util object astroUtilities = new AstroUtils(); // Initialise astro-utilities object _tl.LogMessage("Focuser", "Completed initialisation"); }
public ClassFactory(Type type) { _classType = type ?? throw new ArgumentNullException("type"); _progid = Marshal.GenerateProgIdForType(type); _classId = Marshal.GenerateGuidForType(type); // Should be nailed down by [Guid(...)] _classContext = (uint)CLSCTX.CLSCTX_LOCAL_SERVER; // Default _flags = (uint)REGCLS.REGCLS_MULTIPLEUSE // Default | (uint)REGCLS.REGCLS_SUSPENDED; _interfaceTypes = new ArrayList(); foreach (Type T in type.GetInterfaces()) // Save all of the implemented interfaces { _interfaceTypes.Add(T); } }
/// <summary> /// ASCOM DeviceID (COM ProgID) for this driver. /// The DeviceID is used by ASCOM applications to load the driver at runtime. /// </summary> //private static string driverID = "ASCOM.NexStar.Telescope"; // TODO Change the descriptive string for your driver then remove this line /// <summary> /// Driver description that displays in the ASCOM Chooser. /// </summary> //private static string driverDescription = "NexStar Telescope Driver"; #if Telescope // // Driver private data (rate collections) for the telescope driver only. // This can be removed for other driver types // //private readonly AxisRates[] _axisRates; #endif /// <summary> /// Initializes a new instance of the <see cref="NexStar"/> class. /// Must be public for COM registration. /// </summary> public Telescope() { #if Telescope // the rates constructors are only needed for the telescope class // This can be removed for other driver types //_axisRates = new AxisRates[3]; //_axisRates[0] = new AxisRates(TelescopeAxes.axisPrimary); //_axisRates[1] = new AxisRates(TelescopeAxes.axisSecondary); //_axisRates[2] = new AxisRates(TelescopeAxes.axisTertiary); #endif //TODO: Implement your additional construction here Common.DriverId = Marshal.GenerateProgIdForType(this.GetType()); Attribute attr = ServedClassNameAttribute.GetCustomAttribute(typeof(Telescope), typeof(ServedClassNameAttribute)); Common.DriverDescription = ((ServedClassNameAttribute)attr).DisplayName; }
// // Constructor - Must be public for COM registration! // public Telescope() { _driverId = Marshal.GenerateProgIdForType(this.GetType()); _tl = SharedResources.tl; _tl.Enabled = Profile.TraceState; LogMessage("Telescope", $"Starting initialization - v{Version}"); // TODO: Implement your additional construction here _transform.SetJ2000(_utilities.HMSToHours("02:31:51.12"), _utilities.DMSToDegrees("89:15:51.4")); _transform.SiteElevation = SiteElevation; _transform.SiteLatitude = SiteLatitude; _transform.SiteLongitude = SiteLongitude; PolarisRAJNow = _transform.RATopocentric; LogMessage("Telescope", "Completed initialization"); }
/// <summary> /// Initializes a new instance of the <see cref="TalonSuccessor"/> class. /// Must be public for COM registration. /// </summary> public Dome() { s_csDriverID = Marshal.GenerateProgIdForType(this.GetType()); s_csDriverDescription = "Talon Successor"; tl = new TraceLogger("", "TalonSuccessor"); ReadProfile(); // Read device configuration from the ASCOM Profile store tl.LogMessage("Dome", "Starting initialisation"); // connectedState = false; // Initialise connected to false utilities = new Util(); //Initialise util object astroUtilities = new AstroUtils(); // Initialise astro utilities object //TODO: Implement your additional construction here tl.LogMessage("Dome", "Completed initialisation"); }
/// <summary> /// Initializes a new instance of the <see cref="Skeleton2"/> class. /// Must be public for COM registration. /// </summary> public Telescope() { tl = new TraceLogger("", "Skeleton2"); Guid _guid = SharedResources.GetGuid(); MessageBox.Show("Shared Resources = " + _guid.ToString(), "Message"); driverID = Marshal.GenerateProgIdForType(this.GetType()); ReadProfile(); // Read device configuration from the ASCOM Profile store tl.LogMessage("Telescope", "Starting initialisation"); connectedState = false; // Initialise connected to false utilities = new Util(); //Initialise util object astroUtilities = new AstroUtils(); // Initialise astro utilities object //TODO: Implement your additional construction here tl.LogMessage("Telescope", "Completed initialisation"); }
/// <summary> /// Initializes a new instance of the <see cref="DeviceHub"/> class. /// </summary> public Focuser() { _driverID = Marshal.GenerateProgIdForType(this.GetType()); _driverDescription = GetDriverDescriptionFromAttribute(); _logger = new TraceLogger("", "DeviceHubFocuser"); ReadProfile(); // Read device configuration from the ASCOM Profile store _logger.LogMessage("Focuser", "Starting initialization"); ConnectedState = false; // Initialise connected to false Utilities = new Util(); //Initialise util object // We need this to get the focuser ID. AppSettingsManager.LoadAppSettings(); _logger.LogMessage("Focuser", "Completed initialization"); }
public static void test() { //uint a=0; IntPtr b = new IntPtr(0); //a=Program.GetWindowThreadProcessId(b, a); string result = ""; Process[] processes = Process.GetProcesses(); foreach (var process in processes) { result = process.MainWindowTitle; Console.WriteLine(result); result = process.MainWindowTitle; if (result == "Kalkulator") { Console.WriteLine(result); Console.WriteLine(process.Handle); Console.WriteLine(process.MainWindowHandle); Console.WriteLine(process.Id); Console.WriteLine(process.ProcessName); Console.WriteLine(process.Threads); Console.WriteLine(process.GetType()); Console.WriteLine(process.Handle); Console.WriteLine(process.HandleCount); foreach (ProcessThread ab in process.Threads) { Console.WriteLine(ab.Id); try { //Console.WriteLine(ab.GetType()); String sProgId = Marshal.GenerateProgIdForType(ab.GetType()); Object obj = GetObj(1, sProgId); } catch (Exception e) { } } //process.Handle } } System.Threading.Thread.Sleep(50000); //GetObj(1, "Word.Application"); }
// // Constructor - Must be public for COM registration! // public Telescope() { try { driverID = Marshal.GenerateProgIdForType(this.GetType()); m_Util = new ASCOM.Utilities.Util(); // get a unique instance id objectId = TelescopeHardware.GetId(); TelescopeHardware.TL.LogMessage("New", "Instance ID: " + objectId + ", new: " + "Driver ID: " + driverID); TrackingRates = new TrackingRateObject(TelescopeInstance.TrackingRates); } catch (Exception ex) { EventLogCode.LogEvent("ASCOM.SimulatorCore.Telescope", "Exception on New", EventLogEntryType.Error, GlobalConstants.EventLogErrors.TelescopeSimulatorNew, ex.ToString()); System.Windows.Forms.MessageBox.Show("Telescope New: " + ex.ToString()); } }
private void WriteTypes(Stream s, Module m, Assembly asm, string strRuntimeVersion, RegistrationServices regServices, bool bGenerateTypeLib, int offset) { string fullName = null; string str2 = "{" + Marshal.GetTypeLibGuidForAssembly(asm).ToString().ToUpper() + "}"; foreach (Type type in m.GetTypes()) { if (regServices.TypeRequiresRegistration(type)) { string str3 = "{" + Marshal.GenerateGuidForType(type).ToString().ToUpper() + "}"; fullName = type.FullName; if (regServices.TypeRepresentsComType(type) || type.IsValueType) { this.WriteUTFChars(s, "<clrSurrogate" + Environment.NewLine, offset); this.WriteUTFChars(s, " clsid=\"" + str3 + "\"" + Environment.NewLine, offset); this.WriteUTFChars(s, " name=\"" + fullName + "\">" + Environment.NewLine, offset); this.WriteUTFChars(s, "</clrSurrogate>" + Environment.NewLine, offset); } else { string str4 = Marshal.GenerateProgIdForType(type); this.WriteUTFChars(s, "<clrClass" + Environment.NewLine, offset); this.WriteUTFChars(s, " clsid=\"" + str3 + "\"" + Environment.NewLine, offset); this.WriteUTFChars(s, " progid=\"" + str4 + "\"" + Environment.NewLine, offset); this.WriteUTFChars(s, " threadingModel=\"Both\"" + Environment.NewLine, offset); this.WriteUTFChars(s, " name=\"" + fullName + "\"" + Environment.NewLine, offset); this.WriteUTFChars(s, " runtimeVersion=\"" + strRuntimeVersion + "\">" + Environment.NewLine, offset); this.WriteUTFChars(s, "</clrClass>" + Environment.NewLine, offset); } } else if ((bGenerateTypeLib && type.IsInterface) && (type.IsPublic && !type.IsImport)) { string str5 = "{" + Marshal.GenerateGuidForType(type).ToString().ToUpper() + "}"; this.WriteUTFChars(s, "<comInterfaceExternalProxyStub" + Environment.NewLine, offset); this.WriteUTFChars(s, "iid=\"" + str5 + "\"" + Environment.NewLine, offset + 4); this.WriteUTFChars(s, "name=\"" + type.Name + "\"" + Environment.NewLine, offset + 4); this.WriteUTFChars(s, string.Concat(new object[] { "numMethods=\"", type.GetMethods().Length, "\"", Environment.NewLine }), offset + 4); this.WriteUTFChars(s, "proxyStubClsid32=\"{00020424-0000-0000-C000-000000000046}\"" + Environment.NewLine, offset + 4); this.WriteUTFChars(s, "tlbid=\"" + str2 + "\" />" + Environment.NewLine, offset + 4); } } }
public ClassFactory(Type type) { if (type == null) { throw new ArgumentNullException("type"); } m_ClassType = type; //PWGS Get the ProgID from the MetaData m_progid = Marshal.GenerateProgIdForType(type); m_ClassId = Marshal.GenerateGuidForType(type); // Should be nailed down by [Guid(...)] m_ClassContext = (uint)CLSCTX.CLSCTX_LOCAL_SERVER; // Default m_Flags = (uint)REGCLS.REGCLS_MULTIPLEUSE | // Default (uint)REGCLS.REGCLS_SUSPENDED; m_InterfaceTypes = new ArrayList(); foreach (Type T in type.GetInterfaces()) // Save all of the implemented interfaces { m_InterfaceTypes.Add(T); } }
// // Constructor - Must be public for COM registration! // public Telescope() { _driverId = Marshal.GenerateProgIdForType(this.GetType()); logMessageFunc = SharedResources.LogMessageCallback; SharedResources.SetTraceFlags(Profile.TraceFlags); LogMessage(LoggingFlags.Scope, $"Starting initialization - v{Version}"); // TODO: Implement your additional construction here _transform.SetJ2000(_utilities.HMSToHours("02:31:51.12"), _utilities.DMSToDegrees("89:15:51.4")); _transform.SiteElevation = SiteElevation; _transform.SiteLatitude = SiteLatitude; _transform.SiteLongitude = SiteLongitude; PolarisRAJNow = _transform.RATopocentric; _azAltTransform.SiteElevation = SiteElevation; _azAltTransform.SiteLatitude = SiteLatitude; _azAltTransform.SiteLongitude = SiteLongitude; LogMessage(LoggingFlags.Scope, "Completed initialization"); }
/// <summary> /// Initializes a new instance of the <see cref="iOptronZEQ25"/> class. /// Must be public for COM registration. /// </summary> public Telescope() { driverID = Marshal.GenerateProgIdForType(this.GetType()); driverDescription = GetDriverDescription(); tl = new TraceLogger("", "iOptronZEQ25"); //ReadProfile(); // Read device configuration from the ASCOM Profile store //Properties.Settings.Default.Reload(); comPort = iOptronZEQ25.Properties.Settings.Default.COMPort; tl.LogMessage("Telescope", "Starting initialisation"); //connectedState = false; // Initialise connected to false utilities = new Util(); //Initialise util object astroUtilities = new AstroUtils(); // Initialise astro-utilities object //TODO: Implement your additional construction here clientId = SharedResources.ConnectionManager.RegisterClient(SharedResources.TelescopeDriverId); tl.LogMessage("Telescope", "Completed initialisation"); }
/// <include file='doc\ImportUtil.uex' path='docs/doc[@for="ComManagedImportUtil.GetComponentInfo"]/*' /> public void GetComponentInfo(string assemblyPath, out string numComponents, out string componentInfo) { RegistrationServices rs = new RegistrationServices(); Assembly asm = LoadAssembly(assemblyPath); Type[] asmTypes = rs.GetRegistrableTypesInAssembly(asm); int nComponents = 0; string s = ""; foreach (Type t in asmTypes) { if (t.IsClass && t.IsSubclassOf(typeof(ServicedComponent))) { nComponents++; string clsid = Marshal.GenerateGuidForType(t).ToString();; string progId = Marshal.GenerateProgIdForType(t); s += progId + ",{" + clsid + "},"; } } numComponents = nComponents.ToString(); componentInfo = s; }
// // Do everything to register this for COM. Never use REGASM on // this exe assembly! It would create InProcServer32 entries // which would prevent proper activation! // // Using the list of COM object types generated during dynamic // assembly loading, it registers each one for COM as served by our // exe/local server, as well as registering it for ASCOM. It also // adds DCOM info for the local server itself, so it can be activated // via an outboiud connection from TheSky. // private static void RegisterObjects() { if (!IsAdministrator) { ElevateSelf("/register"); return; } // // If reached here, we're running elevated // var assy = Assembly.GetExecutingAssembly(); var attr = Attribute.GetCustomAttribute(assy, typeof(AssemblyTitleAttribute)); var assyTitle = ((AssemblyTitleAttribute)attr).Title; attr = Attribute.GetCustomAttribute(assy, typeof(AssemblyDescriptionAttribute)); var assyDescription = ((AssemblyDescriptionAttribute)attr).Description; // // Local server's DCOM/AppID information // var appIdKey = Registry.LocalMachine.CreateSubKey(@"Software\Classes\AppID"); var serverAppIdKey = appIdKey.CreateSubKey(s_appId); try { // // HKLM\Software\Classes\AppID\{server-app-id} // serverAppIdKey.SetValue(null, assyDescription); serverAppIdKey.SetValue("AppID", s_appId); serverAppIdKey.SetValue("AuthenticationLevel", 1, RegistryValueKind.DWord); serverAppIdKey.SetValue("RunAs", "Interactive User"); // // HKLM\Software\Classes\AppID\{server-executable-filename} // var executableFileName = Path.GetFileName(Application.ExecutablePath); using (var executableKey = appIdKey.CreateSubKey(executableFileName)) { executableKey?.SetValue("AppID", s_appId, RegistryValueKind.String); } } catch (Exception ex) { MessageBox.Show("Error while registering the server:\n" + ex, "ASCOM LocalServer", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } finally { appIdKey?.Dispose(); serverAppIdKey?.Dispose(); } // // For each of the driver assemblies // foreach (var type in s_ComObjectTypes) { var bFail = false; try { // // HKLM\Software\Classes\ClsID\{clsid} // var clsid = Marshal.GenerateGuidForType(type).ToString("B"); var progid = Marshal.GenerateProgIdForType(type); //PWGS Generate device type from the Class name var deviceType = type.Name; //[TPL] unsafe assumption using (var key = Registry.LocalMachine.CreateSubKey($@"Software\Classes\CLSID\{clsid}")) { key.SetValue(null, progid); // Could be assyTitle/Desc??, but .NET components show ProgId here key.SetValue("AppId", s_appId); using (var key2 = key.CreateSubKey("Implemented Categories")) { key2.CreateSubKey("{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}"); } using (var key2 = key.CreateSubKey("ProgId")) { key2.SetValue(null, progid); } key.CreateSubKey("Programmable"); using (var key2 = key.CreateSubKey("LocalServer32")) { key2.SetValue(null, Application.ExecutablePath); } } // // HKLM\Software\Classes\{progid} // using (var key = Registry.LocalMachine.CreateSubKey($@"Software\Classes\{progid}")) { key.SetValue(null, assyTitle); using (var key2 = key.CreateSubKey("CLSID")) { key2.SetValue(null, clsid); } } // // ASCOM // assy = type.Assembly; // Pull the display name from the ServedClassName attribute. attr = Attribute.GetCustomAttribute(type, typeof(ServedClassNameAttribute)); //PWGS Changed to search type for attribute rather than assembly var chooserName = ((ServedClassNameAttribute)attr).DisplayName ?? $"Server for {type.Name}"; using (var P = new Profile()) { P.DeviceType = deviceType; P.Register(progid, chooserName); } } catch (Exception ex) { MessageBox.Show("Error while registering the server:\n" + ex, "ASCOM LocalServer", MessageBoxButtons.OK, MessageBoxIcon.Stop); bFail = true; } if (bFail) { break; } } }