public void DemoRpcOverLrpc() { //obtain the interface id for rpc registration Guid iid = Marshal.GenerateGuidForType(typeof(ISearchService)); //Create the server with a stub pointing to our implementation using (RpcServer.CreateRpc(iid, new SearchService.ServerStub(new AuthenticatedSearch())) //allow GSS_NEGOTIATE .AddAuthNegotiate() //LRPC named 'lrpctest' .AddProtocol("ncalrpc", "lrpctest") //Begin responding .StartListening()) { //Create the rpc client connection and give it to the new SearchService using ( SearchService client = new SearchService( RpcClient.ConnectRpc(iid, "ncalrpc", null, "lrpctest").Authenticate( RpcAuthenticationType.Self))) { //party on! SearchResponse results = client.Search(SearchRequest.CreateBuilder().AddCriteria("Test Criteria").Build()); Assert.AreEqual(1, results.ResultsCount); Assert.AreEqual("Test Criteria", results.ResultsList[0].Name); Assert.AreEqual("http://whatever.com", results.ResultsList[0].Url); } } }
// Implement creation of the type and interface. void IClassFactory.CreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject) { var nullPtr = new IntPtr(0); ppvObject = nullPtr; // Handle specific requests for implemented interfaces foreach (Type iType in m_InterfaceTypes) { if (riid == Marshal.GenerateGuidForType(iType)) { ppvObject = Marshal.GetComInterfaceForObject(Activator.CreateInstance(m_ClassType), iType); return; } } // Handle requests for IDispatch or IUnknown on the class if (riid == IID_IDispatch) { ppvObject = Marshal.GetIDispatchForObject(Activator.CreateInstance(m_ClassType)); } else if (riid == IID_IUnknown) { ppvObject = Marshal.GetIUnknownForObject(Activator.CreateInstance(m_ClassType)); } else { throw new COMException("No interface", unchecked ((int)0x80004002)); } }
public void InsertControl(Control control, int position, uint dwUser) { if (control == null) { return; } ILockBytes bytes; IStorage storage; IOleClientSite site; var guid = Marshal.GenerateGuidForType(control.GetType()); NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes); NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage); IRichEditOle.GetClientSite(out site); var lpreobject = new REOBJECT(); lpreobject.posistion = position; lpreobject.clsid = guid; lpreobject.pstg = storage; lpreobject.poleobj = Marshal.GetIUnknownForObject(control); lpreobject.polesite = site; lpreobject.dvAspect = 1; lpreobject.dwFlags = 2; lpreobject.dwUser = dwUser; IRichEditOle.InsertObject(lpreobject); Marshal.ReleaseComObject(bytes); Marshal.ReleaseComObject(site); Marshal.ReleaseComObject(storage); }
public InterfaceConfigCallback(ICatalogCollection coll, Type t, Hashtable cache, RegistrationDriver driver) { this._type = t; this._coll = coll; this._cache = cache; this._driver = driver; this._ifcs = this.GetInteropInterfaces(this._type); foreach (Type type in this._ifcs) { if (Marshal.GenerateGuidForType(type) == IID_IProcessInitializer) { try { ICatalogObject obj2 = cache["Component"] as ICatalogObject; ICatalogCollection catalogs = cache["ComponentCollection"] as ICatalogCollection; obj2.SetValue("InitializesServerApplication", 1); catalogs.SaveChanges(); } catch (Exception exception) { if ((exception is NullReferenceException) || (exception is SEHException)) { throw; } throw new RegistrationException(Resource.FormatString("Reg_FailPIT", this._type), exception); } } } RegistrationDriver.Populate(this._coll); }
int IObjectWithSite.SetSite(object site) { this.site = site; if (site != null) { var serviceProv = (IServiceProvider)this.site; var guidIWebBrowserApp = Marshal.GenerateGuidForType(typeof(IWebBrowserApp)); var guidIWebBrowser2 = Marshal.GenerateGuidForType(typeof(IWebBrowser2)); IntPtr intPtr; serviceProv.QueryService(ref guidIWebBrowserApp, ref guidIWebBrowser2, out intPtr); browser = (IWebBrowser2)Marshal.GetObjectForIUnknown(intPtr); ((DWebBrowserEvents2_Event)browser).DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else { ((DWebBrowserEvents2_Event)browser).DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); browser = null; } return(0); }
private static void AddComImportedTypeToRegFile(Type type, String strAsmName, String strAsmVersion, String strAsmCodeBase, String strRuntimeVersion, Stream regFile) { String strClsId = "{" + Marshal.GenerateGuidForType(type).ToString().ToUpper(CultureInfo.InvariantCulture) + "}"; // HKEY_CLASS_ROOT\CLSID\<CLSID>\InprocServer32 key. WriteUTFChars(regFile, Environment.NewLine); WriteUTFChars(regFile, "[" + strClassesRootRegKey + "\\CLSID\\" + strClsId + "\\InprocServer32]" + Environment.NewLine); WriteUTFChars(regFile, "\"Class\"=\"" + type.FullName + "\"" + Environment.NewLine); WriteUTFChars(regFile, "\"Assembly\"=\"" + strAsmName + "\"" + Environment.NewLine); WriteUTFChars(regFile, "\"RuntimeVersion\"=\"" + strRuntimeVersion + "\"" + Environment.NewLine); if (strAsmCodeBase != null) { WriteUTFChars(regFile, "\"CodeBase\"=\"" + strAsmCodeBase + "\"" + Environment.NewLine); } // HKEY_CLASSES_ROOT\CLSID\<CLSID>\InprovServer32\<version> key WriteUTFChars(regFile, Environment.NewLine); WriteUTFChars(regFile, "[" + strClassesRootRegKey + "\\CLSID\\" + strClsId + "\\InprocServer32" + "\\" + strAsmVersion + "]" + Environment.NewLine); WriteUTFChars(regFile, "\"Class\"=\"" + type.FullName + "\"" + Environment.NewLine); WriteUTFChars(regFile, "\"Assembly\"=\"" + strAsmName + "\"" + Environment.NewLine); WriteUTFChars(regFile, "\"RuntimeVersion\"=\"" + strRuntimeVersion + "\"" + Environment.NewLine); if (strAsmCodeBase != null) { WriteUTFChars(regFile, "\"CodeBase\"=\"" + strAsmCodeBase + "\"" + Environment.NewLine); } }
public void DemoExampleConnection() { //obtain the interface id for rpc registration Guid iid = Marshal.GenerateGuidForType(typeof(ISearchService)); //Create the server with a stub pointing to our implementation using (RpcServer.CreateRpc(iid, new SearchService.ServerStub(new AuthenticatedSearch())) //allow GSS_NEGOTIATE .AddAuthNegotiate() //LRPC named 'lrpctest' .AddProtocol("ncalrpc", "lrpctest") .AddProtocol("ncacn_ip_tcp", "12345") .AddProtocol("ncacn_np", @"\pipe\p1") //Begin responding .StartListening()) { // Demonstrate a typical client-implemented wrapper that can parse URIs, retry connections, etc. using (var client = new SearchService(new ExampleRpcConnection(iid, "lrpc://localhost/lrpctest"))) Assert.AreEqual(1, client.Search(SearchRequest.CreateBuilder().AddCriteria("Test1").Build()).ResultsCount); using (var client = new SearchService(new ExampleRpcConnection(iid, "rpc://self@localhost:12345"))) Assert.AreEqual(1, client.Search(SearchRequest.CreateBuilder().AddCriteria("Test2").Build()).ResultsCount); using (var client = new SearchService(new ExampleRpcConnection(iid, "np://self@localhost/pipe/p1"))) Assert.AreEqual(1, client.Search(SearchRequest.CreateBuilder().AddCriteria("Test3").Build()).ResultsCount); } }
// // 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); } }
public static CoreWindow CreateCoreWindow(String windowTitle, int x, int y, int width, int height) { IntPtr pvObject; Guid iid = Marshal.GenerateGuidForType(typeof(ICoreWindow)); UInt32 hr = WindowsUI.CreateCoreWindow( 6, /* NOT_IMMERSIVE */ windowTitle, x, y, width, height, 0, IntPtr.Zero, ref iid, out pvObject); if (0 != hr) { throw new Exception(String.Format("CreateCoreWindow failed with 0x{0:X}", hr)); } IInspectable inspectable = new IInspectable(pvObject); CoreWindow coreWindow = (CoreWindow)Marshal.GetObjectForIUnknown(pvObject); inspectable.Dispose(); return(coreWindow); }
/// <summary> /// Creates an instance of a COM object without the Registry information, by invoking its class factory. /// </summary> /// <param name="guidClsid">CLSID of the object to create.</param> public ComObject CreateComObject(Guid guidClsid) { // Get factory provider entry point var funcDllGetClassObject = ImportMethod <DllGetClassObjectDelegate>("DllGetClassObject"); object instance; try { // Get the factory IClassFactory factory; Guid iidClassFactory = Marshal.GenerateGuidForType(typeof(IClassFactory)); int retval = funcDllGetClassObject(&guidClsid, &iidClassFactory, out factory); if (retval < 0) { Marshal.ThrowExceptionForHR(retval); } // Make the factory create the object var iidIUnknown = new Guid("00000000-0000-0000-C000-000000000046"); factory.CreateInstance(null, iidIUnknown, out instance); } catch (Exception ex) { throw new InvalidOperationException(String.Format("Could not create an instance of {0} from {1}. {2}", guidClsid, File.QuoteIfNeeded(), ex.Message), ex); } if (instance == null) { throw new InvalidOperationException(String.Format("Failed to create an instance of {0} from {1}.", guidClsid, File.QuoteIfNeeded())); } return(new ComObject(instance, guidClsid)); }
int IObjectWithSite.SetSite(object site) { this.site = site; if (site != null) { LoadOptions(); var serviceProv = (IServiceProvider)this.site; var guidIWebBrowserApp = Marshal.GenerateGuidForType(typeof(IWebBrowserApp)); // new Guid("0002DF05-0000-0000-C000-000000000046"); var guidIWebBrowser2 = Marshal.GenerateGuidForType(typeof(IWebBrowser2)); // new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E"); IntPtr intPtr; serviceProv.QueryService(ref guidIWebBrowserApp, ref guidIWebBrowser2, out intPtr); browser = (IWebBrowser2)Marshal.GetObjectForIUnknown(intPtr); ((DWebBrowserEvents2_Event)browser).DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else { ((DWebBrowserEvents2_Event)browser).DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); browser = null; } return(0); }
// // 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 GetCF() { foreach (var f in Directory.EnumerateFiles(@"C:\Temp", "*.*", SearchOption.AllDirectories)) { try { SHGetPropertyStoreFromParsingName(f, null, GETPROPERTYSTOREFLAGS.GPS_READWRITE, Marshal.GenerateGuidForType(typeof(IPropertyStore)), out IPropertyStore ps); if (ps == null) { continue; } using (var pv = new PROPVARIANT()) { ps.GetValue(ref PROPERTYKEY.System.Thumbnail, pv); if (pv.IsNullOrEmpty) { continue; } if (pv.vt == VARTYPE.VT_CF) { TestContext.WriteLine(f); } } ps = null; } catch { } } }
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; }
private static string GetProgID(Type type) { Guid guid = Marshal.GenerateGuidForType(type); string progID = String.Format(CultureInfo.InvariantCulture, "{0:B}", guid); return(progID); }
public void InsertControl(Control control) { if (control != null) { ILockBytes bytes; IStorage storage; IOleClientSite site; Guid guid = Marshal.GenerateGuidForType(control.GetType()); NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes); NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage); IRichEditOle.GetClientSite(out site); REOBJECT lpreobject = new REOBJECT(); lpreobject.cp = _richEdit.TextLength; lpreobject.clsid = guid; lpreobject.pstg = storage; lpreobject.poleobj = Marshal.GetIUnknownForObject(control); lpreobject.polesite = site; lpreobject.dvAspect = 1; lpreobject.dwFlags = 2; lpreobject.dwUser = 1; IRichEditOle.InsertObject(lpreobject); Marshal.ReleaseComObject(bytes); Marshal.ReleaseComObject(site); Marshal.ReleaseComObject(storage); } }
internal static V1Interop.ITask GetTask(V1Interop.ITaskScheduler iSvc, string name) { Guid ITaskGuid = Marshal.GenerateGuidForType(typeof(V1Interop.ITask)); try { return(iSvc.Activate(name, ref ITaskGuid)); } catch {} return(null); }
public void InsertControl(Control control, int position, uint dwUser) { if (control != null) { ILockBytes bytes; IStorage storage; IOleClientSite site; Guid guid = Marshal.GenerateGuidForType(control.GetType()); NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes); NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage); this.IRichEditOle.GetClientSite(out site); REOBJECT lpreobject = new REOBJECT { posistion = position, clsid = guid, pstg = storage, poleobj = Marshal.GetIUnknownForObject(control), polesite = site, dvAspect = 1, dwFlags = 0x00000002, dwUser = dwUser }; this.IRichEditOle.InsertObject(lpreobject); Marshal.ReleaseComObject(bytes); Marshal.ReleaseComObject(site); Marshal.ReleaseComObject(storage); } }
public InterfaceConfigCallback(ICatalogCollection coll, Type t, Hashtable cache, RegistrationDriver driver) { _type = t; _coll = coll; _cache = cache; _driver = driver; // TODO: Populate w/ QueryByKey // TODO: Build cache for FindObject() _ifcs = GetInteropInterfaces(_type); // Check to see if one of the interfaces is IProcessInitializer foreach (Type ifc in _ifcs) { if (Marshal.GenerateGuidForType(ifc) == IID_IProcessInitializer) { DBG.Info(DBG.Registration, "Setting component " + cache["ComponentType"] + " up as process initializer"); try { ICatalogObject comp = cache["Component"] as ICatalogObject; ICatalogCollection compColl = cache["ComponentCollection"] as ICatalogCollection; comp.SetValue("InitializesServerApplication", 1); compColl.SaveChanges(); } catch (Exception e) { throw new RegistrationException(Resource.FormatString("Reg_FailPIT", _type), e); } } } RegistrationDriver.Populate(_coll); }
public void GenerateGuidForType_NotRuntimeType_ThrowsArgumentException() { AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); AssertExtensions.Throws <ArgumentException>("type", () => Marshal.GenerateGuidForType(typeBuilder)); }
/// <include file='doc\BYOT.uex' path='docs/doc[@for="BYOT.CreateWithTipTransaction"]/*' /> public static Object CreateWithTipTransaction(String url, Type t) { Guid clsid = Marshal.GenerateGuidForType(t); return(((ICreateWithTipTransactionEx)GetByotServer()).CreateInstance(url, clsid, Util.IID_IUnknown)); }
internal static ITask GetTask(ITaskScheduler iSvc, string name) { var riid = Marshal.GenerateGuidForType(typeof(ITask)); try { return(iSvc.Activate(name, ref riid)); } catch { } return(null); }
// // 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) { } */ } }
internal void UnregisterAssembly(Assembly asm, ApplicationSpec spec) { bool flag = true; if ((null != asm) && ((spec != null) && (spec.ConfigurableTypes != null))) { foreach (Type type in spec.ConfigurableTypes) { string str = "{" + Marshal.GenerateGuidForType(type).ToString() + "}"; try { int num = 0; Type type2 = this._cat.GetType(); try { object[] args = new object[5]; args[0] = str; num = (int)this.InvokeMemberHelper(type2, "GetComponentVersions", BindingFlags.InvokeMethod, null, this._cat, args); } catch (COMException exception) { if (-2147352570 != exception.ErrorCode) { throw; } num = (int)this.InvokeMemberHelper(type2, "GetComponentVersionCount", BindingFlags.InvokeMethod, null, this._cat, new object[] { str }); } if (num > 0) { flag = false; break; } } catch (COMException exception2) { if (-2147221164 != exception2.ErrorCode) { throw; } } } if (flag) { this.ClassicUnregistration(asm); try { this.UnregisterTypeLib(asm); } catch (Exception exception3) { if ((exception3 is NullReferenceException) || (exception3 is SEHException)) { throw; } } } } }
// // 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) { } } }
private static void hostRpc() { var guid = Marshal.GenerateGuidForType(typeof(api)); _api = new ExplicitBytesServer(guid); _api.AddProtocol(RpcProtseq.ncalrpc, "FastDataServer", 20); _api.OnExecute += api_OnExecute; _api.StartListening(); }
// // 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) { } } }
static void Main(string[] args) { if (!ProcessArguments(args)) { return; } // Initialize critical member variables. m_iObjsInUse = 0; m_iServerLocks = 0; m_uiMainThreadId = GetCurrentThreadId(); // Register the SimpleCOMObjectClassFactory. SimpleCOMObjectClassFactory factory = new SimpleCOMObjectClassFactory(); factory.ClassContext = (uint)CLSCTX.CLSCTX_LOCAL_SERVER; factory.ClassId = Marshal.GenerateGuidForType(typeof(XApiCom)); factory.Flags = (uint)REGCLS.REGCLS_MULTIPLEUSE | (uint)REGCLS.REGCLS_SUSPENDED; factory.RegisterClassObject(); ClassFactoryBase.ResumeClassObjects(); // Start up the garbage collection thread. GarbageCollection GarbageCollector = new GarbageCollection(10000); Thread GarbageCollectionThread = new Thread(new ThreadStart(GarbageCollector.GCWatch)); // Set the name of the thread object. GarbageCollectionThread.Name = "Garbage Collection Thread"; // Start the thread. GarbageCollectionThread.Start(); // Start the message loop. MSG msg; IntPtr null_hwnd = new IntPtr(0); while (GetMessage(out msg, null_hwnd, 0, 0) != false) { TranslateMessage(ref msg); DispatchMessage(ref msg); } Console.WriteLine("Out of message loop."); // Revoke the class factory immediately. // Don't wait until the thread has stopped before // we perform revokation. factory.RevokeClassObject(); Console.WriteLine("SimpleCOMObjectClassFactory Revoked."); // Now stop the Garbage Collector thread. GarbageCollector.StopThread(); GarbageCollector.WaitForThreadToStop(); Console.WriteLine("GarbageCollector thread stopped."); // Just an indication that this COM EXE Server is stopped. Console.WriteLine("Press [ENTER] to exit."); Console.ReadLine(); }
private System.Runtime.InteropServices.ComTypes.IMoniker GetCmdNameMoniker() { System.Runtime.InteropServices.ComTypes.IMoniker moniker; string delim = "!"; Guid guid = Marshal.GenerateGuidForType(typeof(SVsCmdNameMapping)); string progID = string.Format(CultureInfo.InvariantCulture, "{0:B}", guid); int hResult = NativeMethods.CreateItemMoniker(delim, progID, out moniker); return(moniker); }
public void InsertImageDataObject(ImageDataObject ido, int position) { if (ido == null) { return; } ILockBytes pLockBytes; int sc = CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes); IStorage pStorage; sc = StgCreateDocfileOnILockBytes(pLockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE | STGM.STGM_READWRITE), 0, out pStorage); IOleClientSite pOleClientSite; IRichEditOle.GetClientSite(out pOleClientSite); Guid guid = Marshal.GenerateGuidForType(ido.GetType()); Guid IID_IOleObject = new Guid("{00000112-0000-0000-C000-000000000046}"); Guid IID_IDataObject = new Guid("{0000010e-0000-0000-C000-000000000046}"); Guid IID_IUnknown = new Guid("{00000000-0000-0000-C000-000000000046}"); object pOleObject; int hr = OleCreateStaticFromData(ido, ref IID_IOleObject, (uint)OLERENDER.OLERENDER_FORMAT, ref ido._Formatetc, pOleClientSite, pStorage, out pOleObject); if (pOleObject == null) { return; } OleSetContainedObject(pOleObject, true); REOBJECT reoObject = new REOBJECT(); reoObject.cp = position; reoObject.clsid = guid; reoObject.pstg = pStorage; reoObject.poleobj = Marshal.GetIUnknownForObject(pOleObject); reoObject.polesite = pOleClientSite; reoObject.dvAspect = (uint)(DVASPECT.DVASPECT_CONTENT); reoObject.dwFlags = (uint)(REOOBJECTFLAGS.REO_BELOWBASELINE); reoObject.dwUser = 0; this.IRichEditOle.InsertObject(reoObject); Marshal.ReleaseComObject(pLockBytes); Marshal.ReleaseComObject(pOleClientSite); Marshal.ReleaseComObject(pStorage); Marshal.ReleaseComObject(pOleObject); }