Tech Ed session 1

Tue, October 31, 2006, 08:38 AM under Events
In exactly one week, I invite you to attend one of my 4 sessions at Tech Ed Europe in Barcelona.

Tue, Nov 7, 16:00 - 17:15, Room 125

DEV329 .NET Compact Framework (NETCF) for Desktop Developers

There are many C# and VB developers that have never used NETCF. In this session, we introduce NETCF v2.0, highlighting differences from the previous version. This talk explores the development platform differences between the Windows desktop environment and Windows Mobile-based devices such as the Pocket PC and smartphone. We also examine the options for sharing .NET assets between platforms, and demo suggestions for making the best development decisions. By the end of the show you will be inspired to write your first NETCF application that leverages existing code. Attendees require no previous knowledge of mobility devices or NETCF - simply an understanding of .NET on the desktop.

WCF for devices

Tue, October 31, 2006, 06:06 AM under MobileAndEmbedded
When we talk about the NetFx3 technologies, there are always one or two attendees (not the same ones each time!) that ask if any of the technologies are applicable to mobile devices. There are no plans for WF and no immediate plans for WPF (often confused with WPF/e which is actually quite a different technology with an unfortunate name IMO).

However, the WCF story is good with Orcas and it is now public information! Read all about the WCF support on Roman's blog post. Below some choice quotes:
"... The WCF programming model support will be limited to channel layer messaging (no service model support on the device) [...]
[...] We'll expose all necessary extensibility points so people could plug in their own transport and layered channels, while maintaining a unified programming model. [...] The channels we plan to deliver out of the box are Http and... yes, e-mail (for WCF on desktop and device)."

Go read the full story!

Out of Continent

Sun, October 15, 2006, 12:45 AM under Personal
Well, the time has come for another vacation (and our 2nd honeymoon in fact, since it is still within the period that the travel agents accept it as such!). We are taking our first ever trip to Egypt to visit the pyramids in Cairo, cruise down the Nile (Luxor, Aswan etc), visit Abu Simbel and dive the Red Sea...

I’ve been looking forward to this break, given the workload of September/October (you can work out from my blog how many events I have done!). Plus, when I return I am off to Tech Ed Europe and, boy, will that be tiring (more on my Tech Ed sessions soon)...

I will be back from our holiday on 1st November so until that Wednesday... other than my nuggets... let there be silence on this domain :-D

PS For any work related queries, try one of my colleagues.

VB6 does glass on Vista

Sat, October 14, 2006, 07:00 PM under Windows | Vista
The other day at one my talks somebody asked me if the new Vista native APIs I show callable from managed code are also callable from VB6. I hadn't thought about that before, but in principle, yes, they should be. He was specifically interested in glass (glass, as in what I talked about here, here, here, here, here and here.).

Unsurprisingly, it took me longer to download the VB6 iso, to install it on my laptop and to remember how to work with that IDE, than what it did to get glass in VB6. A form, a module and a total of 11 lines of code later and the following screenshot shows the project running (or if you prefer without transparency):

Note that just like with Windows Forms (but unlike WPF), actually making controls look good on the glass surface is not trivial (unless you enjoy painting everything yourself!). You get a glimpse of the challenge here and a full blown project here.

Vista: Restart Manager

Sat, October 14, 2006, 03:45 AM under Windows | Vista
It is amazing how as end users we all take for granted that before we install something we need to save our application state, manually close everything, install the new thing, manually restart every app we were using (if we remember what they were) and try to get to the state we were before! How many times have you installed an application (or completed a Windows Update or some other patch) and then had to restart your machine? How irritating is that?

Restart Manager promises to make that experience a thing of the past. Personally, I'd like to live with Vista for a bit longer before I subscribe to that promise but I have to admit initial experiences are promising!

So what does Restart Manager (RM) do?

Fundamentally, when a RM-aware piece of software installs, it will ask all RM-aware applications to shutdown, assuming the said applications are holding resources (e.g. files) that it needs to update. The RM-aware app, will listen to the request and shutdown, saving its state! When the installation has completed, it will then restart all the RM-aware applications. The RM-aware application will then restore its state and the user has a nice experience. The classic example is that you have left Word open with a document you are working on and gone home. Overnight a patch is available and windows update does its job. So it closes down Word, install whatever, then restarts Word so when you arrive in the morning, you can't even tell what happened because Word is waiting for you where you left it with the document you were last working on :)

If the update involves a critical system component so a windows reboot is unavoidable, a reboot will take place but after reboot the RM-aware applications will also restart!

Now that Vista offers this technology, reaching this seemingly imaginary world is down to us, application developers. And since you are reading this blog... managed developers! So what is it we need to do?

Developer actions
Well, reading the above should have given you a clue :)
1. We need to make our installations follow the RM philosophy and
2. we need to make our applications at runtime also play ball

To achieve the first action we can simply use (directly or indirectly via commercial package) Windows Installer v4 and you are pretty much done!! If you have chosen an alternative deployment technology then ditch it and switch! No I am only joking, if you do wish to use something else, then you must manually work with the API which resides in rstrtmgr.dll. A typical series of calls is to create a session (RmStartSession), then register the resources we created (RmRegisterResources), then shutdown the resources/processes (RmShutdown), later on restart them (RmRestart) and finally end the session (RmEndSession). I may post a full C# sample in a future blog entry.

To achieve the second developer action for your application, you need to do a further two things:
a) Register with the system for restart, and be capable of restoring your state when (re)starting up
b) Listen for the message from an installation program that you are about to shutdown (good opportunity to save state etc)

The first of these actions is identical to what we talked about before for unexpected crashes/hangs. Now you see that there is a dual benefit to calling RegisterApplicationRestart as I’ve already mentioned in this article.

The difference with that scenario is that in this case your application doesn't crash, instead it is being asked nicely to shutdown. To listen to that request you need to hook into your window's message loop and listen for a specific message as per the example below:
    protected override void WndProc(ref Message m)
base.WndProc(ref m);

if (m.Msg == WM_QUERYENDSESSION) //0x0011
// some installation will shut us down next, so do some cleanup (prepare for it)
File.WriteAllText(Environment.CurrentDirectory + @"\rm.txt", "for demo purposes");
//MessageBox.Show("intercepted", “RM request”);
Other links
If you want to find out more about Windows Installer 4.0 working with Restart Manager then there is this video on channel9 (watch the first 3’ and then watch another 4’ starting at 15’).

There is public/external mention of Restart Manager over at eWeek.

For the developer types, lookout for a nugget coming real soon!

Vista: Sample Sidebar Gadget

Thu, October 12, 2006, 09:33 AM under Windows | Vista
While most people think they know all there is to know about Sidebar and Sidebar gadgets, I strongly recommend you read my blog entry that details the feature: Sidebar Gadgets. The best way of course is to actually try out all the system gadgets that give you a glimpse of what is possible. Only then you'll have acquired an appetite to go build your own!

First step to creating our own gadget is to know what a gadget looks like on the file system. Easy one that... it is just a folder! A folder with a .gadget extension placed in one of two places: the system folder or the user folder (more on both follows).

