Exemple #1
0
        public void AddComObject()
        {
            TextInputDialog dialog = new TextInputDialog(
                "Add COM object",
                "CLSID or ProgID of COM object:",
                "Enter the CLSID (eg '{0002DF01-0000-0000-C000-000000000046}')\r\n" +
                "or ProgID (eg 'InternetExplorer.Application') of the COM object to create and\r\n" +
                "provide to the WebView as `window.chrome.remoteObjects.example`.",
                "InternetExplorer.Application",
                false);

            if (dialog.ShowDialog() == true)
            {
                Type type = Type.GetTypeFromProgID(dialog.Input, false);
                if (type == null)
                {
                    try
                    {
                        Guid guid = new Guid(dialog.Input);

                        type = Type.GetTypeFromCLSID(guid, false);
                    }
                    catch (Exception) { }
                }
                if (type != null)
                {
                    _remoteObject = Activator.CreateInstance(type);
                    _webView2.AddRemoteObject("example", ref _remoteObject);
                }
                else
                {
                    CommonDialogs.ShowError("Coudn't create COM object.");
                }
            }
        }
Exemple #2
0
        private void _webView2_NavigationStarting(object sender, Wrapper.NavigationStartingEventArgs e)
        {
            string navigationTargetUri = e.Uri;

            if (_sampleUri == navigationTargetUri)
            {
                //! [AddRemoteObject]
                //                _remoteObject = new RemoteObjectSampleNet();

                string progId  = "RemoteComObjectImpl.1";
                Type   comType = Type.GetTypeFromProgID(progId, true);
                //Guid clsId = new Guid("19C0E72A-9D34-4F10-A92E-1119F53D1645");
                //Type comType = Type.GetTypeFromCLSID(clsId, true);
                _remoteObject = Activator.CreateInstance(comType);

                //                VARIANT remoteObjectAsVariant = { };
                //                m_remoteObject.query_to<IDispatch>(&remoteObjectAsVariant.pdispVal);
                //                remoteObjectAsVariant.vt = VT_DISPATCH;

                // We can call AddRemoteObject multiple times in a row without
                // calling RemoveRemoteObject first. This will replace the previous object
                // with the new object. In our case this is the same object and everything
                // is fine.
                _webView2.AddRemoteObject("sample", ref _remoteObject);
//                remoteObjectAsVariant.pdispVal->Release();
                //! [AddRemoteObject]
            }
            else
            {
                // We can call RemoveRemoteObject multiple times in a row without
                // calling AddRemoteObject first. This will produce an error result
                // so we ignore the failure.
                _webView2.RemoveRemoteObject("sample");

                // When we navigate elsewhere we're off of the sample
                // scenario page and so should remove the scenario.
                _parent.DeleteComponent(this);
            }
        }