Here is a WPF workaround.
MainWindow.xaml:
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=system.windows.forms" > <Grid> <WebBrowser x:Name="webBrowser" SnapsToDevicePixels="True" > </WebBrowser> </Grid> </Window>
MainWindow.xaml.cs:
public void Run(Uri uri) { m_gateway = new HostGateway { MyComponent = SomeNativeLib.SomeNativeComponent }; webBrowser.ObjectForScripting = m_gateway; webBrowser.Navigate("about:blank"); webBrowser.Navigate(uri); } [ComVisible(true)] public class HostGateway { public SomeNativeLib.SomeNativeComponent MyComponent {get;set;} }
And we need to add our own lib as a reference:
<Reference Include="SomeNativeLib, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <EmbedInteropTypes>True</EmbedInteropTypes> <HintPath>..\..\..\References\SomeNativeLib.dll</HintPath> </Reference>
Then, in our client, the js code we will need to access the HostGateway instance through window.external:
window.external.MyComponent.foo();
source share