Slides from my MEDC sessions

Thu, June 28, 2007, 11:17 PM under MobileAndEmbedded
The MEDC world tour is over and my contribution was participating in panels and presenting at two locations: Las Vegas and Berlin. In both the US and the European events I delivered the sharing assets and the mobile UI tips sessions. You can find the powerpoint slides from both my breakouts in this ZIP file (tip: some of the slides have URLs for more info at the bottom).

Back from Berlin

Thu, June 28, 2007, 12:22 PM under Random
Just came back from MEDC Europe in Berlin after the flight from hell (5 hour delay spent in airports, gates, planes and runways) due to the Heathrow gas leakage. I've only had 4 hours sleep in the last 24... And that was following a previous night of little sleep due to a debaucherous celebration in Berlin with the MEDC organisers. Tomorrow I have to be at TVP all day including evening entertainment with our UK "community leaders", followed by DDD5 on Saturday... In the dictionary next to "sleep deprivation" there must be a picture of me... No surprise then that I've decided to take some time off Sunday thru to Wednesday and be totaly unreachable... Anyway...

On a more pleasant note, our book was selling like a hotcake over there, so MS Press should be very happy... To the people that took photos of me and Andy signing copies for the delegates (what a bizarre feeling that was!), please send me some.

Slides: Windows Mobile Managed APIs

Sun, June 24, 2007, 03:16 AM under MobileAndEmbedded
A few people asked me this week for my material for the Windows Mobile session I did at DevDays last week.

You can get the demos from this post. What you'll also find from there are links to screencasts I have done and other relevant blog posts. Note that even though those demos are for WM5 projects running in VS2005, the code is identical to what I showed in VS2008 Beta 1 targeting WM6 – no code change whatsoever.

Download the slides here (pptx inside another ZIP). If you are on a legacy version of powerpoint, see this post.

Download my Vista demos

Sat, June 23, 2007, 06:07 AM under Windows | Vista
Last November I made a TOC post that linked to all my work on Vista-only features for Managed Developers. I have updated that blog post today so I strongly suggest you revisit it if the topic interests you and you want content, videos and slides.

By following and reading those links you can recreate every single one of my demos – trust me, that is the best way to learn this stuff! You should also note that any demo I show in presentations is a DEMO; it is not real production-ready code by any stretch of imagination. Also many of my demos won't make any sense to someone that has not seen me present them (e.g. at UK MSDN events, Tech Ed, UK Vista launch, DevDays...) and some of them are incomplete since I do the coding on the fly while others will not work if you don't install their dependencies as described in my sessions. My demo projects target .NET Framework 2.0 from C# and the project/solution format is for Visual Studio 2008. You could create VS2005 projects and add the code files from my projects if you don't have VS2008 Beta 1.

So, with those caveats in place and by popular demand, you can now download my demo code here. Enjoy!

Sidebar + SideShow = Love

Fri, June 22, 2007, 01:35 AM under Windows | Vista | SideShow
In the past I have introduced Sidebar gadgets and have made a quite few blog posts on SideShow. What I've not done here is talk about the integration between these two. In this blog entry I'll assume you are familiar with both of them independently.

The integration is about being able to send content from your Sidebar gadget to SideShow-enabled devices. Effectively, the SideShow gadget(s) running on Windows *is* the Sidebar process. So how do you SideShow-enable your Sidebar gadget? You add a bit to your manifest and the remainder modifications are all in javascript calling the SideShow methods of the Sidebar API:

1. Add an icon for SideShow to your Sidebar gadget manifest. In your gadget.xml file you already have an icon element under an icons element which is under the gadget element. You need to add another element named ico that points to your SideShow icon i.e.
<icon height="48" width="48" src="daniel.PNG" />
<ico src="SSnotification1.ico"/>

2. Set a friendly name. Somewhere in your javascript make the following method call:
var friendName = ""; //your data
3. Add glance content. Whenever you want to update the glance data, make this call:
var glance = "Hello from Sidebar"; //your data
System.Gadget.SideShow.addText(0, glance);
At this point on your SideShow device you have something like this:

