The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Apr 28, 2026
Post comments count 4
Post likes count 0

Developing a cross-process reader/writer lock with limited readers, part 1: A semaphore

Raymond Chen

A pot of tokens.

Apr 27, 2026
Post comments count 4
Post likes count 1

Looking at consequences of passing too few register parameters to a C function on various architectures

Raymond Chen

It's bad news no matter how you slice it, but Itanium makes it even worse.

Apr 24, 2026
Post comments count 3
Post likes count 2

Defending against exceptions in a scope_exit RAII type

Raymond Chen

But maybe it's not worth it.

Apr 23, 2026
Post comments count 12
Post likes count 2

Another crash caused by uninstaller code injection into Explorer

Raymond Chen

Inadvertently destroying a staircase while standing on it.

Apr 22, 2026
Post comments count 2
Post likes count 3

Mapping the page tables into memory via the page tables

Raymond Chen

So-called "fractal page mapping".

Apr 21, 2026
Post comments count 29
Post likes count 3

Sure, xor’ing a register with itself is the idiom for zeroing it out, but why not sub?

Raymond Chen

Somehow xor became the most popular version.

Apr 20, 2026
Post comments count 1
Post likes count 3

How did code handle 24-bit-per-pixel formats when using video cards with bank-switched memory?

Raymond Chen

You still have to use aligned accesses, even though the pixels might not be aligned.

Apr 17, 2026
Post comments count 1
Post likes count 4

Forgotten message from the past: LB_INIT­STORAGE

Raymond Chen

Preallocating memory to avoid quadratic behavior.

Apr 16, 2026
Post comments count 9
Post likes count 2

What’s up with window message 0x0091? We’re getting it with unexpected parameters

Raymond Chen

Trespassing on system messages.

Apr 15, 2026
Post comments count 0
Post likes count 2

Why is there a long delay between a thread exiting and the Wait­For­Single­Object returning?

Raymond Chen

Maybe it didn't really exit.

Apr 14, 2026
Post comments count 2
Post likes count 3

Why was there a red telephone at every receptionist desk?

Raymond Chen

Not a direct line to Bill Gates's office.

Apr 13, 2026
Post comments count 8
Post likes count 1

Finding a duplicated item in an array of N integers in the range 1 to N − 1

Raymond Chen

Taking advantage of special characteristics of the array.

Apr 10, 2026
Post comments count 3
Post likes count 2

How do you add or remove a handle from an active Wait­For­Multiple­Objects?, part 2

Raymond Chen

Waiting for the waiting thread to acknowledge the change.

Apr 9, 2026
Post comments count 4
Post likes count 2

How do you add or remove a handle from an active Wait­For­Multiple­Objects?

Raymond Chen

You can't, but you can cooperate with the other thread.

Apr 8, 2026
Post comments count 4
Post likes count 2

How do you add or remove a handle from an active Msg­Wait­For­Multiple­Objects?

Raymond Chen

You can't, but you can arrange for the waiter to do it for you.

Apr 7, 2026
Post comments count 9
Post likes count 6

Were there any Windows 3.1 programs that were so incompatible with Windows 95 that there was no point trying to patch them?

Raymond Chen

The permanently ineligible list.

Apr 6, 2026
Post comments count 3
Post likes count 2

Learning to read C++ compiler errors: Illegal use of -> when there is no -> in sight

Raymond Chen

If the compiler is complaining about things you didn't write, find out who wrote them.

Apr 3, 2026
Post comments count 3
Post likes count 2

How can I use Read­Directory­ChangesW to know when someone is copying a file out of the directory?

Raymond Chen

File copying is not a fundamental operation, nor is it even detectable at the file system layer.

Apr 2, 2026
Post comments count 0
Post likes count 4

Why doesn’t the system let you declare your own messages to have the same semantics as WM_COPY­DATA?

Raymond Chen

Tempting but misleading.

Apr 1, 2026
Post comments count 17
Post likes count 14

The cover of C++: The Programming Language raises questions not answered by the cover

Raymond Chen

What are we reading about here?

Mar 31, 2026
Post comments count 21
Post likes count 4

Before you check if an update caused your problem, check that it wasn’t a problem before the update

Raymond Chen

It was going to be like that when I got here.

Mar 30, 2026
Post comments count 4
Post likes count 3

A question about the maximimum number of values in a registry key raises questions about the question

Raymond Chen

Why is this even a question?

Mar 27, 2026
Post comments count 1
Post likes count 4

What if a dialog wants to intercept its own message loop?

Raymond Chen

You can steal them from your owner.

