简体   繁体   English

如何获取可以在浏览器外部传递的JavaScript中的对象(COM)的引用

[英]How to get a reference to an object (COM) in JavaScript that can be passed outside the browser

I have a hyrid type application (web and forms). 我有一个hyrid类型的应用程序(Web和表单)。 It's a .net compact framework app. 这是一个.net紧凑框架应用程序。 On one of the forms I have a WebBrowser control. 在其中一种形式上,我有一个WebBrowser控件。

I want to communicate between the WebBrowser control and the form that host/contains the WebBrowser control. 我想在WebBrowser控件和承载/包含WebBrowser控件的表单之间进行通信。

To do this I plan to create an Activex (COM) object in C++ compiled for the windows mobile device. 为此,我计划为Windows移动设备使用C ++创建一个Activex(COM)对象。

I plan to use JavaScript to create an instance of the ActiveX control on the web page that is displayed in the WebBrowser control. 我计划使用JavaScript在WebBrowser控件中显示的网页上创建ActiveX控件的实例。

How can I get a reference to this ActiveX control that I can then send to the form? 如何获得对该ActiveX控件的引用,然后将其发送到表单?


My objective is to send a reference of the ActiveX control instance to the windows mobile form that contains the WebBrowser control so that both the web page and form can use/access the same instance of the ActiveX control. 我的目标是将ActiveX控件实例的引用发送到包含WebBrowser控件的Windows Mobile表单,以便网页和表单都可以使用/访问ActiveX控件的同一实例。

I created a way to send strings from the ActiveX control to the form. 我创建了一种将字符串从ActiveX控件发送到表单的方法。 Is there a way to convert a reference of the ActiveX control to a string then pass the string to the form and re-create a reference to the object instance on the form side? 有没有一种方法可以将ActiveX控件的引用转换为字符串,然后将字符串传递给表单,然后在表单一侧重新创建对对象实例的引用?

I hope this makes sense. 我希望这是有道理的。

You can get an IDispatch reference to the window using something like this: 您可以使用以下方式获取对该窗口的IDispatch引用:

CComPtr<IWebBrowser2> m_webBrowser(/* create, assign, whatever to get the pointer */
CComQIPtr<IHTMLWindow2> m_htmlWin;
CComPtr<IDispatch> m_htmlDocDisp;
CComQIPtr<IDispatch> m_htmlWindDisp;

m_webBrowser->get_Document(&m_htmlDocDisp);
CComQIPtr<IHTMLDocument2> doc(m_htmlDocDisp);
assert(doc);
doc->get_parentWindow(&m_htmlWin);
assert(m_htmlWin);

m_htmlWindDisp = m_htmlWin;
assert(m_htmlWin);

Once you have that, you can use IDispatch methods to either query the value of a property on the window object or you can set the value of such a property. 一旦有了该属性,就可以使用IDispatch方法查询窗口对象上的属性值,或者可以设置此类属性的值。 For example, if you create an IDispatch object that exposes methods and properties then you use the m_htmlWindDisp object to Invoke with PROPERTYPUTREF that object as "foo" then you could access that object from javascript using "window.foo". 例如,如果创建一个公开方法和属性的IDispatch对象,则可以使用m_htmlWindDisp对象以PROPERTYPUTREF将该对象作为“ foo”调用,然后可以使用“ window.foo”从javascript访问该对象。 Alternatley, using Invoke with PROPERTYGET you can get the IDispatch handle for an object that you set on window, such as "window.foo = someFooBaredObject" Alternatley,将Invoke与PROPERTYGET结合使用,可以获得在窗口上设置的对象的IDispatch句柄,例如“ window.foo = someFooBaredObject”

Hope that makes sense. 希望有道理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript是否可以从浏览器外部进行选择? - Can Javascript get a selection from outside the browser? 通过引用传递给JavaScript中的COM对象 - Pass by reference to COM object in JavaScript 您如何在使用JavaScript创建的自定义对象之外引用自定义对象? - How do you reference a custom object outside of the function it was created in with JavaScript? jQuery / Javascript:如何获取匿名函数以引用外部变量? - jQuery/Javascript: How to get anonymous function to reference variable declare outside? Javascript-返回通过引用传递的修改对象 - Javascript - Return modified object passed by reference 当我将对象传递给JavaScript函数时,该对象是否通过引用传递? - When I pass an object to a JavaScript function does that object get passed by reference? 如何捕捉浏览器外的点击 - Javascript - How can I catch the click outside the browser - Javascript 如何获取javascript对象引用或引用计数? - How to get javascript object references or reference count? 我如何从angular之外的javascript函数中获取angular js创建的对象的实例 - How can i get an instance of object created by angular js from javascript function outside angular 如何在我的对象中获取跨浏览器ajax参考 - how to get the cross browser ajax reference within my object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM