March 2006 - Posts

Workaround for IE7 object activation

Microsoft is changing the way ActiveX controls, and pretty much anything that offers a user interface inside the web browser, can be interacted with. This is mainly to avoid paying patent whores such as Eolas hundreds of millions of dollars for something they did not invent in the first place. Normally I would moan about a change such as this, but I applaud Microsoft for making this bold decision.
 
This change is already implemented in IE7, all IE6 users will automatically get this 'update' on the 11th of April 2006. Microsoft has posted a description of the changes and a workaround, but an easier solution is provided here.
 
 
Most of the approaches offered so far involve the use of DIV tags, innerHTML properties and a separate function for each object you want to insert. This is a mess so together with a friend, Balazs Molnar, I have come up with a simpler solution.
 
The first part of our solution is to create a single JavaScript file that contains the following function. We'll call this file createObject.js.
 
function createObject(objectDefinition)
{
    document.write(objectDefinition);
}

 
This function must be created in an external JavaScript file or it will not work. This must be one of the workarounds that invalidate the patent.
 
We can now insert any OBJECT, EMBED or APPLET element in our HTML code in almost the same way we did before. The only change is that we need to put a few extra quotes and a function call in our HTML.
 
... other HTML
  
  <script language="javascript">
   var objectDefinition = 
       '<object width="425" height="350">' +
       '   <param name="movie" value="http://www.youtube.com/v/jkqoPkuJaMI"></param>' +
       '   <embed src="http://www.youtube.com/v/jkqoPkuJaMI" type="application/x-shockwave-flash" width="425" height="350"></embed>' +
       '</object>';
   
   createObject(objectDefinition);
  </script>
 
... other HTML
 
The provided solution works fine in my copy of IE7b2  and is backwards compatible with IE6 as well as Firefox.
 
Check out this online sample of the method described here or download the code.
 
Alternative ways, all more complex than the solution offered here, are listed below.

Microsoft certified training for VS2005

I get enough traffic on this blog so maybe soeone can help me with the following:
 

 
All developers in my company need to qualify for all relevant .net exams. Some are starting on new exams but I would prefer it if they took the upgraded ones for VS2005.
 
Having looked at Microsoft's site it is not clear if these updated exams are available. Does anyone know if new versions of the following exams are avaialble?
  • 70–320: Developing XML Web Services and Server Components with Microsoft Visual C# and the Microsoft .NET Framework
  • 70–315: Developing and Implementing Web Applications with Microsoft Visual C#™ .NET and Microsoft Visual Studio .NET
Any help would be greatly appreciated.

Excellent showcase of a real world WPF application (Windows Presentation Foundation)

Microsoft recently hosted a very interesting conference, MIX06, in Las Vegas. By Microsoft's standards (PDC, TechEd) this was a very toned down event, but nevertheless very interesting. This wasn't just an event about Microsoft products, but also about sharing knowledge and interesting discussions such as the one between Bill Gates and Tim O'Reilly.
 
One of the technologies showcased at this event was WPF (Windows Presentation Foundation, formerly known as Avalon), a new way to create and render user interfaces. It relies on DirectX to accelerate everything including font rendering, alpha channels, video and animation. However you don't need to have any knowledge about hardcore C++, all you need to know is C# (orVB) and XML. Up until now I have seen few real world showcases that really show off the technology, but REZN8 has pulled it off by developing an application for Nascar that really shows off the power of this technology (watch video, disregard the first 3 minutes as these people are way too excited for their own good).
 
 
My team is currently using Flash 8 for these kinds of interfaces as that is available today and requires less powerful computers. However I am already considering switching to WPF for future functionality.
 
Some interesting links:

What is of interest to me personally is that the Nascar demo is presented by Andrew Whiddett, a former co-worker that poached me away from a Dutch multimedia company to work with him for a really rubbish company in the UK. I didn't recognise him at first as it looks like he is trying to grow a beard and suddenly got a real heavy American accent. Nevertheless Andrew knows his stuff, he is always operating on the cutting edge of technology and recently published an interesting article on WPF data binding. I am glad for him that he finally got out of the boring retail sector.


The fastest JavaScript string class in the known universe

Ok, so the title of this post is a ridiculous claim as I have not researched the alternatives, but it may actually be true.
 
About 6 or 7 years ago when I was doing Ajax like development before it was the fashionable thing to do (and everyone told me I was nuts) I ran into performance problems on the client due to the large number of string concatenations that were required to render the data to the screen.
 
