views:

1784

answers:

2

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?

+4  A: 

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.

Pavel Minaev
Thank you Pavel. This was what I was expecting, I was just hoping maybe there are other approaches I might have missed. I am not concerned that it's IE only, since that's the joy of working with ActiveX in the first place.
Except, that it's not quite true for the latest Silverlight; Silverlight 4 has COM interop now.
Robert P
+5  A: 

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

Red Knight