NxtGenUG chat

Tue, August 22, 2006, 03:36 AM under Random
Those crazy guys from the NxtGenUG are cornering anyone they can find, shoving a microphone in their face and recording short interviews!

Dave caught me at the Office event 2 months ago (little after I joined MS) and the results are up on their site (read or listen).

Vista: Application Recovery

Mon, August 21, 2006, 04:28 PM under Windows | Vista
Out of the many new native functions in Vista, two that I've been looking at using from managed code are the Application Recovery APIs.

There are 9 functions but two are the main ones: RegisterApplicationRestart and RegisterApplicationRecoveryCallback. These two serve two different, but complementary goals:
1. When your application crashes, it automatically restarts
2. When your application crashes, it gets a chance to save some recovery information

To demo this we need:
a) A new Windows Form application that has a button for crashing the application. Something like this:
// crash
private void button2_Click(object sender, EventArgs e)
{
int zero = 0;
int error = 5 / zero;
}
b) We must turn off .NET's exception handling. I've previously talked about global exception handling in .NET 2.0 but I never mentioned the ability to turn off plain exception catching, which we can do in our config file or in the Main function like this:
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
c) We then need to re-declare in managed code the RegisterApplicationRestart like this:
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern uint RegisterApplicationRestart(string pszCommandline, int dwFlags);
Taking advantage of the API involves two lines of code in two different places.
d) First, we need to actually tell Vista that we want to be restarted (do this in your form_load or wherever else you see fit):
RegisterApplicationRestart("some_text_like_eg_pathname ", 0);

e) Second, on startup check if our application crashed last time (and use the string we passed to the API call):
string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1)
{
this.Text = args[1];
}
Now run your app, and after you have called RegisterApplicationRestart, wait for 60 seconds before hitting the button that crashes your app. If you have windows error reporting enabled, you'll see the dialogs for checking for a solution, sending information and sending additional information. This is an interactive process where you can OK or cancel communications with winqual. Either way, once those dialogs are gone, your application will restart :-)

The other relevant restart functions that you could pinvoke are GetApplicationRestartSettings and UnregisterApplicationRestart.

In the next blog post, we'll look at the RegisterApplicationRecoveryCallback.

Using Vista's search in your managed apps

Wed, August 16, 2006, 04:41 AM under Windows | Vista
In an internal conversation, someone indicated they were interested in using “search” from their application. There are two great sources for that:

Catherine’s blog entries and Ian’s screencast.
--
UPDATE: Also see a search sample

Windows Workflow Foundation (WF)

Mon, August 14, 2006, 02:31 AM under dotNET | dotNET
As I described previously, .NET Framework 3.0 is simply adding four elements to the released .NET 2.0 bits. While these library/framework bits are released with Windows Vista at the end of the year, the VS/tools side of things is planned for release next year with Orcas. One of the technologies however will have tool support from the start (with a VS2005 add on) and that is Windows Workflow Foundation (WF). I personally think that this will lead to WF being widely adopted earlier that the others. So if you haven't checked it out yet, now is a great time to start! Below are some online resources to help you out.

If I've missed a good WF link, drop me a line (as always from the link on the left).

1. The central official WF sites on MSDN and the NetFx3 home.

2. A bunch of articles on msdn here, here, here and here.

3. Scott has some truly great articles on his blog here, here, here and here.

4. Watch a bunch of WF webcasts. They are linked from this blog post by Paul Andrew.

5. Plenty of screencasts on channel9 and on our msdn uk nuggets page (from my colleague Mike Tauly, filter nuggets by technology "Workflow Foundation").

6. In addition to any blogs you come across from the links above, examples of good blog posts are these by: Matthew Winkler, Moustafa Ahmed, Nate Talbert and Tom Lake. Also read these on “Why WF” by: James Conard, Dave Green and Dennis Pilarinos.

7. For support, as with any other technology, head for the forums.

And remember, if you are on Windows Vista 5472, the only NetFx technology with full tool support etc is WF :-)
Check out the build matrix on Tom Archer's blog

