Extending the Widget model on Windows Mobile 6.5

Over the past week we have seen a number of posts from Jorge and the team at Microsoft covering what’s new for developers in Windows Mobile 6.5.  This was kicked off with the release of the Windows Mobile 6.5 Developer Tool Kit which includes both emulators and documentation/samples for working with gestures. 

What isn’t included in the DTK is any documentation on building Widgets. Jorge made a great initial post covering getting started building your first widget but went short of providing any real documentation on the extent of the widget object model. One of the first question that comes to mind is extensibility.  This has in part been answered in a forum question and answer.

The upshot is that in order to extend the widget model you need to build and deploy an activex control that can do the hardwork for you.  If you want to try it out, all you really need are WM6.5 emulator images and the Windows Mobile 5 SDK (that’s right the WM5 SDK!).  In the WM5 SDK you will find a sample called AXSample which surprise, surprise is an ActiveX control sample (On my machine this is in the folder C:\Program Files\Windows Mobile 5.0 SDK R2\Samples\PocketPC\CPP\ATL\AXSample). You can load and run this sample and it will display the simple activex control in the IE Mobile browser (step 1…. done).

The next thing to do is to add the registry value to enable the activex control for use within a widget.  Note that the other registry values mentioned by Jorge are added automatically by Visual Studio when you depoy and run the activeX control sample.  The registry value you need to set includes the CLSID for your activeX control.  You can get this a couple of ways but the easiest is using the Remote Registry Editor:

image

Once you have the CLSID you can go and create the appropriate keys and values:

image

You will note here that I have replaced the <ObjectName> value in Jorge’s answer with “SampleControl”.  This is how we then reference this object from within your widget javascript code:

                var myObj = widget.createObject("SampleControl");
                alert("The current fill color is " + myObj.FillColor);

This is in essence all you need to do in order to extend the widget framework.  This example just shows how you can retrieve a value from the activex control but you could execute any native code you want as part of executing that property.

If you look at the other samples that ship with the Windows Mobile 5 SDK you will notice that there are a host of native code examples on everything from retrieving the current phone number through to accessing POOM.  You can use any of these to build out your widget code to do whatever you want on the device.

Now the downside…. you can’t deploy a widget with an activex control embedded in the widget file via marketplace.  So the question is how you can deploy your widget and still leverage activex controls.  I would suggest the easiest approach is to build the widget so that when it first loads it detects if the activex control is present.  If it’s not, it can direct the user to a download site where you have placed a .cab file with the relevant activex control in it.  Of course, as marketplace has not available yet we don’t know if even this strategy will be possible. 

Published Monday, June 08, 2009 4:35 AM by nick

Comments

Tuesday, June 09, 2009 5:42 PM by Christopher Fairbairn

# re: Extending the Widget model on Windows Mobile 6.5

I'm interested in this extensibility story too.

I'm not expecting the market place to allow widgets that deploy CABs from external servers.

If they did it would seem to rather weaken their response as to why widgets must be deployed via the marketplace (security etc), as any bad bits could be pushed into the "uncontrollable" CAB file.

I'm wondering if another scenario would be to package up your widget as a *.CAB instead of a *.widget file. If you deployed this from your own server it could install the ActiveX control and a custom setup.dll could directly launch wmwidgetinstaller.exe to install the embedded widget file).

You would probbably loose the ability to publish via the market place, as again I assume they won't accept such a CAB for publication. But it may be a scenario for line of business / inhouse developments.

I've started porting Chris Craft's 30 days of windows mobile apps to widget form (windowsmobileapps.codeplex.com) but am quickly getting to the ones which will require access to GPS / phone functionality.

Monday, June 15, 2009 11:56 PM by Extends widgets using ActiveX

# Extends widgets using ActiveX

Pingback from  Extends widgets using ActiveX