public static void UnregisterTemporaryProtocolHandler(Type protocolHandlerClass, string protocol) { if (protocolHandlerClass == null) { throw new ArgumentNullException("protocolHandlerClass"); } lock ( temporaryHandlerCFList ) { HandlerAndProtocol token = new HandlerAndProtocol(protocolHandlerClass, protocol); IntPtr handlerCF; if (temporaryHandlerCFList[token] == null) { throw new InvalidOperationException(string.Format( "Protocol handler is not registered.", protocolHandlerClass.FullName)); } else { handlerCF = (IntPtr)temporaryHandlerCFList[token]; } NativeMethods.IInternetSession session = GetSession(); try { session.UnregisterNameSpace( handlerCF, token.Protocol); } finally { Marshal.ReleaseComObject(session); session = null; } temporaryHandlerCFList[token] = null; } }
public static void RegisterTemporaryProtocolHandler(Type protocolHandlerClass, string protocol) { if( protocolHandlerClass==null ) throw new ArgumentNullException("protocolHandlerClass"); lock( temporaryHandlerCFList ) { HandlerAndProtocol token=new HandlerAndProtocol(protocolHandlerClass,protocol); if( temporaryHandlerCFList[token]!=null ) throw new InvalidOperationException(string.Format( "Handler for this protocol already registered.", protocolHandlerClass.FullName )); CheckHandlerType(protocolHandlerClass); Guid handlerGuid=protocolHandlerClass.GUID; Guid iid_IUknown=NativeMethods.IID_IUnknown; Guid iid=NativeMethods.IID_IClassFactory; IntPtr handlerCF; int hResult=NativeMethods.DllGetClassObject( ref handlerGuid, ref iid, out handlerCF ); Marshal.ThrowExceptionForHR(hResult); if( handlerCF==IntPtr.Zero ) { RegistryKey inprocServer32=Registry.ClassesRoot.OpenSubKey( @"CLSID\"+protocolHandlerClass.GUID.ToString("B")+@"\InprocServer32" ); if( inprocServer32==null || (inprocServer32.GetValue(null)+"").ToLower()!="mscoree.dll" || (inprocServer32.GetValue("Assembly")+"")=="" || (inprocServer32.GetValue("Class")+"")=="" ) throw new InvalidOperationException( "Class seems to be not registered." ); else throw new ExternalException( "DllGetClassObject failed.", hResult ); } string emptyStr=null; NativeMethods.IInternetSession session=GetSession(); try { session.RegisterNameSpace( handlerCF, ref handlerGuid, protocol, 0, ref emptyStr, 0 ); } finally { Marshal.ReleaseComObject(session); session=null; } temporaryHandlerCFList[token]=handlerCF; } }
public static void UnregisterTemporaryProtocolHandler(Type protocolHandlerClass,string protocol) { if( protocolHandlerClass==null ) throw new ArgumentNullException("protocolHandlerClass"); lock( temporaryHandlerCFList ) { HandlerAndProtocol token=new HandlerAndProtocol(protocolHandlerClass,protocol); IntPtr handlerCF; if( temporaryHandlerCFList[token]==null ) throw new InvalidOperationException(string.Format( "Protocol handler is not registered.", protocolHandlerClass.FullName )); else handlerCF=(IntPtr)temporaryHandlerCFList[token]; NativeMethods.IInternetSession session=GetSession(); try { session.UnregisterNameSpace( handlerCF, token.Protocol ); } finally { Marshal.ReleaseComObject(session); session=null; } temporaryHandlerCFList[token]=null; } }
public static void RegisterTemporaryProtocolHandler(Type protocolHandlerClass, string protocol) { if (protocolHandlerClass == null) { throw new ArgumentNullException("protocolHandlerClass"); } lock ( temporaryHandlerCFList ) { HandlerAndProtocol token = new HandlerAndProtocol(protocolHandlerClass, protocol); if (temporaryHandlerCFList[token] != null) { throw new InvalidOperationException(string.Format( "Handler for this protocol already registered.", protocolHandlerClass.FullName)); } CheckHandlerType(protocolHandlerClass); Guid handlerGuid = protocolHandlerClass.GUID; Guid iid_IUknown = NativeMethods.IID_IUnknown; Guid iid = NativeMethods.IID_IClassFactory; IntPtr handlerCF; int hResult = NativeMethods.DllGetClassObject( ref handlerGuid, ref iid, out handlerCF); Marshal.ThrowExceptionForHR(hResult); if (handlerCF == IntPtr.Zero) { RegistryKey inprocServer32 = Registry.ClassesRoot.OpenSubKey( @"CLSID\" + protocolHandlerClass.GUID.ToString("B") + @"\InprocServer32"); if (inprocServer32 == null || (inprocServer32.GetValue(null) + "").ToLower() != "mscoree.dll" || (inprocServer32.GetValue("Assembly") + "") == "" || (inprocServer32.GetValue("Class") + "") == "") { throw new InvalidOperationException( "Class seems to be not registered."); } else { throw new ExternalException( "DllGetClassObject failed.", hResult); } } string emptyStr = null; NativeMethods.IInternetSession session = GetSession(); try { session.RegisterNameSpace( handlerCF, ref handlerGuid, protocol, 0, ref emptyStr, 0); } finally { Marshal.ReleaseComObject(session); session = null; } temporaryHandlerCFList[token] = handlerCF; } }