Speaker Idol

Sun, August 13, 2006, 05:19 PM under Links
I was over at the Tech Ed Europe site to steal a logo for my blog (check it out on the left) and came accross this uber cool concept/contest: Speaker Idol.

Vista glass answers and DwmEnableBlurBehindWindow

Fri, August 11, 2006, 06:06 PM under Windows | Vista
While I have explained how to get glass on Vista with C# (twice), I did leave two open questions (hint: read the last paragraph of my last glass blog post or the stuff below won't make any sense).

Kenny Kerr steps up to the challenge and answers both questions on his article here!
For the answer to "why black" scroll down to the "Painting" section under the form with the red blob on it. For the question of why R=G=B fails, scroll slightly further down under the "Can you see me" forms.

If you don't care about the answers to the questions I posed then still go read Kenny's entry for the excellent clarification on the terminology at the beginning of his article. Even if you are not interested in the answers, terminology or even glass, then go read it for the coverage of other DWM topics. Go!

The other thing Kenny covers is a relevant glass API that I haven't talked about here before: DwmEnableBlurBehindWindow

I won't go into *any* description or give any context as I expect you'll read that on Kenny's blog. But after you've read the native approach, here is a simplified example of a managed version:

Create a new VS2005 winforms project on Vista, delete all Form1 files, add a new empty code file, and paste into it the following (then hit F5):
namespace GlassMoth
{
public class Form2 : System.Windows.Forms.Form
{
public Form2()
{
this.ClientSize = new System.Drawing.Size(200, 200);

System.IntPtr hr =
CreateEllipticRgn(30, 30, 170, 170); //or CreateRectRgn

DWM_BLURBEHIND dbb;
dbb.fEnable = true;
dbb.dwFlags = 1 2;
dbb.hRgnBlur = hr;
dbb.fTransitionOnMaximized = false;
DwmEnableBlurBehindWindow(this.Handle, ref dbb);
}

protected override void OnPaintBackground(
System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.FillRectangle(
new System.Drawing.SolidBrush(System.Drawing.Color.Black),
new System.Drawing.Rectangle(30, 30, 140, 140));
}

#region pinvokes
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern System.IntPtr CreateEllipticRgn(
int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);

public struct DWM_BLURBEHIND
{
public int dwFlags;
public bool fEnable;
public System.IntPtr hRgnBlur;//HRGN
public bool fTransitionOnMaximized;
}

[System.Runtime.InteropServices.DllImport("dwmapi")]
private static extern int DwmEnableBlurBehindWindow(
System.IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind);
#endregion
}
}
Enjoy (believe it or not, I do have one final blog entry to do on glass... stay tuned)!

Vista Windows Experience Index

Thu, August 10, 2006, 01:19 PM under Windows | Vista
Remember the System Performance Rating (the one of the M3)? It is now called Windows Experience Index. Here is the one from my M5 running build 5472.


--
UPDATE: Also see WinSAT

Fun with partitions and Vista 5472

Wed, August 9, 2006, 01:48 PM under Windows | Vista
This is kind of a rant but there may be some useful hidden info for some of you

About a month ago I made the mistake of letting some supposedly experts take my main laptop for 2 hours in order to put Vista 5472 on it (it later became the July CTP). It seemed like a good deal: They would preserve my existing XP installation and create a new partition where they install Vista including all relevant applications that I would put on anyway (e.g. Office 2007 B2TR and all internal utilities for VPN connecting etc). I thought they were going to save me time but when I collected the laptop they had "shot" my XP installation (not exactly shot, but it does blue screen on startup every time rendering it useless).

The other ‘clever’ thing they did was create my Vista partition as 20GB and leave the other one to 40GB+ contrary to what I explicitly asked for.

Anyway, I am not going to tell you that I love 5472 because quite frankly it doesn't work as well as Beta 2 did for me but that is probably due to Toshiba driver issues on the M5 and, besides, that is not the point of this blog post. So today I realised that I actually *really* do need more space on my boot drive.

