Silverlight vs. ActiveX: Give me automation or give me death!

by Jon 1/8/2008 6:49:00 PM

In the wonderful IE4 days when ActiveX was the big new thing, you could create an ActiveX control -- that is, a first class COM object - in full Visual Basic. In fact, Microsoft released a free version of Visual Basic just for creating ActiveX controls. It was ridiculously easy to create COM objects in this way.

Then you could instantiate the object in the browser scripting engine and do things like:

<script>
myActiveXObject.HtmlDocument = document;go
</script>

With that one line of code, (popping knuckles) the full-blown Visual Basic programming environment had access to the Internet Explorer web browser document object. There was no wrapper, just a COM interface!!

Visual Basic:

Call Me.HtmlDocument.window.eval("alert(""Hello from full-blown Visual Basic via the browser's Javascript scripting engine"");")

Me.HtmlDocument.body.innerHTML = "<h3>Muahahaha!</h3>" & Me.HtmlDocument.body.innerHTML
Me.HtmlDocument.body.style.backgroundColor = "#00000"
Me.HtmlDocument.body.style.color = "#ffffff"

Call Me.PlayVideo()

' etc.

Likewise, the COM interfaces of the ActiveX control were directly and effortlessly exposed to the browser Javascript runtime.

<script>
myActiveXObject.PlayVideo();
</script>

This opened all kinds of doors of opportunity. Event sinks and controllers could be dropped in every which way. Flexibility of writing code was virtually limitless.

This WAS doable before Microsoft abandoned Visual COM (Visual Basic 4/5/6). The ActiveX Script runtime engine was a marvelous invention. I'll admit that it's proprietary to Internet Explorer, though, but Mozilla has traditionally supported COM in some fashion. I don't know how Mozilla's plug-in and scripting runtime integrations work.

Fast forward to today. Rich client applications are now written in Javascript and AJAX, making use of only one specialized COM object (or other automation object, depending on the browser) now known today as XMLHttpRequest. Rich client apps also make heavy use of objects-based programming.

In order to create user experiences that are outside of the capabilities of Dynamic HTML, plug-ins are still used. This is where plug-ins like Silverlight come in. But those plug-ins, especially when they have broad and powerful runtimes like Flash (ActionScript) or Silverlight (CLR), need to be able to be interopable with the browser's script runtime in order for utilization to be fully realized. In the Internet Explorer world, the answer to this was simply IUnknown / COM / ActiveX.

Browser Javascript objects and logic need to be able to interact with plug-in runtime objects and logic and vice-versa.

ActiveX componentization is now virtually deprecated. Microsoft no longer sells nor supports Visual COM (Visual Basic 4/5/6, which was the only tool Microsoft ever created to allow users to be able to effortlessly create COM objects). ActiveX controls are also a security concern, and in Internet Explorer 7, users are discouraged from installing them.

But what I'm looking for is unwrapped interop support between the Silverlight CLR and the browser's runtime. Silverlight doesn’t have access to the Javascript DOM. It has access to a limited set of objects and properties of the HTML DOM using a wrapper API.

http://silverlight.net/QuickStarts/Dom/DomAccess.aspx

The CLR in Silverlight introduces a secure but powerful runtime engine to the web environment and an extent of sophistication that previously never existed, not even with old Visual COM (Visual Basic 4/5/6). Now that Silverlight 2.0 is coming out soon with a rich programmatic runtime like Visual COM (VB) used to have, I’d like rich COM automation back. The value is more fully realized when you can pass browser Javascript objects to the CLR or pass CLR-declared objects to the browser Javascript runtime.

(I'll post better examples of what used to work versus what doesn't work later this week. But yes, full COM interop was possible between VB and ActiveX Scripting, and yes you could pass objects back and forth. It even supported dynamically generated COM interfaces. For example, you could declare and instantiate a class in VBScript in the browser, pass the instance to a method on an ActiveX control written in VB where the VB OCX property expects a Variant, and then VB OCX could call upon the functions within that class.)