4. If you want to send SCF pages, use the same method as above, this time changing the id (first argument) as appropriate and making the 2nd argument hold the XML, e.g.
var scfXmlcontent = "<body><menu id='1' title='My menu'><item target='2'>I am a menu</item></menu></body>";
System.Gadget.SideShow.addText(1, scfXmlcontent);
So, on your previous screenshot if you now click on the SideShow's OK button you'll get the following:

Clearly, if you select the menu item then you'll get a "Page not found" message because we haven't send any other page with an id=2. I leave that as an exercise to you.

Of course, it would be great if whatever you render on your Sidebar gadget automatically got sent to the SideShow device but as you see above, that is not the case. However, the crucial part of building gadgets in general is getting the content that you want to show: you only need fetch that once and then you just need to package it twice (html for Sidebar and SCF for SideShow).

Note that if you want to send images that you reference by id in your SCF pages, then you must use the addImage API. When you visit the APIs, ignore their advice to check for the enabled method because it apparently always returns true. Also note that when you want to update the same content id, it is best that you call the remove method first and the send down the new content corresponding to the id. You should also not bother with notifications or events for combined gadgets, since the applicationEvent is non-functioning.

Should you wish to play with the simple sample I described here and you are too lazy to type it yourself, download this ZIP on your Vista machine and then execute the daniel.gadget inside it. To see a fully fledged proper gadget and not the Hello World demo I created, download the StocksPlus combined gadget (it is the Stocks gadget you have in your box, enhanced to support SideShow). Whichever gadget your download, first make sure the SideShow Simulator is running already! Enjoy :)

VS2008 integration with UAC

Wed, June 20, 2007, 02:52 PM under Orcas | VisualStudio | UAC
You know that when you run VS2005 on Vista (even with SP1 and the SP1 update) you get advised to run elevated. You also know that VS2008 has better indication when you run it elevated.

What I haven't explicitly stated before is that VS2008 does not require you to run it elevated from the start. Instead it is a good Vista client and plays nicely with UAC by only prompting you to restart the IDE when you truly need to. For some type of projects this will equate to always run elevated of course, but it is good that it doesn't force this behaviour on all of us and that it offers to do it for you as needed.

Recently I discovered one scenario where it plays nicely. I double clicked on a solution file in explorer and because it was in a place requiring admin rights, I got the following dialog from VS2008

This is cool (even though I suspect the final text will be slightly different as there are a couple of errors there e.g. UAC = User Account Control).­­­­­­­­­­­­­

Using Extension methods for cross-framework projects

Tue, June 19, 2007, 10:11 AM under MobileAndEmbedded
In this post I assume you have read my blog entry on Extension Methods. When I described extension methods I finished by saying:
"Overall, I like this feature *a lot* (will post some concrete examples of why in the future)."
The time has come to explain myself. I've been waiting for my MSDN magasine article to go live so it can be the first to describe the proposed usage :-)

So to quote myself from the article:
"While using .NET Compact Framework classes, the occasion often arises that a particular class has members missing compared to the full Framework. Typically, developers have to write the missing functionality themselves and then decide whether to use inheritance if possible to add the missing members or add them to a utility helper class."
Please visit the article to see a good example of how extension methods can help with the above scenario.

When we faced this issue in the SDF from OpenNETCF, we took one decision in some cases (utility classes) and the other decision (inheritance) in other cases. Unfortunately, utility classes suffer from the inherent non-discoverability for client code and inheritance is not always possible due to sealed classes. So many times we opted for a 3rd approach (that I was never entirely comfortable with): Introducing a replacement class e.g. TextBox2. Now, there are still scenarios where that approach is the only viable technique, but for some cases using the Extension methods as I describe in the article is a better alternative.

I'll just give one more example here. If we wanted the System.Windows.Forms.Timer class in the NETCF to have a compatible interface with the desktop version, one thing we'd have to do is add Start and Stop methods. Easily achieved by dropping the following code file in just the device project and not the desktop project:
public static class TimerExtensions
public static void Start(this Timer t)
t.Enabled = true;
public static void Stop(this Timer t)
t.Enabled = false;
...and then the codefile that uses the Timer can be the same on both platforms, e.g.
private void menuItem1_Click(object sender, EventArgs e)

private void menuItem2_Click(object sender, EventArgs e)
We have seemingly added extra methods to a class so our utility methods are discoverable and if the real NETCF class ever got those methods implemented, our code gracefully bows out at runtime. Try it out... coding is believing how cool this is :)

