public void SetSite(object pUnkSite)
        {
            // Release previous COM objects.
            if (this.site != null)
            {
                Marshal.ReleaseComObject(this.site);
            }
            if (this.explorer != null)
            {
                Marshal.ReleaseComObject(this.explorer);
                this.explorer = null;
            }

            // pUnkSite is a pointer to object that implements IOleWindowSite.
            this.site = pUnkSite as NativeMethods.IInputObjectSite;

            if (this.site != null)
            {
                // The site implements IServiceProvider interface and can be used to
                // get InternetExplorer instance.
                var  provider = this.site as NativeMethods._IServiceProvider;
                Guid guid     = new Guid("{0002DF05-0000-0000-C000-000000000046}");
                Guid riid     = new Guid("{00000000-0000-0000-C000-000000000046}");
                try
                {
                    object webBrowser;
                    provider.QueryService(ref guid, ref riid, out webBrowser);
                    this.explorer = webBrowser as InternetExplorer;
                }
                catch (COMException)
                {
                }
            }
        }
Esempio n. 2
0
        public void SetSite(object pUnkSite)
        {
            // 释放之前的COM对象。
            if (this.site != null)
            {
                Marshal.ReleaseComObject(this.site);
            }
            if (this.explorer != null)
            {
                Marshal.ReleaseComObject(this.explorer);
                this.explorer = null;
            }

            // pUnkSite是一个实现IOleWindowSite对象的指针。
            this.site = pUnkSite as NativeMethods.IInputObjectSite;

            if (this.site != null)
            {
                // site实现了IServiceProvider接口并可以被用来获取InternetExplorer实例。
                var  provider = this.site as NativeMethods._IServiceProvider;
                Guid guid     = new Guid("{0002DF05-0000-0000-C000-000000000046}");
                Guid riid     = new Guid("{00000000-0000-0000-C000-000000000046}");
                try
                {
                    object webBrowser;
                    provider.QueryService(ref guid, ref riid, out webBrowser);
                    this.explorer = webBrowser as InternetExplorer;
                }
                catch (COMException)
                {
                }
            }
        }
        public void SetSite(object pUnkSite)
        {
            // 释放之前的COM对象。
            if (this.site != null)
            {
                Marshal.ReleaseComObject(this.site);
            }
            if (this.explorer != null)
            {
                Marshal.ReleaseComObject(this.explorer);
                this.explorer = null;
            }

            // pUnkSite是一个实现IOleWindowSite对象的指针。
            this.site = pUnkSite as NativeMethods.IInputObjectSite;

            if (this.site != null)
            {

                // site实现了IServiceProvider接口并可以被用来获取InternetExplorer实例。
                var provider = this.site as NativeMethods._IServiceProvider;
                Guid guid = new Guid("{0002DF05-0000-0000-C000-000000000046}");
                Guid riid = new Guid("{00000000-0000-0000-C000-000000000046}");
                try
                {
                    object webBrowser;
                    provider.QueryService(ref guid, ref riid, out webBrowser);
                    this.explorer = webBrowser as InternetExplorer;
                }
                catch (COMException)
                {
                }
            }
        }
        public void SetSite(object pUnkSite)
        {
            // Release previous COM objects.
            if (this.site != null)
            {
                Marshal.ReleaseComObject(this.site);
            }
            if (this.explorer != null)
            {
                Marshal.ReleaseComObject(this.explorer);
                this.explorer = null;
            }

            // pUnkSite is a pointer to object that implements IOleWindowSite.
            this.site = pUnkSite as NativeMethods.IInputObjectSite;

            if (this.site != null)
            {

                // The site implements IServiceProvider interface and can be used to
                // get InternetExplorer instance.
                var provider = this.site as NativeMethods._IServiceProvider;
                Guid guid = new Guid("{0002DF05-0000-0000-C000-000000000046}");
                Guid riid = new Guid("{00000000-0000-0000-C000-000000000046}");
                try
                {
                    object webBrowser;
                    provider.QueryService(ref guid, ref riid, out webBrowser);
                    this.explorer = webBrowser as InternetExplorer;
                }
                catch (COMException)
                {
                }
            }
        }