Mar 26, 2026
Post comments count 3
Post likes count 3

Why doesn’t WM_ENTER­IDLE work if the dialog box is a Message­Box?

Raymond Chen

Because it opted out.

Mar 25, 2026
Post comments count 2
Post likes count 4

How can I change a dialog box’s message loop to do a Msg­Wait­For­Multiple­Objects instead of Get­Message?

Raymond Chen

The dialog box lets you change how it waits.

Mar 24, 2026
Post comments count 6
Post likes count 6

Windows 95 defenses against installers that overwrite a file with an older version

Raymond Chen

A very primitive version of recovery.

Mar 23, 2026
Post comments count 14
Post likes count 4

How can I make sure the anti-malware software doesn’t terminate my custom service?

Raymond Chen

You'll have to ask nicely.

Mar 20, 2026
Post comments count 6
Post likes count 2

Windows stack limit checking retrospective: arm64, also known as AArch64

Raymond Chen

Wrapping things up.

Mar 19, 2026
Post comments count 8
Post likes count 3

Windows stack limit checking retrospective: amd64, also known as x86-64

Raymond Chen

Reaching the modern day.

Mar 18, 2026
Post comments count 1
Post likes count 1

Windows stack limit checking retrospective: Alpha AXP

Raymond Chen

Double the size, double the fun.

Mar 17, 2026
Post comments count 2
Post likes count 4

Windows stack limit checking retrospective: x86-32 also known as i386, second try

Raymond Chen

Appeasing the invisible return address predictor.

Mar 16, 2026
Post comments count 0
Post likes count 3

Windows stack limit checking retrospective: PowerPC

Raymond Chen

Doing the math backwards.

Mar 13, 2026
Post comments count 4
Post likes count 3

Windows stack limit checking retrospective: MIPS

Raymond Chen

Optimizing out the unnecessary probes comes with its own complexity.

Mar 12, 2026
Post comments count 9
Post likes count 3

Windows stack limit checking retrospective: x86-32, also known as i386

Raymond Chen

One of the weirdest calling conventions you'll see.

Mar 11, 2026
Post comments count 6
Post likes count 6

How do compilers ensure that large stack allocations do not skip over the guard page?

Raymond Chen

Don't take steps that are too large.

Mar 10, 2026
Post comments count 3
Post likes count 5

A snappy answer when asked about dressing casually at IBM

Raymond Chen

Oh, this old thing?

Mar 9, 2026
Post comments count 8
Post likes count 2

The fine print giveth and the bold print taketh away: The countdown timer

Raymond Chen

Think fast, no pressure.

Mar 9, 2026
Post comments count 2
Post likes count 2

Learning to read C++ compiler errors: Ambiguous overloaded operator

Raymond Chen

Look for the conflicting definitions to see where they are coming from.

Mar 6, 2026
Post comments count 11
Post likes count 2

When Read­Directory­ChangesW reports that a deletion occurred, how can I learn more about the deleted thing?

Raymond Chen

It's already gone. If you need more information, you should have been remembering it.

Mar 5, 2026
Post comments count 2
Post likes count 2

The mystery of the posted message that was dispatched before reaching the main message loop

Raymond Chen

Perhaps it's because you dispatched it.

Mar 4, 2026
Post comments count 6
Post likes count 2

Aha, I found a counterexample to the documentation that says that Query­Performance­Counter never fails

Raymond Chen

Of course, anything can happen if you break the rules.

Mar 3, 2026
Post comments count 18
Post likes count 2

Just for fun: A survey of write protect notches on floppy disks and other media

Raymond Chen

Just some useless trivia.

Mar 2, 2026
Post comments count 3
Post likes count 1

What sort of horrible things happen if my dialog has a non-button with the control ID of IDCANCEL?

Raymond Chen

You get notifications that might not make sense.

Feb 27, 2026
Post comments count 3
Post likes count 2

Intercepting messages inside Is­Dialog­Message, fine-tuning the message filter

Raymond Chen

Making sure it triggers when you need it, and not when you don't.

Feb 26, 2026
Post comments count 1
Post likes count 2

Intercepting messages inside Is­Dialog­Message, installing the message filter

Raymond Chen

Using an <CODE>Is­Dialog­Message</CODE> extension point.

Feb 25, 2026
Post comments count 4
Post likes count 1

Intercepting messages before Is­Dialog­Message can process them

Raymond Chen

Process the message before you let <CODE>Is­Dialog­Message</CODE> see it.

Feb 24, 2026
Post comments count 2
Post likes count 2