Luckily, with Vista we get the ability out of the box to extend and shrink partitions. Go to 'Computer' and select 'Manage' to open the 'Disc Management' page. By right clicking on partitions the desired options are there. Great! I shrunk my D partition and that gave me 10GB of unallocated space. When I tried to 'Extend' my C drive though I got the error:
“There is not enough space available on the disk(s) to complete this operation.”

I read on this page that I could try the same operation from the command line, so I did and got this message:
“There is not enough usable free space on specified disk(s) to extend the volume.”

Given that I had 1GB of space and was only trying to extend by 1MB (for test purposes), that didn't seem right. I then played with the unallocated space by creating another drive letter and shrinking/extending it at will: so the feature works, it is just my C drive that can't be extended!

Here is a screenshot of what my setup looked like at the time:


I could bore you with the wasted hours trying to figure this out but it is summarised best here and here. So as you can see in the screenshot above, my C drive is on the end of the disc so it cannot be extended :(

I didn't give up. I thought "well, I am going to have to use Partition magic after all". Tried installing it and it complains about not being administrator. "UAC at work" me thinks. I disable UAC (as previously described here), reboot and I see a black screen informing me that the boot sector is corrupt - brilliant! After moments filled with panic, I managed to hunt down a Vista DVD, booted from that, selected the repair tools and waited with sweat dripping from my forehead while trying to remember the last time I performed a backup… eventually booting from the DVD fixed the problem - phew!!

Back online, I use my favorite search engine to see if it is a known issue and discover that the advice is not to use partition magic or other XP utilities with Vista. Doh!

If anybody has any idea how I can extend my C drive above I would welcome it. What I ended up doing is uninstalling a whole bunch of apps, and reinstalling them selecting D as the install drive. This moves me forward at the moment but is not ideal (plus I haven’t tested this configuration before and no doubt there will be issues with some apps).

The moral of the story: You can bet your life that when RC1 hits us in September, *I* will be the one installing it on my laptop and *not* some other %^$&^£*# person!

This cost me a full day. In hindsight, I could have spent the time repaving... Don't you wish that before starting a task something would tell you how long it will *really* take? [Sigh]

Resources for Mobile CAB

Tue, August 8, 2006, 02:30 PM under MobileAndEmbedded
For all my mobility developer friends, just got word that there is a new resource where you can get and contribute information regarding the Mobile Client Software Factory.

I then looked at Eugenio's latest blog entry and found a sea of resources: bookmarked!

msfeeds.dll

Fri, August 4, 2006, 06:27 AM under IE7 RSS
If you followed the links from my Windows RSS Platform blog entry, you will have found the infamous example of using the RSS API to create a screensaver. In that same MSDN area from the treeview on the left you can find the RSS object model reference. The RSS API allows browsing the feed hierarchy, add/edit/delete the hierarchy, listening for events to changes in the hierarchy and controlling the process of synching/downloading.

Please see my blog post with a short example of utilising managed code for using the RSS API (skip to the code section and keep it in mind while reading the following).

What I want to do here is provide some tips for when you start using the RSS API.
1. It is a COM dll, so locate and reference msfeeds.dll (Microsoft Feeds, version 1.0) from the COM tab in the Visual Studio references dialog
2. This will bring in Microsoft.Feeds.Interop which is also the namespace you use from code
3. Everything starts with the FeedsManager and his RootFolder property (there is always a implicit root folder).
4. The object hierarchy is RootFolder->Subfolder->subfolder->feed->feeditem->feedenclosure
5. Most class/interface members return an object typed as System.Object. That means you have to do some casting in your code e.g. the Feeds and Subfolders properties in my example have to be cast to IFeedsEnum.

To help you navigate the RSS API, in addition to the links and descriptions above, check out the 4 class diagrams I laid out (collectively, the depict the entire API):
FeedManager , Folder and Feed , Item and Enclosure , Events

Now go to our nuggets page and watch one (by MikeT) on how to build an RSS viewer in C# using the API.