1. Navigate to the following path on your machine (copy it and paste it on your explorer window): "%userprofile%\appdata\local\microsoft\windows sidebar\gadgets".
2. Create a folder named "moth.gadget".
3. In that folder, place this gadget.xml file.
4. Drop in the same folder this daniel.html file (right click and save it, don't worry about what is inside it for now).

Go to the gadget picker and you see your gadget (“Moth Gadget”)! So all we have to do to get our gadget in the gadget picker is use a manifest which is always named gadget.xml. Now go ahead and open the XML file in your favourite editor (~20 lines) and check out the element names. It should be obvious what each one describes (name, version, author, description, icon etc) and also obvious what you need to change for your own gadgets. Spot the correlation of values between the XML file and the text that appears in the gadget picker. Looking at the gadget.xml contents, notice under the base element (under the host element, under the hosts element) the attribute "src"? That points to where the actual content of your gadget is in terms of how it renders itself when added to the Sidebar (and that is why we added the html file).

5. Drop in the same folder an image with a name of “daniel.PNG” (I have one here if you are desperate for images). Now in the gadget picker we can also see our own icon for the gadget (rather than the default).

6. Now add the gadget to your Sidebar. If everything went to plan, you can see on a plain white background some text. This text is the machine name of the computer you are running on.

Open the html file in your favourite editor and observe its contents (~25 lines). It has 3 sections: script (the guts of all Sidebar gadgets is script), head (for styling) and body (for context). It should be fairly obvious to web developers what it does: In the script section we setup the 'machName' span to the return value of a gadget API (System.Environment.machineName). In the body we simply render the machName. "Not running in Sidebar!" is what you see if you open the html file outside of Sidebar of course.

So to summarise, gadgets are basically DHTML. A combination of html+script+css+images and you've got it (preferably PNG files so you can play with some transparency). Of course, you should also take advantage of the Sidebar gadget API to create powerful gadgets.

Questions that usually pop up at this stage:
Q1. (tone of disbelief) How powerful can I possibly make a gadget when I am only using DHTML?
A1. Very :) Just check out the gadgets that ship out of the box. You can view all of that code for inspiration by browsing to "C:\Program Files\Windows Sidebar\Gadgets" <-- this is also my top tip :)

Q2. Where can I find more about the Gadget API?
A2. On msdn of course. The gadget API page appears empty, but you can navigate to the topics below it from the treeview on the left.

Q3. Is there a tutorial more comprehensive that what you just showed?
A3. My sample above demonstrates how easy it is with essentially two files to hook into the gadget plumbing. The best samples are the ones on your Vista machine as per Q1 above. However, you can find two additional more comprehensive walkthroughs: One on msdn and one on technet. Enjoy!

Q4. No offense to web people and script fans, but can I not write these in binary code?
A4. Of course you can use ActiveX. You may lose the simplicity of deployments but you gain all the richness of ActiveX technology. Follow the link for more on gadgets with activex.

Q5. How about .NET code and in particular WPF?
A5. While originally this was the plan, regrettably the feature had to be cut (and will hopefully re-appear in a future version). There are a few samples of using WPF with gadgets but they are more a proof of concept rather than an attractive (or a supported) scenario. One such example (via an XBAP) is here.

Q6. Any other gadget resources?
A6. If you consume the links above (and from my previous post on Sidebar), as a side effect you'll discover other resources :) There is an example of using Atlas to call web services (very popular scenario) from gadgets here.

My nugget on the subject should be out next week

Vista: Sidebar gadgets

Wed, October 11, 2006, 11:20 PM under Windows | Vista
After talking about gadgets in general, let's focus on Sidebar gadgets specifically.

Sidebar gadgets are hosted, managed, installed, picked in Sidebar. Sidebar without gadgets is useless and gadgets without Sidebar are non-existent. Sidebar contains gadgets (gadgets can also be dragged onto the desktop area). Multiple instances of the same gadget can appear on the Sidebar.

Sidebar is a Vista feature and it is basically a pane on the side of the screen (whichever side you want on whatever monitor you want). It is an executable (sidebar.exe) and also has a systray icon. You can "close" the Sidebar in which case it is still running and is minimized to the systray or you can "Exit" the Sidebar in which case it is gone for real (along with any gadgets you dragged onto the desktop).

Sidebar can be configured to be always on top (or not) and the same is true of any gadgets that were dragged onto the desktop area. All gadgets have a thumb for moving them around and a close button for removing them from the Sidebar. Some of them also have a config button (little spanner icon). Furthermore, those gadgets can have their opacity tuned. Right click on the gadget and you get this menu:

Clicking on the Sidebar systray icon will bring to the front the Sidebar (if that was behind a window) and also any gadgets on the desktop (if they were behind a window). Right clicking on the icon will show a menu and right clicking on the Sidebar itself will also produce a menu. Both of these menus are in the following screenshot:

Clicking on "Properties" produces the following dialog.

The last thing to know about Sidebar is that there is a gadget picker that previously looked like this and now looks as follows (access it from the top of the Sidebar "+"):

You can add a gadget to the Sidebar from the gadget picker by double clicking, right clicking and selecting "Add" or finally by simply dragging and dropping. To remove the gadget from your system, right click on it in the gadget picker and select "Uninstall".

As the screenshot above shows there are 11 gadgets shipping out of the box.
- Calendar (Browse the days of the calendar)
- Clock (Watch the clock in your own time zone or any city in the world)
- Contacts (See a list of Windows contacts, search for a contact, or select a contact to see e-mail address and phone numbers)
- CPU meter (See the current CPU and RAM)
- Currency (Convert from one currency to another)
- Feed Headlines (Track the latest news, sports, and entertainment headlines)
- Notes (Capture ideas, notes, and reminders in a quick and easy way)
- Picture Puzzle (Move the pieces of the puzzle and try to put them in order)
- Slide Show (Show a continuous slide show of your pictures)
- Stocks (Monitor your favourite stocks)
- Weather (See what the weather looks like around the world)

These are the system gadgets and the user can install additional gadgets. I encourage you to familiarise yourself with these OOB gadgets as collectively they show some of the cool thing gadgets can do.

Before we close the description of this feature, it is important to understand that the security aspects have been thoroughly thought of and you can read about some of them here.

Next we look at the developer story with a sample Sidebar gadget :-)

Gadgets, gadgets, gadgets

Wed, October 11, 2006, 03:54 PM under Windows | Vista
If you didn't know about it, then yes it is true. Our marketeers have managed to name 3 slightly different things with the same name. I can sort of see where they are coming from, since in all 3 cases we are talking about task specifics mini-applets that are not quite full blown applications but are also not web pages so “gadgets” seemed appropriate for each category.

I am talking of course about (note the spelling/casing!)
* live gadgets (web)
* SideShow gadgets (Vista)
* Sidebar gadgets (Vista)

The compatibility between these is not there *yet*. Each has its own API that the other two hosts will not understand. SideShow gadgets are probably more removed from the other two. Live gadgets can be made under certain circumstances to run in Sidebar (via an iframe) but the vice versa story is not as good. I am being vague on the compatibility as I know it will get better in the future and the current story is ever changing. But here I am talking about (in)compatibility when I haven’t introduced each one of them!

* Being a client guy myself, I will not ever mention live gadgets here again (famous last words). To find out more about them visit these pages: 1 , 2 , 3 , 4.