Customizing the ways the dialog manager dismisses itself: Isolating the Close pathway

Raymond Chen

Intercepting the flow in your message loop.

Feb 23, 2026
Post comments count 0
Post likes count 2

Customizing the ways the dialog manager dismisses itself: Detecting the ESC key, second (failed) attempt

Raymond Chen

Sniffing the synchronous keyboard state is still not precise enough.

Feb 20, 2026
Post comments count 0
Post likes count 0

The 2026/2027 Seattle Symphony subscription season at a glance

Raymond Chen

The pocket reference guide for 2026/2027.

Feb 20, 2026
Post comments count 12
Post likes count 3

Customizing the ways the dialog manager dismisses itself: Detecting the ESC key, first (failed) attempt

Raymond Chen

Sniffing the asynchronous keyboard state.

Feb 19, 2026
Post comments count 1
Post likes count 6

Exploring the signals the dialog manager uses for dismissing a dialog

Raymond Chen

Summarizing the flow.

Feb 18, 2026
Post comments count 3
Post likes count 2

Could Write­Process­Memory be made faster by avoiding the intermediate buffer?

Raymond Chen

I guess it could, but why bother?

Feb 17, 2026
Post comments count 8
Post likes count 2

Microspeak: Escrow

Raymond Chen

Final build, final, final, final 2, ship this one.

Feb 16, 2026
Post comments count 10
Post likes count 2

It rather involved being on the other side of the airtight hatchway: Tricking(?) a program into reading files

Raymond Chen

Is it really a trick when reading the file is the purpose of the program?

Feb 13, 2026
Post comments count 10
Post likes count 4

How can I distinguish between the numeric keypad 0 and the top-row 0 in the WM_CHAR message?

Raymond Chen

See if it matches the scan code.

Feb 12, 2026
Post comments count 2
Post likes count 3

How can I distinguish between the numeric keypad 0 and the top-row 0 in the WM_KEY­DOWN message?

Raymond Chen

Check whether it is an extended key.

Feb 11, 2026
Post comments count 0
Post likes count 4

How do I suppress the hover effects when I put a Win32 common controls ListView in single-click mode?

Raymond Chen

You can prevent the item from becoming hot-tracked.

Feb 10, 2026
Post comments count 11
Post likes count 6

How did Windows 95 get permission to put the Weezer video Buddy Holly on the CD?

Raymond Chen

Asking nicely, and asking a lot of people.

Feb 9, 2026
Post comments count 3
Post likes count 3

What should I do if a wait call reports WAIT_ABANDONED?

Raymond Chen

It's your one chance to make amends.

Feb 6, 2026
Post comments count 1
Post likes count 3

How can I prevent the user from changing the widths of ListView columns in version 5 of the common controls?, part 2

Raymond Chen

Preventing the resize cursor from appearing.

Feb 5, 2026
Post comments count 6
Post likes count 2

How can I prevent the user from changing the widths of ListView columns in version 5 of the common controls?

Raymond Chen

Deny changes to the width.

Feb 4, 2026
Post comments count 2
Post likes count 1

Super Bowl LX creates an opportunity for symphonic friendly wagering

Raymond Chen

Betting classical music.

Feb 4, 2026
Post comments count 3
Post likes count 2

How can I prevent the user from changing the widths of ListView columns?

Raymond Chen

You can ask the header to be non-resizing.

Feb 3, 2026
Post comments count 0
Post likes count 8

Some small stories about the giant satellite dish antenna that was behind Microsoft Building 11

Raymond Chen

A little trivia.

Feb 2, 2026
Post comments count 5
Post likes count 2

Studying compiler error messages closely: Input file paths

Raymond Chen

Are you even compiling the correct file?

Jan 30, 2026
Post comments count 1
Post likes count 1

Why not store the SAFEARRAY reference count as a hidden allocation next to the SAFEARRAY?

Raymond Chen

The case of "Bring your own <CODE>SAFEARRAY</CODE>."

Jan 29, 2026
Post comments count 1
Post likes count 2

How can I retain access to the data in a SAFEARRAY after my method returns?

Raymond Chen

Find a way to take ownership.

Jan 28, 2026
Post comments count 0
Post likes count 1

Why did I lose the data even though I called Safe­Array­Add­Ref?

Raymond Chen

You have to use the original pointer, but even that won't be good enough.

Jan 27, 2026
Post comments count 2
Post likes count 2

A digression on the design and implementation of Safe­Array­Add­Ref and extending APIs in general

Raymond Chen

The concerns when adding a feature to an existing API.