Obviously, what this means is that Safari, Mozilla, and Microsoft would have to agree on an interop strategy. I thought they had already accomplished this, but it'd be surprising to me if they didn't. It would, however, further cement my frustrations with Microsoft that they allowed too many years to go by without staying involved with the browser standards communities like W3C and ECMA to work those issues out.

ActiveX componentization is not deprecated because COM is a security concern. It is deprecated because the technologies that implemented ActiveX were not sandboxed like Java applets, Flash, and Silverlight are. The Silverlight CLR is neatly sandboxed--this means that there are no longer serious security concerns that developers otherwise had with the ActiveX plug-in support--so if security is a concern, it shouldn't be.

But, practically speaking, browser Javascript objects and logic need to be able to interact with plug-in runtime objects and logic and vice-versa. Put as succinctly as I can, if I cannot declare a function in the browser script with parameters, and call on it from the CLR while passing CLR objects, I feel stuck with preferring old ActiveX over the Silverlight CLR for dynamicizing HTML. The same is true going the other way. The way things are right now, it's an all-or-nothing deal--either you completely rewrite the AJAX web application so that it no longer users the browser Javascript and uses the Silverlight CLR, or you don't use the Silverlight CLR and stick with the browser Javascript. These two options are completely unrealistic, from a business perspective.

Microsoft's position on this matter has so far been that they think the "wish is valid, but it is challenging since we are dealing with a scripting world, a native world and a managed world all in one wish."

I'm sure it is challenging. But this and true DHTML are precisely why I thought Internet Explorer v4 was the greatest invention that came out of Redmond after the Windows NT kernel. It's why Internet Explorer had been Microsoft's preferred generic COM host for SDKs and development for many years.

I don't care if it is challenging. It was Microsoft who invented COM. It was Microsoft who implemented the ActiveX Scripting engine. It was Microsoft who invented the fully programmable browser DOM. It was Microsoft who invented .NET and the Visual Basic and C# languages. I have no doubt that the most profitable corporation on the planet can figure something out in this matter.

But this is an issue I have that goes beyond Silverlight, it is about Microsoft's leadership role in the Internet client software industry. It's like they fired their automation visionaries as soon as IE4 went gold.

Perhaps that isn't fair; the CLR is certainly quite visionary. It's just that the current state of things shows abandonment of the industry necessity to keep striving to bridge the gap between the browser script runtime and the plug-in runtime; this is a problem that has been around for over a decade, and that the industry leaders aren't still pushing for a cross-browser automation solution really befuddles me.

There is one "trick" that I can think of, though, to make window.eval() happen from Silverlight that may or may not work efficiently. Perhaps you can get Silverlight to change the text value of a hidden HTML element. This HTML element is strictly used for window.eval(). Javascript would need to be notified that the value changed. A setInterval loop? An onchange event hook? Dunno. But once it sees it it can fire it off and then populate some other hidden element for the eval result. I'd prototype this but I don't think onchange will work and a setInterval loop frightens me, not to mention only being able to use text (or XML) for params and return values. The whole idea seems terribly kludgy... Yuck.

kick it on DotNetKicks.com

Currently rated 4.3 by 4 people

  • Currently 4.25/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

Software Development | Microsoft Windows | Web Development

Related posts

Comments

1/7/2008 7:25:09 PM

sam

Been following this discussion on AZGROUPS. Can I add myself to the list of folks who would like some clarification? I would truly like to see a sentence - paragraph - whatever - that describes a real-world business problem - or at least a potential one. The sentence need not - in fact, should not - include the terms ActiveX, marshalling or COM. Instead - practically - what do you want to do that you are saying you cannot?

Without that - with all due respect - it's coming across as somewhat abstract, academic nitpicking where you're demanding Microsoft do a tremendous amount of work and move in a completely different direction to solve a problem you don't actually have.

sam us

1/7/2008 9:23:39 PM

Jon Davis

Javascript objects and logic need to interact with plug-in objects and logic and vice-versa.