* SideShow is a platform that attracts me hugely but I will refrain from talking about those gadgets until after Tech Ed Europe, in November (I am hoping to own hardware then and, if not, I'll just have to use the emulator - either way, stay tuned!).

* This leaves us with Sidebar gadgets... but that is the subject of my next post :-p

IE7 released to the wild

Wed, October 11, 2006, 09:00 AM under IE7 RSS
Well, not just yet but this month none the less. Everyone will receive Internet Explorer 7.0 via Windows Update (after they accept the EULA).

For web devs this means making sure your web pages work on IE7. It should, as a lot of effort was put into compatibility apparently, but all those CSS improvements and security enhancements (especially “protected mode” on Vista) may break you... who knows (other than you!)

I am not a web dev so I just see this from an end-user's perspective. I have switched to IE7 for a while now. You may think "Yeah, since you can't run IE6 side by side with IE7, obviously you have switched in order to dogfood IE7". Well, yes that is true, but to be perfectly honest with you, I meant that I switched from Firefox. That's right, I am one of the crowds that switched from IE to Firefox just over a year ago and now I have switched back (with my only gripe being no free ad-blocker out of the box, but I might be tempted by an add-on).

The main thing firefox gave me is now present in IE7: Tabbed browsing (and it is done a lot better IMO with closing/newing/previewing hitting the sweet spot).

Other things I like are the RSS integration (inc. RSS platform), easy page zooming, printing now does the right thing by default and integrated search that lets me add custom search providers e.g. I've added one that searches my blog:

The other thing, which is quite significant, is that IE7 just seems a lot faster (I wonder if someone can prove that for me please, I just know it is true).

Of course, there are websites out there doing stupid things like checking if they recognise the browser. In other words, an idiotic person wrote code that says "I explicitly recognise IE6 and support it, but anything else that will come in the future I will just not render and give out a silly message". As you can probably tell by the emotion in my statement, I have been dealing with such a 3rd party crap website to order my company car... anyway... if you are in that scenario too, you can always spoof the website by using this user agent tool (even more useful on Vista where there seems to be no way to remove IE7+).

Bottom line... try IE7 if you haven't already... you will like it (screenshot in my previous blog post).

I hate to make all this sound like an advert, but see it as my way of saying "thank you" to the IE team for a product I genuinely like!


Tue, October 10, 2006, 02:25 PM under Windows | Vista
Whenever I talk about the Vista enhancements in Windows Error Reporting, I am surprised to discover the number of devs that ask me "What is winqual?”

You know how sometimes an application crashes and then you hit that "send" button in the dialog that pops up? Well guess where it sends those reports (which can include your own diagnostics!).

That isn't just "a server that Microsoft uses to diagnose potential system issues". It is a server with data about *your* application, waiting for *you* to examine that data. Simply go register for free on winqual.

If you fix a bug and want to update all those users that have been hitting "send", how do you update them? Yup, winqual again. Trust me; it will make them happy :)

So what are you waiting for, use the Vista enhancements, register with winqual for free, examine the bug reports, and update your users with the solution. Let me hear you repeat after me (am I taking this too far?):
"I am off to"

Vista Shell revealed

Mon, October 9, 2006, 03:23 PM under Links
I really hope you guys were not waiting for me to point you to a (fairly) new blog on Vista. This is the authoritative blog of the Shell team that is growing in readership like no other blog ever has.

Go read everything they’ve written to date as every single post is a gem, e.g. the one about minesweeper or the one about the menus or best of all the one with the treat at the end.

And if you’ve had enough of serious information, they published something on the lighter side today :-D

Free MEDC DevCon material

Mon, October 9, 2006, 03:00 PM under MobileAndEmbedded
Remember that rss download feed I was telling you about? It just "dropped me a line" to say that all the MEDC content is available for anyone to download!

Go get the MEDC 2006 conference DVD!

My session was APP330...

Vista: UAC internals

Sun, October 8, 2006, 03:15 AM under Windows | Vista | UAC
I have explained before what you (a managed developer) has to do about User Account Control in Vista (and also expanded a bit on UAC policies).

The other day I got asked exactly how this works under the covers. Luckily, my mate Kenny covers this on his article (butchered quote):
When an administrator logs on to a computer ... the system ... creates ... two different tokens representing the same logon session. The first token grants all the permissions and privileges afforded to the administrator while the second token is a restricted token ... offering far fewer permissions and privileges. ... The system then creates the shell application using the restricted token.

Follow this link for the full unedited story.

WMDC for Windows Mobile 2003

Sat, October 7, 2006, 03:46 AM under MobileAndEmbedded
I promised I’d let you know when WMDC for RC1 was out. Also given that most people searching for an ActiveSync replacement or for Windows Mobile Device Centre land on my blog, it is only fair that I let you have some links!

