开发者

ObjectForScripting with multiple Interfaces not working

I have a WinForm which interacts with a WebBrowserControl through the ObjectForScripting. The baseclass of my WinForm is not ComVisible and I can not or will not change it. Because there is a NonComVisibleBaseClass I have created an Interface and set开发者_开发百科 it ComVisible(true) and set the FormAttribute [ClassInterface(ClassInterfaceType.None)]. The methods in the Interface can be called by the JavaScript. And it works perfect:

//Make the class visible for COM so we can set the ObjectForScripting
//Specify ClassInterfaceType.None to use the ComVisible Interface
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public partial class GeekBrowser : GeekBasePage, IMapControlInteractable
...
public class GeekBasePage : System.Windows.Forms.Form
...
[ComVisible(true)]
public interface IMapControlInteractable

But now my problem. The Interface contains multiple functions. I want to separate Interfaces for separate task groupings. So I want an Interface which contains Logging functions and an Interface for DataAccess functions and so on.

So it would be something like:

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public partial class GeekBrowser : GeekBasePage, IDataAccess, ILogging
...
public class GeekBasePage : System.Windows.Forms.Form
...
[ComVisible(true)]
public interface IDataAccess
...
[ComVisible(true)]
public interface ILogging

But when I do this the functions of the second Interface (ILogging) are not accessible from the Javascript. If I switch the order of the interfaces the IDataAccess functions are not accessible.

So it seems to be the case that only methods from the first Interface are accessible in Javascript.

What can I do to make every function of each Interface accessible? Once again, making the BaseClass ComVisible and deleting the ClassInterface attribute will work but is not an option.

Thanks in advance!!


When doing a similar project, we found that JavaScript was only able to access the default interface of the generate COM wrapper, in your case it is picking the first ComVisible interface it finds as the default one, since you are not explicitly setting the default interface attribute. The problem is that JavaScript has no QueryInterface analogue.

To get access to the other interfaces we need to create our own version of QueryInterface for JavaScript, either by providing an explicit cast-type function in the default interface (not so elegant) or having a separate object that can perform the conversion to the correct ComVisible interface type.

Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