public static object QueryInterface(object obj, Guid iid) { if (obj == null) { return(null); } // get an nsISupports (aka IUnknown) pointer from the objection IntPtr pUnk = Marshal.GetIUnknownForObject(obj); if (pUnk == IntPtr.Zero) { return(null); } // query interface IntPtr ppv; Marshal.QueryInterface(pUnk, ref iid, out ppv); // if QueryInterface didn't work, try using nsIInterfaceRequestor instead if (ppv == IntPtr.Zero) { // QueryInterface the object for nsIInterfaceRequestor Guid interfaceRequestorIID = typeof(nsIInterfaceRequestor).GUID; IntPtr pInterfaceRequestor; Marshal.QueryInterface(pUnk, ref interfaceRequestorIID, out pInterfaceRequestor); // if we got a pointer to nsIInterfaceRequestor if (pInterfaceRequestor != IntPtr.Zero) { // convert it to a managed interface nsIInterfaceRequestor req = (nsIInterfaceRequestor)Marshal.GetObjectForIUnknown(pInterfaceRequestor); // try to get the requested interface ppv = req.GetInterface(ref iid); // clean up Marshal.ReleaseComObject(req); Marshal.Release(pInterfaceRequestor); } } object result = (ppv != IntPtr.Zero) ? Marshal.GetObjectForIUnknown(ppv) : null; Marshal.Release(pUnk); if (ppv != IntPtr.Zero) { Marshal.Release(ppv); } return(result); }
private static object GetInterface(nsIInterfaceRequestor requestor, Guid iid) { IntPtr ppv = IntPtr.Zero; try { ppv = requestor.GetInterface(ref iid); } catch (Exception ex) { Debug.WriteLine("Exception \n" + ex.ToString()); } object result = (ppv != IntPtr.Zero) ? GetObjectForIUnknown(ppv) : null; int count = Marshal.Release(ppv); return(result); }
private static object GetInterface(nsIInterfaceRequestor requestor, Guid iid) { IntPtr ppv = IntPtr.Zero; try { ppv = requestor.GetInterface(ref iid); } catch (Exception ex) { GeckoFxCoreCatalogApi.Logging.Exception(ex); } object result = (ppv != IntPtr.Zero) ? GetObjectForIUnknown(ppv) : null; int count = Marshal.Release(ppv); return(result); }
public static nsIInterfaceRequestor GetProxy (Mono.WebBrowser.IWebBrowser control, nsIInterfaceRequestor obj) { object o = Base.GetProxyForObject (control, typeof(nsIInterfaceRequestor).GUID, obj); return o as nsIInterfaceRequestor; }
public static TInterfaceType GetInterface <TInterfaceType>(this nsIInterfaceRequestor requestor) { return(( TInterfaceType )GetInterface(requestor, typeof(TInterfaceType).GUID)); }
public static nsIInterfaceRequestor GetProxy(Mono.WebBrowser.IWebBrowser control, nsIInterfaceRequestor obj) { object o = Base.GetProxyForObject(control, typeof(nsIInterfaceRequestor).GUID, obj); return(o as nsIInterfaceRequestor); }
public nsIStreamListener DoContent(nsACStringBase aMimeContentType, nsIRequest aRequest, nsIInterfaceRequestor aWindowContext, bool aForceSave) { var request = Request.CreateRequest(aRequest); var lChannel = request as HttpChannel; try { if (lChannel != null) { var uri = lChannel.OriginalUri; var contentType = lChannel.ContentType; var contentLength = lChannel.ContentLength; var dispositionFilename = lChannel.ContentDispositionFilename; // Do your contenttype validation, keeping only what you need. // Make sure you clean dispositionFilename before using it. // If you don't want to do anything with that file, you can return null; return(new MyStreamListener(/* ... */)); } } catch (COMException) { /* ... */ } return(null); }