WMDC Beta3 page here. (Notice how now there is also support for Windows Mobile 2003 :))

How did I know? I got notified via the download center RSS feed (don’t tell me you are not subscribed to that?!) about the download page.

Problem fixed...

Fri, October 6, 2006, 01:36 AM under Windows | Vista
When I booted up my laptop today, with no intervention on my behalf, an unobtrusive message in a balloon on the tray informed me that there were solutions to my problems (or words to that effect, I doubt Vista can do anything about my real problems :)). So I clicked on it and it took me to the Problem Reports and Solutions window! See it below:

When I click on the "Problem fixed in Windows Vista final release" link, it take me to another page that looks like this (screenshot).

On that last screenshot, when I click on "See related problems" it shows me exactly what problem it is talking about, as you can see below:

If I then double-click on the item in the listview it takes me to the bucket/info that was sent up to winqual and thus it closes the loop (screenshot).

Have I told you that I love the new WER architecture more and more every day :)

Silent ones are the worst!

Thu, October 5, 2006, 03:37 PM under dotNET
The problem
When I was trying to call the WerRegisterFile API as described previously, I run into an interesting situation: Calling the API without specifying any CharSet should have attempted first the WerRegisterFile. If I specify CharSet.Auto, it should first attempt WerRegisterFileW and if it cannot find that then go back to try WerRegisterFile. Either way, you would have thought that this would succeed or blow. As it turns out, leaving the CharSet off, silently fails (no exception, return value is 0, Marshal.GetLastWin32Error is 0 etc) but specifying CharSet.Auto works as expected! For the record, CharSet.Unicode behaves like CharSet.Auto and CharSet.Ansi fails like when we omit altogether CharSet from the DllImport declaration.

Download a repro VS2005 project here (obviously requires Vista).

Looking at kernel32.dll (which exports this function) shows that there is only one entry for the API (screenshot of dumpbin). This seems to be a pattern with Vista, according to my colleague MikeT.

Well it seems that after a series of chats with Mike, he updated his post with useful thoughts. Read his 4th thought in the updated section and come back... I’ll wait...

[...time passes...]

So to prove the thought, I looked at another Vista API that takes strings: RegisterApplicationRestart. It too has no trailing A or W (screenshot). So calling this API without CharSet also gives no errors, but the string you get passed back to the application at the command line is definitely not the one I passed to it (something Chinese-looking on my system when I gave it something English).

That rests the case. I should have realised earlier that CharSet is not just about finding the correct entry point but also about how the string will be marshalled.

As an excuse I should state that, having mostly coded for WinCE, I think I have been spoilt since that is all Unicode and I can’t remember using CharSet with any of NETCF pinvokes and they all worked fine :)

Final thoughts
1. Whoever thought the default of CharSet should be Ansi has a lot to answer for. Note that it is a C# decision as the CLR defaults to Auto!
2. I wonder if the Vista change (that threw me off track) is going to bite others or if it just muppets like me that fell for it :S
3. Why is WerRegiserFile in kernel32.dll when all the other WER APIs are in wer.dll?!
4. WerRegisterFile should be giving some indication to the developer that it failed. At the end of the day, you give it a path (string), it thinks it is a different string (path), so it cannot find the file and then it silently fails! WTF?
5. I detest silent failures. Make an explosion next time. A big loud one or a quiet one, but not a silent one. Silent ones are the worst!

DDD4, LDNUG and event review

Thu, October 5, 2006, 03:26 AM under Events
Eric Wroolie wrote (what I think is) a nice review of my event from a couple of days ago and has some interesting thoughts on attending webcasts versus attending live events. I strongly encourage you to go read and share your own thoughts there.

Having read that, you should now be inspired to attend a live event so if you can make it to London on October 18th, head over to the London Dot Net User Group where Ian is preparing a nice line-up and it is all for free! (full details available over the next few days)

