ObjectForScripting with multiple interfaces does not work

I have a WinForm that interacts with WebBrowserControl through ObjectForScripting. The base field of my WinForm is not ComVisible, and I cannot change it or not change it. Since NonComVisibleBaseClass exists, I created the interface and installed it ComVisible (true) and set FormAttribute [ClassInterface (ClassInterfaceType.None)]. Methods in the interface can be called by JavaScript. And it works great:

//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 several functions. I want to separate interfaces for separate task groups. So I need an interface that contains logging functions and an interface for DataAccess functions, etc.

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

, (ILogging) Javascript. , IDataAccess .

, , Javascript .

, ? , BaseClass ComVisible ClassInterface , .

!

+3
1

, JavaScript COM-, ComVisible, , . , JavaScript QueryInterface.

, QueryInterface JavaScript, cast-type ( ), , ComVisible.

, !

+1

Source: https://habr.com/ru/post/1794116/


All Articles