MSDN mag article: Cross-framework code

Mon, June 18, 2007, 03:31 AM under MobileAndEmbedded
In my July MSDN magazine article, I have collected in a single place my tips for writing cross-platform managed code, in this case meaning code that targets both the Windows desktop and Windows Mobile. Even though the article was written with the .NET Compact Framework and the full .NET Framework in mind, most of the techniques apply in other scenarios as well.

Consider how many frameworks/CLRs we have today: .NET Compact Framework, full .NET Framework (aka desktop framework), .NET Micro Framework, Silverlight CLR, MONO (framework for non-Windows platform) etc. To that list you should add scenarios where you wish to target two different versions of the same framework type e.g. both v1.0 and v2.0 of the NETCF/Full Fx. Even though it looks the same, the framework/CLR between versions is effectively a different framework so again some of the principles in the article apply. Read the article here.

Back from DevDays

Fri, June 15, 2007, 11:30 AM under Random
Just came back from a few busy days in Amsterdam. I have been to Amsterdam a few times before and given the busy schedule I didn't venture anywhere beyond the hotel and the RAI (the venue) other than one night for dinner in an Italian restaurant with funny man Rob Miles. In fact, I ordered a lemon tart and got a cake with a bit of lemon on the side! Rob has a photo of it here.

Anyway, I have to say, I was very impressed with this event. The sound system/microphone was the best I have ever used. The food was fresh and healthy (no cans of coke, or packet of crisps or chocolate bars and other junk food like that). There was a geeky buzz about the place and the Dutch were a wonderful audience – very interactive and kind enough to laugh at my bad jokes. Some of them even let me to devalue their fresh purchase by asking me to sign it.

The screen in the auditorium (capacity 2K people) was one of the largest I have ever seen. The screen had a feature that must be every presenter's dream, but is very hard to describe: it was split in two where on one side they showed the presenter's face and on the other the slides.

No, that isn't the killer feature yet. When the presenter switches to a demo, the face bit becomes smaller and goes to the corner, and a 3rd viewport appears on the screen in the middle.

So now you have 3 squares (1 small showing the presenter, 1 large showing the demo machine plus 1 more that is also large). The new one that appears in the middle is a magnifier for the demo machine, controlled by people backstage! So while you, as the presenter, are doing your demo as usual, someone else makes sure that the important bits are magnified for the audience on a separate screen. Pure genius.

Overall, I'd be more than happy to go back to DevDays in coming years. The organiser picked only speakers that he had seen present at other events previously and hence was confident they would be good for his event. He covered expenses for speakers which was refreshing for a large international conference. Congrats on a good show and thanks for inviting me Arie!

My book is now in my hands

Mon, June 11, 2007, 06:13 AM under MobileAndEmbedded | Personal | Links
Mobile Development Handbook

My book is now in my hands, and here is the proof... and another wobbly photo of the back :-D

At some point in 2006 I started writing a book and at some point in April 2007 we completed the project. I say "we", because I had two excellent co-authors, both long standing Device Application MVPs: Peter Foot and Andy Wigley. I would have liked to be able to say that I also am a .NET Compact Framework MVP, but unfortunately I lost that title when joining Microsoft last year as per the rules.

We explicitly targeted two audiences with our book and implicitly excluded one audience segment:
1. Existing C# and VB device developers - YES
If you are already targeting Windows Mobile devices you will know that all existing books talk about version 1.0 of the .NET Compact Framework and Visual Studio.NET 2003. Since those times there have been three service packs for v1.0, version 2.0 with two service packs and, of course, Visual Studio 2005. Furthermore, v3.5 is in Beta 1 right now as is Visual Studio "Orcas". Our book covers what is new in the .NET Compact Framework and Visual Studio 2005 compared to their predecessors. It also covers throughout the chapters, but also in a dedicated chapter, version 3.5 of the NETCF and VS "Orcas" for Devices.

2. Existing .NET developers who are complete newbies to device development - YES
There are millions of proficient .NET desktop developers that would like to know how to write code for their mobile device or generally want to find out how to transfer their skills or business logic to the mobile platform. The book's tone is certainly aimed directly to those developers by continually contrasting and comparing with desktop development as applicable, highlighting what is different or missing when doing device development.