If that is too soon for you, definitely plan to make it for DDD4 that is also free. Even better, you can shape the day by voting now for the sessions you'd like to see! How cool is that? :)


Thu, October 5, 2006, 02:53 AM under dotNET
This post just serves as a background URL that I can link to from my next post later :)

We all know that to call unmanaged code from managed code you have to pinvoke (i.e. use the DllImport attribute). One of the enumerations that becomes relevant when calling native methods that accept strings is CharSet.

It is also relevant for native structures with strings but I am explicitly ignoring that in this post. I am also ignoring the CharSet.None enumeration as it means the same as CharSet.Ansi and is there for C++ legacy reasons, I think.

CharSet is useful so you can instruct the runtime to invoke the "A" version of an API or the "W" version (Ansi or Unicode) e.g. MessageBoxA or MessageBoxW. If you select CharSet.Ansi the CLR attempts to invoke an entry point with an appended "A" if the entry point specified by the signature doesn't exist. If you select Auto, then on modern OSs it will default to Unicode. This means the CLR will attempt to invoke an entry point with an appended "W" before attempting to invoke the entry point specified by the signature. If you miss the CharSet from your DllImport declaration, the default is Ansi with the behaviour described above.

Wed, October 4, 2006, 09:42 AM under dotNET
In my Vista sessions I focus on accessing native APIs form managed code. A few times now people ask me if there is an API browser of some sort... you know, like the API Text Viewer from the VB6 times... I found this replacement on the web but haven’t personally tried it. Frankly, I don’t know of a Microsoft one so if there is a replacement hiding somewhere and you know about it please share a pointer!

So the alternative I offer is... the alternative I have always offered! The title gives it away:
If you read my older entry then you’ll know where to go to get the interop book.

There is also a Visual Studio 2005 add-in for the pinvoke wiki site, but I haven’t personally tried it. Get it from gotdotnet.

I plan to update the wiki with Vista API definitions at some point (the power API I mentioned previously is already there). I’ve added this to my TODO list (item # 88345602), but if you feel you’d like to take on the task, please go for it (Vista dllimports all over my blog entries since May this year)!


Wed, October 4, 2006, 04:36 AM under Windows | Vista
At a talk last week, while demoing the Vista application recovery mechanism, a delegate (no pun intended!) asked me if he could access UI elements (e.g. textbox contents) from the recovery function (i.e. in my sample, the RecoveryIt method).

The stock answer is that in your recovery method you should not be spending too much time doing anything and should make no assumptions for any application state as you have just crashed and hence who knows what is valid and what not. Try and do something that is fairly autonomous.

Having said that, from trial and error, I can tell you that you can write to files (as the sample shows), you can create threads, access private variables (and hence navigate object structures) and even the form's handle is valid.

Note that the method runs on a worker thread (that is donated by the OS in the recovery scenario); it is easily provable by sticking the following line of code in the recovery method:
MessageBox.Show(Thread.CurrentThread.IsBackground.ToString()); //true

So, based on the previous sentence, it is obvious that you cannot touch UI elements from that method (we know that we have to be on the main thread to do that). Even if you try to use Invoke/BeginInvoke, you still won't get very far. The point here is that you should treat the UI as frozen or in other words don't rely on the availability of a message pump...

Also, here is an extract of the bullet points from the slide that accompanies my demo:
+ Recovery routine called after data collection
--+ Application’s code attempts to recover user work
----+ Flush to disk, repair on next run of application
----+ Repair data in memory, save to disk

Hope this helps.

Mobile cross-platform development

Tue, October 3, 2006, 03:00 AM under MobileAndEmbedded
A topic I've done a lot of work on in the past and just one of the areas covered in Nick Randolph's podcast so go listen here (funny American and Aussie accents aside :-p).

Inspired by the podcast, I gathered some of the relevant blog posts I've written on the subject in chronological order (click on the numbers): 1, 2, 3, 4, 5, 6, 7, 8, 9

Favourite quote by Nick near the end (47:51):
" need the equivalent of the vb6 to converter/wizard... you'd run it on a VB6 app and it would come back with 18 million lines of code that had to be changed and your application only had 500K lines of code! "
LOL... been there, done that, got the t-shirt :D

Microsoft Developer Show #8

Vista: WerRegisterFile

Mon, October 2, 2006, 05:52 AM under Windows | Vista
Did you know that on Vista you can add your own files to the reports of WER?

Here are some steps for achieving that.

1. Create a brand new VS2005 WinForms project on Vista and name it "WerRegisterFile". Add a button to the form and in its event handler stick the following:
    private void button1_Click(object sender, EventArgs e)
// simulate crash
Environment.FailFast("bye bye");
Build and run the project from the file system to observe WER in action
a) First windows checks if there is a solution to the problem (screenshot).
b) Then it asks the end user to confirm that they'd like to send the report (screenshot)
c1) it then (asynchronously) proceeds with sending the data (e.g. Version.txt, minidump.mdmp) to winqual (screenshot). Note: this can be instantaneous and capturing that screenshot required blistering mouse movement

