Recursively Deleting a directory–with long filename support.

I recently was updating some test code to handle long filename (longer than MAX_PATH) support. My initial cut at the function was something like the following (don’t worry about the VERIFY_ macros, they’re functionally equivalent to asserts): const PCWSTR LongPathPrefix=L"\\\\?\\"; void RecursivelyDeleteDirectory(const std::wstring &strDirectory) { // Canonicalize the input path to guarantee it’s a full…


Reason number 9,999,999 why you don’t ever use humorous elements in a shipping product

I just saw an email go by on one of our self hosting aliases: From: <REDACTED> Sent: Saturday, April 30, 2011 12:27 PM To: <REDACTED> Subject: Spelling Mistake for browser in event viewer Not sure which team to assign this to – please pick up this bug – ‘bowser’ for ‘browser’ And he included a…


Someone is a glutton for punishment

From Long Zheng, a video of someone who decided to upgrade every version of Windows from Windows 1.0 to Windows 7. The amazing thing is that it worked.


It’s a bad idea to have a TEMP environment variable longer than about 130 characters

I’ve been working with the Win32 API for almost 20 years – literally since the very first Win32 APIs were written.  Even after all that time, I’m occasionally surprised by the API behavior. Earlier today I was investigating a build break that took out one of our partner build labs.  Eventually I root caused it to…


I can make it arbitrarily fast if I don’t actually have to make it work.

Digging way back into my pre-Microsoft days, I was recently reminded of a story that I believe was told to me by Mary Shaw back when I took her Computer Optimization class at Carnegie-Mellon… During the class, Mary told an anecdote about a developer “Sue” who found a bug in another developer’s “Joe” code that…


The story behind the mysterious “Ding” in Windows Vista.

I just ran into this fairly old post on Channel 9.  mstefan reported that his applications played a “Ding” noise when selecting an item in a listview (or tree) control.   It turns out that I’d had the problem independently reported to me by one of the people here at Microsoft.  Here were his reproduction…


What’s wrong with this code, part 26 – the answer

Yesterday I posted a code snippet from inside a real piece of code inside the client side of a client/server utility in a Microsoft product. static DWORD WINAPI _PlayBeep(__in void* pv) { UNREFERENCED_PARAMETER(pv); PlaySound(L".Default", NULL, SND_SYNC | SND_ALIAS); return 0; } LRESULT WndProc(…) { : : case WM_KEYDOWN: if (!_AcceptInputKeys(wParam, lParam)) { QueueUserWorkItem(_PlayBeep, NULL, 0);…


What’s wrong with this code, part 26 – a real-world example

This is an example of a real-world bug that was recently fixed in an unreleased Microsoft product.  I was told about the bug because it involved the PlaySound API (and thus they asked me to code review the fix), but it could happen with any application. static DWORD WINAPI _PlayBeep(__in void* pv) { UNREFERENCED_PARAMETER(pv); PlaySound(L".Default"NULL,…


Delay Load is not a good way to check for functionality

On my previous post, Koro made the following comment: “Don’t ever check windows versions.  Instead check for functionality being present or not." You can’t always do that. Do I want to add a __try/__except to catch delay-load exceptions around every UxTheme call or just do: g_bTheme=(g_bWinNT&&(g_nWinVer>0x00050001)); Then check that flag before calling OpenThemeData? In some…


Checking file versions is surprisingly hard.

I was wandering around the web the other day and ran into this post.  In general I don’t have many issues with the post, until you get to the bottom of the article.  The author mentions that his code only runs on Win7 or newer so he helpfully included a check to make sure that…