Unfortunately JavaScript does not offer the same powerful classes like Java's StringBuffer and dotNet's StringBuilder so I had to be a bit creative and come up with a workaround.
 
Let's dive a little bit into why traditional string concatenations are slow with a simplified code example:
 

 
// ** To really demonstrate the differences we simulate iterating through 1000 records
var recordCount = 1000;

function slowString()

{

    // ** Save the time for benchmarking purposes
   

var tick = (new Date()).valueOf();
    var html = "<TABLE>";
    var someData = "dfksdjhfsdkjhdf sdhf skh fskh dfksdkfh";
    var someOtherData = "dfksdjhfsdkjhdf sdhf skh fskh dfksdkfh";

    for(i=0; i<recordCount; i++)
    {
        html += "<TR><TD>" + someData + "</TD>"
        html += "<TD>" + someOtherData +  "</TD>"
        html += "<TD>" + someOtherData +  "</TD>"
        html += "<TD>" + someOtherData +  "</TD>"
        html += "<TD>" + someOtherData +  "</TD></TR>"
    }
    html += "</TABLE>";

    // .. additional code to insert the HTML into the document

    alert("String size: " + html.length + "\nTime taken: "
        ((new Date()).valueOf() - tick) + " milliseconds");

}



On my system it takes 2624 milliseconds to concatenate all the data resulting in a string of about 240KB. So what is really going on here? The problem is that we are performing just over 5000 string concatenations on an ever growing string. Every time we perform a concatenation, even of a single character, a memory block is allocated the size of the original string and the string we are concatenating. Then both strings are copied into this new block. Not only is this not very memory efficient, it is also extremely slow.
 
We can make a simple improvement as shown in the following code example (changes in red bold-italics):
 

function mediumString()
{
    var tick = (new Date()).valueOf();
    var html = "<TABLE>";
    var someData = "dfksdjhfsdkjhdf sdhf skh fskh dfksdkfh";
    var someOtherData = "dfksdjhfsdkjhdf sdhf skh fskh dfksdkfh";

    for(i=0; i<recordCount; i++)
    {
        var temphtml = "<TR><TD>" + someData + "</TD>";
        temphtml    += "<TD>" + someOtherData +  "</TD>"
        temphtml    += "<TD>" + someOtherData +  "</TD>"
        temphtml    += "<TD>" + someOtherData +  "</TD>";
        temphtml    += "<TD>" + someOtherData +  "</TD></TR>"
        html += temphtml;
    }
    html += "</TABLE>";

    // .. additional code to insert the HTML into the document

    alert("String size: " + html.length + "\nTime taken: " +
       ((new Date()).valueOf() - tick) + " milliseconds");
}

 

  
This bit of code is considerable faster as it takes only 730 milliseconds to execute, almost 4 times as fast. We still perform roughly the same amount of concatenations, but the majority of the concatenations are performed on a small 'temphtml' string so there is a lot less data being copied around.
 
Now for the big one, lets refactor the code to use my super fast JavaScript StringBuilder class (changes in red bold-italics).
 

 

function fastString()
{
    var tick = (new Date()).valueOf();

    var html = new CStringBuilder("<TABLE>");
    var someData = "dfksdjhfsdkjhdf sdhf skh fskh dfksdkfh";
    var someOtherData = "dfksdjhfsdkjhdf sdhf skh fskh dfksdkfh";

    for(i=0; i<recordCount; i++)
    {
        var temphtml = "<TR><TD>" + someData + "</TD>";
        temphtml    += "<TD>" + someOtherData +  "</TD>"
        temphtml    += "<TD>" + someOtherData +  "</TD>"
        temphtml    += "<TD>" + someOtherData +  "</TD>";
        temphtml    += "<TD>" + someOtherData +  "</TD></TR>"
        html.append(temphtml);
    }
    html.append("</TABLE>");
    var finalHTML = html.toString();

    // .. additional code to insert the HTML into the document


    alert("String size: " + finalHTML.length + "\nTime taken: " +
        ((new Date()).valueOf() - tick) + " milliseconds");

}


 
The difference is amazing, the code executes in 90 milliseconds, almost 30 times as fast as the original code!
 