Tell me, would you please explain what advantage there is in trying to add C# and the CLR to Silverlight when Silverlight already accomplishes most any task with Javascript automation? Can you provide a real-world business problem, or at least a potential one, for a need for C#? Without that, with all due respect, is coming across as somewhat abstract, academic nitpicking where you're demanding Microsoft do a tremendous amount of work and move in a completely different direction to solve a problem you don't actually have.

Alright that was rhetoric. But the fact is, Microsoft had a system and it worked fine--Visual COM (VB4/5/6) and ActiveX Scripting. Then they took that away. Then they spent millions upon millions of dollars developing .NET and then developing WPF and then developing Silverlight. But they never picked the ball back up that they dropped, which was abstract script-to-object, object-to-script automation.

Now Silverlight has the CLR and it's a scripting language of its own. Meanwhile, there are thousands upon thousands of AJAX web applications out there that may want to utilize Silverlight and transition from Javascript to C#. The way things are right now, it's an all-or-nothing deal--either you completely rewrite the AJAX web application so that it no longer users the browser Javascript and uses the Silverlight CLR, or you don't use the Silverlight CLR and stick with the browser Javascript. These two options are completely unrealistic, from a business perspective.

I hesitate to start too fast to describe scenarios because my description sounding abstract is with regard to absraction itself. COM's IUnknown interface spec and the old Variant includes a "reflection"-like mechanism that allowed VB and the like to call upon methods and properties that were not defined in a type library at compile time.

What you describe as "a tremendous amount of work" is rediculous -- the work has already been 80-90% done. My complaint is that Microsoft is on the COM abandonment track rather than recognizing the continual need for automation and respecting their older staff's prior work.

But as I explained in the edited post, I will post samples and scenarios later this week.

Jon Davis us

4/7/2008 1:04:44 AM

Daniel Bryars

I'd be interested in seeing your examples. I'm in a situation where we have an application written in Flash which talks to a variety of ActiveX components through a javascript (and sometimes vb script) layer. The ActiveX integrates with proprietry telephony hardware (phones, pbx's, diallers etc) - we'd really like to move to Silverlight. The business reason is that we think developing applications in flash will take much longer than in Silverlight (most of our staff our conversant in C# but not actionscript) and I believe this will become more and more so.

Daniel Bryars gb

4/7/2008 9:38:36 AM

Jon

@Daniel,

The specific example of being able to directly invoke objects and functions declared at runtime in VBScript from a COM object was not reproduceable. I'll have to retract that particular argument.

As for general support for scripting and Silerlight interop, I think I can survive on the Window.Eval() call-in and [silverlight].Content[public_function] call-back implementations.

www.jondavis.net/.../Silverlight---Weve-Got-WindowEval!!-Yay!!.aspx

Jon us

4/7/2008 9:43:06 AM

Jon

I'm not feeling well this morning. Frown Frown ... Seek out "We've got Window.Eval" on my blog site. If you got e-mailed for added comments, sorry for the spam.

Jon us

Add comment


(Will show your Gravatar icon)  

  Country flag





Live preview

11/21/2008 3:18:45 AM


 

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Jon Davis Jon Davis (aka "stimpy77") has been a programmer, developer, and consultant for web and Windows software solutions professionally since 1997, with experience ranging from OS and hardware support to DHTML programming to IIS/ASP web apps to Java network programming to Visual Basic applications to C# desktop apps.
 
Software in all forms is also his sole hobby, whether playing PC games or tinkering with programming them. "I was playing Defender on the Commodore 64," he reminisces, "when I decided at the age of 12 or so that I want to be a computer programmer when I grow up."
 
Jon is currently in a temp-to-perm contract with a media corporation that primarily produces B2B magazines. The insanely complete and powerful Content Management System that they are switching to is SiteCore CMS, which is arguably the richest and most complete ASP.NET 3.5 based CMS on the planet.
E-mail me Send mail

Most Recent of Many Library Investments

Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
346789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Pages

    Recent comments

    Authors

    Tags

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008

    Sign in