3. Existing native device developers - NO
This book is all about managed code, but we never introduce any basic .NET concepts from scratch. We expect readers to know about those either through experience with previous versions of NETCF or through .NET desktop development. So if you are a native device developer, you should pick up another book to learn the basics of .NET. We also have made no assumptions of knowledge about the Windows CE and Windows Mobile platform. The reason is so desktop developers can get an introduction to the whole stack/environment and not just the dev platform and tools. So, as a native device developer, you will encounter concepts explained that you probably already are intimately familiar with.

Whether you are looking for a book to read cover-to-cover or for a reference that you go back to, this book will fulfil your needs. It isn't just a book on the raw technology, but more importantly it captures lessons from developers that have practised mobile and embedded development in the real world.

Mobile Development Handbook

Vista ProgressBar

Fri, June 8, 2007, 05:46 AM under Windows | Vista
While prepping for an event in Amsterdam next week, I am revisiting all my content from last year to do with Vista for managed developers. A very small part of the presentation is showing the WinForms controls and what additional things you can do with them in Vista such as the TextBox cue banner, commandlink button, treeviewvista, adding shield to clickable controls etc.

It occurred to me that I never looked at the ProgressBar control. In Vista, in addition to NORMAL (green), the control can be in a state of PAUSE (yellow) and ERROR (red). However, the managed ProgressBar control does not expose a managed way of controlling that. Once again, PInvoke to the rescue:
// Assuming a Form1 with 3 ProgressBar controls
private void Form1_Load(object sender, EventArgs e)
0x400 + 16, //WM_USER + PBM_SETSTATE
0x0003, //PBST_PAUSED

0x400 + 16, //WM_USER + PBM_SETSTATE
0x0002, //PBST_ERROR

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern uint SendMessage(IntPtr hWnd,
uint Msg,
uint wParam,
uint lParam);

For a more complete reusable wrapper of the ProgressBar (inc. some other features that I have not covered) check out the code from the VistaControls project on codeplex.

Windows Mobile Device Center 6.1

Wed, June 6, 2007, 02:20 PM under Links
...with updates mainly for WM6 devices, available here (32-bit) or for 64-bit here.

.NET Framework 3.5

Tue, June 5, 2007, 04:17 PM under dotNET | Orcas
This is a follow up to my previous description of putting VS2008 in context.

.NET Framework (NetFx or Fx) version 3.5 has two elements to it that must be understood: the green bits and the red bits. The original references to this term are on old blog posts by Soma and Jason. Compared to those two blog entries I have the advantage of 13 months of hindsight :-), so I will provide here the details behind those descriptions in my own words starting with my own slide:

When we say red bits, those are Framework bits that exist in RTM today i.e. NetFx v2.0 and NetFx v3.0.

NetFx v3.5 includes updates for those two existing frameworks. However, those updates are not a whole bunch of new features or changes, but in reality a service pack with predominantly bug fixes and perf improvements. So to revisit the terminology: Fx 3.5 includes v2.0 SP1 and v3.0 SP1. Like with all service packs, there should be nothing in there that could break your application. Having said that, if a bug is fixed in the SP and your code was taking advantage of that bug, then your code will break of course. To be absolutely clear, this is an in-place upgrade to v2 and v3, not a side-by-side story at the framework/clr level. I will not focus anymore on the Service Pack (red bits) improvements in Fx 3.5. If you are interested in that you may wish to read my previous blog posts here, here, here and here.

When we say green bits, we mean brand new assemblies with brand new types in them. These are simply adding to the .NET Framework (not changing or removing) just like Fx 3.0 was simply adding to v2.0 without changing existing assemblies and without changing the CLR engine. It is here where you find the brand new stuff to talk about. In Beta 1, the list of new assemblies (green bits) is:

1. System.Data.Linq.dll – The implementation for LINQ to SQL.

2. System.Xml.Linq.dll – The implementation for LINQ to XML.

3. System.AddIn.dll, System.AddIn.Contract.dll – New AddIn (plug-in) model.

4. System.Net.dll – Peer to Peer APIs.