Jan 26, 2026
Post comments count 0
Post likes count 3

What’s the difference between Safe­Array­Access­Data and Safe­Array­Add­Ref?

Raymond Chen

Two ways of preserving the data.

Jan 23, 2026
Post comments count 15
Post likes count 6

C++ has scope_exit for running code at scope exit. C# says “We have scope_exit at home.”

Raymond Chen

You can wrap it in an <CODE>IDisposable</CODE>.

Jan 22, 2026
Post comments count 6
Post likes count 3

A simple helper function for attaching a progress handler to a Windows Runtime IAsync­Action­With­Progress or IAsync­Operation­With­Progress

Raymond Chen

It doesn't do much, but it saves typing.

Jan 21, 2026
Post comments count 2
Post likes count 2

On the proper usage of a custom Win32 dialog class

Raymond Chen

You are replacing the window procedure, not the dialog procedure.

Jan 20, 2026
Post comments count 5
Post likes count 2

Microspeak: On fire, putting out fires

Raymond Chen

Dealing with emergencies.

Jan 19, 2026
Post comments count 8
Post likes count 7

What was the secret sauce that allows for a faster restart of Windows 95 if you hold the shift key?

Raymond Chen

An old flag from 16-bit Windows.

Jan 16, 2026
Post comments count 1
Post likes count 2

How can I get the tab index number from a dialog box control?

Raymond Chen

The tab index number is an authoring concept, not a runtime concept.

Jan 15, 2026
Post comments count 26
Post likes count 4

When programs assume that the system will never change, episode 4: Stealing strings

Raymond Chen

The strings are an implementation detail.

Jan 14, 2026
Post comments count 0
Post likes count 1

Clipping the focus item when looking for its on-screen location, part 3

Raymond Chen

Finding <I>all</I> the clipping parents.

Jan 13, 2026
Post comments count 1
Post likes count 2

Clipping the focus item when looking for its on-screen location, part 2

Raymond Chen

Finding the correct clipping parent.

Jan 12, 2026
Post comments count 0
Post likes count 2

Clipping the focus item when looking for its on-screen location

Raymond Chen

Preventing the cursor from pointing to nothing.

Jan 9, 2026
Post comments count 1
Post likes count 1

Using Active Accessibility to find out where the focus item is

Raymond Chen

Looking at child objects.

Jan 8, 2026
Post comments count 4
Post likes count 2

Using Active Accessibility to find out where the Windows caret is

Raymond Chen

It's old and rather simple, but we like simple.

Jan 7, 2026
Post comments count 1
Post likes count 1

How can I find out where the Windows caret is?

Raymond Chen

You'll have go to a larger scope.

Jan 6, 2026
Post comments count 1
Post likes count 2

Swapping two blocks of memory that reside inside a larger block, in constant memory, refinement

Raymond Chen

Could do with a little less rotating.

Jan 5, 2026
Post comments count 1
Post likes count 3

How can you swap two non-adjacent blocks of memory using only forward iterators?

Raymond Chen

Applying the rotation trick to our new problem.

Jan 2, 2026
Post comments count 0
Post likes count 2

How can you swap two adjacent blocks of memory using only forward iterators?

Raymond Chen

A different algorithm, employing a different kind of cleverness.

Jan 1, 2026
Post comments count 10
Post likes count 2

Swapping two blocks of memory that reside inside a larger block, in constant memory

Raymond Chen

A variation on the constant-memory rotation.

Dec 31, 2025
Post comments count 5
Post likes count 2

2025 year-end link clearance

Raymond Chen

Another year gets relegated to history.

Dec 31, 2025
Post comments count 1
Post likes count 2

Understanding and mitigating a stack overflow in our task sequencer

Raymond Chen

The recurring problem of synchronous resumption.

Dec 30, 2025
Post comments count 6
Post likes count 3

Additional notes on color-keyed overlays as a way of doing smooth video rendering

Raymond Chen

Choosing the color-key and other brief discussions.

Dec 29, 2025
Post comments count 3
Post likes count 2

The Gävle Goat (Gävlebocken) succumbs in 2025 to a new menace

Raymond Chen

You could blow me over.

Dec 29, 2025
Post comments count 3
Post likes count 2

How can I detect that the system is running low on memory? Or that my job is running low on memory?

Raymond Chen

You can register for a memory notification.

Dec 26, 2025
Post comments count 7
Post likes count 4

Why are we worried about memory access semantics? Full barriers should be enough for anybody

Raymond Chen

You have to find new ways of going faster.

Dec 25, 2025
Post comments count 4
Post likes count 3