So what is the magic ingredient? The StringBuilder class encapsulates a simple JavaScript array. Every time a string is added to this array the size of the array is increased by 1, a relatively fast operation. The string is not even copied but a reference to the string is added to the array, which again is a very fast operation.
When we need the full string (the toString() method) then we let the system do all the work by calling arrayName.join(""), which takes about 10 milliseconds.
 
This code is used on several major e-commerce sites and has made the difference between being sluggish and being very fast. The difference is even more apparent on slower systems.
 
I have placed both the example as well as the full code online.
 
 
The topic of string concatenations as well as other typical improvements and coding guidelines for C#, JavaScript, Java, VB and other languages are available in the Coding Guidelines document I maintain. It can be downloaded for free from my company's website. See my other blog entry for more information.

Pimp up your PocketPC

After my initial disappointment with Windows Mobile 5 I have grown used to it and prefer my new MDA Vario over my old MDA compact, which I have decided to auction off on eBay. ActiveSync 4.1 is still a big problem though, but hopefully its problems will be addressed in a future release.
 
Now that I have grown used to the various features and shortcomings I have decided to Pimp-up my phone with some useful utilities and eye candy. It is always tempting to install everything and the kitchen sink, but I prefer to keep things simple.
 
Shortcomings I needed to address were the following:
  • The pink T-Mobile theme, this really had to go. Last time I checked I had a girlfriend. I find it difficult to understand why T-Mobile insists on these colours for phones that are mainly aimed at men.
  • I prefer to launch my most frequently used applications from the today screen so I needed solution for that as well.
  • Finally in order to keep things responsive I prefer to close the applications I don't use so I needed a good task manager.
The results can be seen below. The first screenshot is the hideous T-Mobile theme, the second is the default Windows Mobile 5 theme and the third is what my current phone looks like. 
 
 
With a little help from my friends (Baudewijn, Elliot) I found the perfect combination of utilities.
 
Unlock phone: In order to upgrade your OS, and potentially switch to a different provider in the future, you need to unlock the phone. An application and simple instructions are available on the excellent xda-developers website. (Make sure you register and login or you will not see the downloads).
 
Upgrade OS: The next step was to completely replace the OS and all the T-Mobile default settings. This can be achieved by upgrading the ROM with the latest version from i-mate. The upgrade and simple instructions can be found on the xda-developers site.
 
Speed up the CPU: In order to be able to run Skype the CPU needed to be overclocked from 180Mhz to 240Mhz. Luckily a Russian team had already created a simple utility that can be downloaded from xda-developers as well.
  
Launch applications: To make it possible to launch applications from the start screen I installed iLauncher. This is a cheap commercial tool that offers additional extras as well such as the coloured battery meter at the top of the screen.
 
Task manager: Elliot recently installed Wisbar Advanced with a wicked Vista theme. After seeing this I naturally needed to do the same. The advantage is that it comes with an excellent task manager. A small modification was made to the PocketPC Vista theme to switch the font from black to white. Download it here.
 
If you want an iPAQ to play around with these tools then pick up a cheap one here

Web based clipboard - Better get used to it

One of the best moves Microsoft has made in the last 5 to 10 years has been acquiring Groove Networks. Not only did they purchase an excellent and innovative product, they also 'bought' Ray Ozzie, the company's founder and now Microsoft's CTO. Ray is a person who knows how to think outside of the box as he created both Lotus Notes (yuk!) and Groove Virtual office (woohooo!).
 
Ray has recently put on his thinking cap and had a good deep and hard think about what people are struggling with on the web. The results is a simple, yet powerful, system for letting websites interact together via the clipboard in a platform independent and secure manner.
 
 
I am not a person who frequently predicts the future of the web, but forget about all the other new technologies such as Ajax and start implementing Ray's concept. It is one of those solutions that just works and everyone will be using it without even giving it a second thought.
 
The important links are:

Thoughts on Boringami

When Microsoft launched one of their most successful and accidental viral marketing campaigns ever on the 23rd of February, expectations were rising high. Was it a portable XBOX, an iPod killer, a bird, a plane.... Superman?
 
Unfortunately the truth was not nearly as exciting, the Origami is nothing more than a smaller than average TabletPC, a product in search for a market. They claim a price point of around $500, but I doubt they will achieve that in the short term, my estimate is that initially it will be at least double that amount.
 