c2) it then informs the user to close the program (screenshot). Note that if the app registers for restart, then you won't see this dialog and instead the application will re-launch itself :-)

Let's enhance the WER process by adding our own file to send to winqual:

2. In the form paste the following pinvoke declarations:
    internal const int WerRegFileTypeOther = 2;
internal const int WER_FILE_ANONYMOUS_DATA = 2;

[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = CharSet.Auto)]
internal static extern int WerRegisterFile(string pwzFile, int regFileType, int dwFlags);
3. Anywhere in your project (e.g. form_load, form ctor, button_click etc) before the application crashes make the following call:
WerRegisterFile("danielmoth.txt", WerRegFileTypeOther, WER_FILE_ANONYMOUS_DATA);
4. Go to the build directory of your solution (e.g. bin\release) and create a file named "danielmoth.txt"

Now, when you rebuild and then run the exe form the file system, you'll observe the same screenshots /behaviour as above. So how can we inspect that our own file was sent (other than visiting winqual and checking there)? Well, with 'Problem Reports and Solutions' of course!

Find the entry for "WerRegisterFile" (check the date/time to verify that it was just generated). Click on it and you are presented with the following dialog (I've highlighted with the red arrow the evidence that our file was sent):

If you click on the "View a temporary copy of these files" then you get to view a copy of exactly what was sent.

That's all folks :)

Some quick notes:
i) Remember that if you don't have an internet connection, these reports are queued and you can still view them following the steps I outlined before

ii) If you replace step 1 at the top with the alternative crash I described here (steps a & b), then in the last screenshot where it reads "Problem Signature 09" instead of "FatalError" it would say "System.DivideByZeroException"

iii) In addition to crashes and hangs, you can create and submit reports for other events. Surf the relevant APIs by starting here at WerReportCreate and then examine the APIs in the ‘Remarks’ section (and if you create a cool demo with those please drop me a line!).

Vista: Problem Reports and Solutions

Sun, October 1, 2006, 08:59 AM under Windows | Vista
I've talked about Windows Error Reporting in Vista before, but I don't think I explained how to examine locally the reports that have been sent (or that are in a queue to be sent, since with Vista that is what happens when there is no network connection).

From the Control Panel, navigate to 'System and Maintenance' and click the option that reads "Problem Reports and Solutions". You should have a screenshot similar to the following:

I encourage you to explore all of those options on the left, for example if you select "View problem history", then you are presented with a list that I am sure you'll find interesting. On my machine it looks as follows (you can drill into each report further as we'll see in my next blog entry):

Another relevant UI worth exploring is the "Reliability Monitor"
(...from the 'System and Maintenance' click on 'Performance Information and Tools' and then click on 'Advanced Tools' from the left).