5. System.DirectoryServices.AccountManagement.dll – Wrapper for Active Directory APIs.

6. System.Management.Instrumentation.dll – WMI 2.0 managed provider (combined with System.Management namespace in System.Core.dll).

7. System.WorkflowServices.dll and System.ServiceModel.Web.dll – WF and WCF enhancements (for more on WF + WCF in v3.5 follow links from here).

8. System.Web.Extensions.dll – The implementation for ASP.NET AJAX (for more web enhancements, follow links from here) plus also the implementation of Client Application Services and the three ASP.NET 3.5 controls.

9. System.Core.dll – In addition to the LINQ to Objects implementation, this assembly includes the following: HashSet, TimeZoneInfo, Pipes, ReaderWriteLockSlim, System.Security.*, System.Diagnostics.Eventing.* and System.Diagnostics.PerformanceData.

UPDATE: Beta 2 added two more

10. System.Data.DataSetExtensions.dll – The implementation of LINQ to DataSet.

11. System.Windows.Presentation.dll –WPF support for the System.AddIn mentioned of point 3 above.

12. System.VisualC.STLCLR.dll – STL development in the managed world.

If you decide to "borrow" my slide above, feel free to do the right thing and point people back to this blog post ;-)

Run better user groups

Tue, June 5, 2007, 07:17 AM under Links
It is as if Roy has been eavesdropping to similar discussions we are having here in the UK. Check out his list of tips for better user group meetings.

Visual Studio 2008 stack

Mon, June 4, 2007, 07:02 AM under Orcas | VisualStudio
When Visual Studio 2008 (formerly Visual Studio codename "Orcas") ships in FY08, we will also get other elements of the stack. Below is the opening slide I use at Orcas events:

The main points are that the CLR engine is the same version (so no need to retest your apps) and that the headline feature is the language enhancements (C#3 & VB9 compilers) and LINQ.

The VS2008 IDE is not as big a jump as it was when going from VS.NET2003 to VS2005 and it includes all of today's SDKs out of the box and also a simple yet sweet feature: multitargeting inc. the ability to use new language features from .NET 2.0 projects. FYI, I usually do a demo of new IDE features that lasts 15 minutes (inc. aesthetics, VB intellisense, embedding manifests and new Office templates). Given that VS2008 is a superset of VS2005, there is little point in having both of them installed on the same machine, but it is possible – we support side-by-side at the IDE level.

So that is the IDE, languages and CLR in a nutshell. How about .NET Framework v3.5? For that you'll have to see my blog post tomorrow.

Acropolis CTP

Mon, June 4, 2007, 12:32 AM under Links
As if I didn't have enough things to play with and events to prepare for, my incoming list shows me an Acropolis CTP. Download it here.


Sun, June 3, 2007, 05:00 AM under dotNET | Orcas
If you never liked the name of TimeZone2, you'll be pleased to know that in "Orcas" Beta 1 it was renamed to TimeZoneInfo. Having played with this a bit, I found that its members include a dependency on yet another new type: DateTimeOffset. I searched and saw that this has actually been in there for a while.

What I can't fathom is why DateTimeOffset ended up in mscorlib and TimeZoneInfo ended up in System.Core! The latter makes sense, it is a brand new type so it cannot go into existing bits; so why break that rule for the former? To be clear, I would expect both of them to reside in Core. Anyway, regardless of where they belong, go play with them ;)

Visual Studio Orcas SDK June CTP

Sat, June 2, 2007, 03:28 AM under Orcas | VisualStudio
Want to work with VS "Orcas" Beta 1 extensibility points? Get the SDK here.

Some links from the last few days

Fri, June 1, 2007, 03:03 AM under Links
Been on the road for a week so catching up with my aggregator:

- Microsoft Surface (my wife asked me "Why is your mouth open, what are you watching there?")

- There has been discussion on the web about comments Martin made about AlphaGeeks. It is too easy for people to jump on the "doom train" (fact: being negative is so much easier than being positive), which is why I found Rocky's take most interesting: Busy, busy, busy.

- Bill and Steve talk. If you don't have time for the full interview, watch this 8' of highlights video.

- I am glad that other companies are finally seeing my point of view: pure web apps don't cut it; we need offline support and fast UI response. Read Tim's report from Google Developer Day.