Can I use Silverlight in an ActiveX Control? - silverlight

I would like to create an ActiveX control that uses Silverlight. Is this possible/sensible and does anyone have an sample code for this?
I am working in a legacy (non web) system that cannot directly use WPF/Silverlight controls. But the system can access ActiveX controls. The thought is that we may be able to host Silverlight in an ActiveX control, and therefore update our rather dated UI.

Read this article.
Silverlight COM Ref.
The article indicates activeX controls in 'agcore.dll' On windows it is actually imported through 'npctrl.dll'.
you compile may have some sort of activex control wizard.
EDIT: With that said. It might be as easy to host IWebBrowser in an activeX control and embedd silvelight into the browser control from local storage via 'xaml'.

Related

Can i use Activex with silverlight4?

I need to use a ActiveX control in my silverlight application. After some research i found out a few ways in which a silverlight app can use ActiveX control
Use ActiveX control in a webpage along with silverlight plugin and use javascript for interaction between silverlight and activex.
Use a webbrowser control in silverlight 4 and load the webpage containing activex in webbrowser control.
Is there any other way that can utilized to embed activex control in silverlight app. I read somewhere that silverlight 4 has support for COM components. Can silverlight4 provide support for embedding activex control in a silverlight app.
Any help on this is highly appreciated and if some samples/documentation link is there that would be great.
Thanks in advance.
Silverlight does have support for COM automation servers like those used with Microsoft Office. It doesn't have general support for COM though and even if it did, ActiveX controls have very specific hosting requirements.
The idea of using the browser control is a possibility, but it will introduce some significant limitations. For one, you cant use the WebBrowser control in Silverlight unless you're running in out-of-browser mode which means your users would have to take steps to install the Silverlight application.
Additionally, the WebBrowser control (including any ActiveX controls it contains) will always render above your Silverlight content and won't be able to participate in transforms, animations, styling, etc. In other words it will stick out like a sore thumb.
What kind of control is it? Perhaps there is an alternative?

How to use WinForms/WPF as ActiveX control?

I would like to use WinForms/WPF controls as if they were ActiveX controls.
Specifically I would like to host these controls inside SAP Business One or it may be outside
of SAP B1.
Is this possible at all? If yes, I would like to see some examples.
Thanks in advance,
Yes, it's possible. The machine running SAP Business One will still need the .NET framework, of course, but yes, you can expose your controls as ActiveX objects.
Have a look at this article: WPF Vista Gadgets using ActiveX. Referenced in that article is a sample WPF ActiveX control. That should get you started.

Using ActiveX control in WPF

I'm attempting to host an ActiveX control in a WPF app. After attempting to use existing info on the web and here, I've hit a dead-end.
I need to use an ActiveX control provided to communicate with a UV power meter. They provide an application that registers and uses the control and even includes some useful demo apps. I stripped out the OCX file and put it here if needed. You won't have the power meter to talk to, but the app and demos will still load the ActiveX control successfully.
I created a simple Windows Forms application. I was able to bring the ActiveX control into the toolbar, drop it into my form, and everything is fine. The demo apps they provide do this as well.
However, getting this to work in a WPF environment is another story. The control can't be added to the toolbox and "dragged" into the app.
So far I've tried two techniques:
Technique found here. I am able to add a reference to the control, but then I enter namespace hell. The xmlns:ax namespace it suggests making cannot find the information. Here's my attempt based on what the object viewer tells me: xmlns:ax="clr-namespace:OphirUsbXLib;assembly=Interop.OphirUsbXLib"
Technique found here. This is essentially to create a new project that creates a library based on Windows Forms, which contains the ActiveX control (yikes). I am able to add the Windows Forms Host, but I cannot get access to the ActiveX control within. I can make the control public, but I still cannot call methods etc. This doesn't look like the right solution.
In short, I have an ActiveX control that works beautifully in Forms, but is a real bitch to get working in WPF.
Any insight is appreciated!
In this situation I would consider making a WinForms usercontrol which wraps the ActiveX control you are trying to use.
You could make public properties and methods which expose each of the required properties and methods on the ActiveX control, and then host this WinForms UC on the in a WPF WinFormsHost control.
I have already done something similar to this, in reverse, hosting a WPF UserControl in a WinForms UserControl, then hosting that on a VB6 Form in a legacy application.

Silverlight and COM Interop

What are my options for interacting with a COM control from silverlight?
In my particular project, I have a legacy ActiveX authentication control which I would like to leverage in my silverlight application. Without too many boring details, the control takes a couple of parameters, prompts the user for credentials or tokens, and raises events. I need to set the parameters from my control, and somehow get the events' data to my control.
Furthermore, I would like to get the UI to seem as homogeneous as possible.
What are the best ways of doing this?
Silverlight 4 Beta was announced to have COM Interop for Trusted Applications.
More information on the Tim Heuer blog: http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx#com
IIRC, Silverlight doesn't provide any way work with COM directly - there's no P/Invoke nor COM Interop - and the sandbox wouldn't allow you to do that in any case. However, you could host ActiveX control in the browser alongside your Silverlight application (which obviously restricts this to IE only), and then write some in-browser JavaScript glue to work with it - JavaScript can interact with both ActiveX and Silverlight.
I don't think you can reasonably host an ActiveX control inside your Silverlight application, however. The closest you can do is as described above, but position ActiveX control (in browser DOM) on top if Silverlight canvas in the right spot, so it looks like a single UI. Not sure if this will not produce any rendering artifacts, however.

Is any source code available that has an Active X control hosted in WPF?

I am looking for some source code and a project to download and look at that has an Active X control hosting WPF. I can not find any source code anywhere on the net.
I can not add a WPF resource the usual way in an Active X control. I have to add it manually to the reference section.
Not sure if this is even possible. I would check out WPF browser applications. That may be a better solution for you given that if you are going to be running an active x control with WPF the user will need 1) Internet Explorer and 2) .net 3.0+ installed locally. A WPF Browser application will work with IE if the user has .net 3.0+ installed and will work with IE and FireFox if the user has .net 3.5+ installed. Check out WPF Broswer Apps here: http://msdn.microsoft.com/en-us/library/aa970060.aspx
It should be possible, although I don't have the code for it off-hand. You can create an HwndSource, which allows a normal window to host WPF controls, in your ActiveX controls. Then it is only a matter of adding your WPF UI to that window.

Resources