The unit (Samsung's version is displayed below) is smaller than the average TabletPC, but not nearly as small as I was hoping it to be. The moment they hit the $500 price point and make it look like the mock-up Bill Gates is holding in the 2nd photo then I am sure it will take off. As what I don't know, but someone will find a purpose for it.
 
 
Things are not all negative though, by having a less than perfect product like this available now, people, developers and companies will start to think about potential uses for it. Someone will come up with a good, maybe even a killer, idea.
 
Listed below are some interesting Origami related links that are not just copies of the usual press releases:
I'll keep an eye on it, hopefully the ongoing miniaturisation of Windows XP devices will lead to replacements for today's PocketPCs.

Windows mobile 5 phones. You may want to give these a skip for a while

I have been an avid user of smartphones over the last couple of years. I started with a Nokia 7650, possibly the first real smart phone other than the massive Nokia Communicator, then moved to Sony Ericsson's P900 followed by an MDA Compact running Windows Mobile 2003 SE.
 
Earlier this week it was time to upgrade so I ordered a free MDA Vario, which comes with Windows Mobile 5.

The advantages, when compared to my previous MDA Compact, are that this unit has a built in WiFi card, contains a slide out keyboard and runs Windows Mobile 5. Note that I list Windows Mobile 5 as an advantage, more about that later. The disadvantages are that it only has a 200Mhz processor, the MDA Compact runs at 400Mhz, and that it runs Windows Mobile 5 (WM5).

I was very excited about moving to WM5 as WM2003SE was not really an OS designed for a phone. Way too many clicks and operations were necessary to perform even the most basic tasks. Being able to operate the phone with just one hand (god knows what the other hand is doing) is very important for a mobile phone, probably because you need the other hand to constantly reset the unit because it has crashed or become completely unresponsive.

In the last day I had to reset the phone at least 5 times. Not because I was doing anything special, I was just using the basic functionality. Great, let's see how we can make it worse...

Ah, here is how to make it worse, connecting it to a computer makes it a lot worse for both the computer and the phone. For some reason, probably a good one, Microsoft changed the way WM5 phones work with ActiveSync, Microsoft's syncing software.

I deal with a lot of Windows Mobile 2003 devices (dozens, if not hundreds) and ActiveSync has always worked flawlessly, without exception. It was fast and there was really very little that could go wrong, well done Microsoft. Unfortunately even Microsoft admits that ActiveSync in combination with WM 5 can be quite the nightmare.

I hardly ever need to restart my Windows XP machine, it is rock solid and I love it, in a platonic kind of way. In the last day I had to reset it at least as often as my new phone. ActiveSync is attempting to pair the phone, but more often than not it fails....miserably.

I managed to find the source of the problem, on Microsoft's "we are guilty page" it is stated that amongst many other things they have problems with USB hubs. USB HUBS! I have never seen anything fail with USB hubs and I use many different USB devices, all through a hub, but somehow Microsoft has managed to *** it up.

Sigh, so now every time I need to plug in my phone to sync or charge it I need to go all the way to the back of my machine, unplug another USB cable and plug this one in. Great.

 

Anyway, there is plenty more wrong with it, but I am starting to ramble. This is getting boring. To be continued...

Windows Live Messenger beta 2 invites available

The 2nd beta release of Messenger (Live) 8 is out. It is a lot less ugly then the previous one and hopefully it doesn't leak 1GB a day like it used to.
 
At this moment you can only use the application when you are invited. Luckily I have a large number of invites available so leave a message on my personal blog when you are interested.
 
Update: The ads displayed in the lower pane are eating CPU time, switch to the useless Video Carousel (Tools / Options / General) to reclaim your CPU cycles or minimise your messenger window.

Fujitsu Personal Shopping Assistant...THIEVES!

When I founded MCRL a couple of years ago the main product we were focusing on was the PSA, the Personal Shopping Assistant. We generated a lot of headlines and even managed to sell it to two different super market chains, but it was never deployed in massive quantities.
 

Even though we did not get much back for our hard work, we managed to make quite an impact on the retail industry by demonstrating the product on all major trade shows. Both Wincor Nixdorf and IBM are marketing similar products now that the market has matured. Today I found out via a press release on the Microsoft Website that Fujitsu is now also marketing a similar product.

I am not bitter, but it is quite interested that all parties who are now offering these products visited our offices over the last couple of years to 'partner' with us. Haha, I can laugh about it now.

I have to admit that I did not invent the concept of the PSA as a number of companies have been experimenting with the concept, unsuccessfully, since the early 1990's.

Some of my friends are still working on similar devices, however they focus more on handheld PDA units.