Reading the fine print, episode 4: Holiday promotions

Raymond Chen

Checking those validity dates.

Dec 25, 2025
Post comments count 0
Post likes count 3

Why is the last letter of my string not making it to the clipboard?

Raymond Chen

The struggle for null termination.

Dec 24, 2025
Post comments count 1
Post likes count 5

Why does my Ctrl+M accelerator key activate when I press the Enter key?

Raymond Chen

Understanding the difference between keys and characters for accelerators.

Dec 23, 2025
Post comments count 4
Post likes count 5

When irate product support customers demand to speak to Bill Gates

Raymond Chen

So transfer them to his office, or so it seems.

Dec 22, 2025
Post comments count 27
Post likes count 9

All the other cool languages have tryfinally. C++ says “We have tryfinally at home.”

Raymond Chen

The destructor serves as the "finally".

Dec 19, 2025
Post comments count 9
Post likes count 3

A shortcut gives me a weird path for a program shortcut that doesn’t point to the executable, so what is it?

Raymond Chen

It's a placeholder because the shortcut is to an MSI application.

Dec 18, 2025
Post comments count 10
Post likes count 4

Concluding thoughts on our deep dive into Windows clipboard text conversion

Raymond Chen

Stick to Unicode and you'll be fine.

Dec 17, 2025
Post comments count 3
Post likes count 4

Deducing the consequences of Windows clipboard text formats on UTF-8

Raymond Chen

Working out the implications.

Dec 16, 2025
Post comments count 3
Post likes count 2

Why is the Windows clipboard taking the scenic route when converting from CF_TEXT to CF_OEM­TEXT?

Raymond Chen

Something is forcing it down an alternate path.

Dec 15, 2025
Post comments count 3
Post likes count 1

Misunderstanding what the Cricket Celebration Bowl is

Raymond Chen

Apparently, not a bowl of crickets.

Dec 15, 2025
Post comments count 1
Post likes count 4

The Windows clipboard automatic text conversion algorithm is path-dependent

Raymond Chen

When the journey is not half of the fun.

Dec 12, 2025
Post comments count 8
Post likes count 3

Resolving an ambiguity in the Windows clipboard automated text conversion table

Raymond Chen

Who goes first?

Dec 11, 2025
Post comments count 11
Post likes count 3

Studying the various locale mismatch scenarios in Windows clipboard text format synthesis

Raymond Chen

If they don't match, then the 8-bit strings are basically broken already.

Dec 10, 2025
Post comments count 1
Post likes count 1

How does Windows synthesize the CF_LOCALE clipboard format?

Raymond Chen

Getting it from a place that might have been obvious in the past, but maybe not today.

Dec 9, 2025
Post comments count 2
Post likes count 2

How does Windows synthesize CF_UNICODE­TEXT from CF_TEXT and vice versa?

Raymond Chen

Let's ask the locale.

Dec 8, 2025
Post comments count 11
Post likes count 3

How does Windows synthesize CF_OEM­TEXT from CF_TEXT and vice versa?

Raymond Chen

Starting with the easy case, or at least it looks easy.

Dec 5, 2025
Post comments count 11
Post likes count 3

How can my process read its own standard output?

Raymond Chen

You'll have to trick yourself before anybody notices, which may not be possible.

Dec 4, 2025
Post comments count 5
Post likes count 1

How can I read the standard output of an already-running process?

Raymond Chen

You can't. You'll have to do it before the process starts.

Dec 3, 2025
Post comments count 6
Post likes count 5

How do I check whether the user has permission to create files in a directory?

Raymond Chen

Request the directory security attributes that correspond to your proposed operation.

Dec 2, 2025
Post comments count 3
Post likes count 2

Microspeak: Big rocks

Raymond Chen

The large obstacles.

Dec 1, 2025
Post comments count 0
Post likes count 2

How do I get my edit control text to be autoselected when I choose it to be the default focus in my dialog?

Raymond Chen

Remembering some old APIs.

Nov 28, 2025
Post comments count 8
Post likes count 5

How can I have a Win32 drop-down combo box with a read-only edit control?

Raymond Chen

You can ask for its handle and mark it read-only.

Nov 27, 2025
Post comments count 3
Post likes count 5

Message-only windows are for messaging, not as a convenient victim for hosting UI

Raymond Chen

If you want to host UI, use a real window (possibly hidden).

Nov 26, 2025
Post comments count 9
Post likes count 2

At what point in the Windows development cycle is it too late to change the text of a translatable string?

Raymond Chen

The translation team sets the deadline.