The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Feb 10, 2014
Post comments count 0
Post likes count 1

Execute a file as if it were a program, even though its extension is not EXE

Raymond Chen

Today's Little Program executes a file as if it were a program, even though its extension is not EXE. The idea here is to prevent somebody from running your program by accident, so you give it an extension like . This is great for preventing somebody from running the program by mistake, but how do you do it on purpose? We're merely using the member of the structure to force the file to be interpreted as the type we specify, overriding the default type inference code.

Feb 7, 2014
Post comments count 0
Post likes count 1

VirtualLock locks your memory into the working set, even if your threads are blocked

Raymond Chen

Today, a correction to an earlier article on . When you lock memory with , it will remain locked even if all your threads are blocked. As noted in the Follow-up section at the end of the referenced article, the behavior of the operating system never changed. Virtually-locked pages were never unlocked in practice. What changed is that an implementation detail was elevated to contract. The intention when was originally designed was that virtually-locked pages were potentially unlockable if the application is not running. However, the memory manager folks never got around to implementing that part. At some point,...

Feb 6, 2014
Post comments count 0
Post likes count 0

The United States Team uniforms for the opening ceremony is rather hideous, and illegal, and a bit anachronistic

Raymond Chen

By the time you read this, the opening ceremony for a large sporting event organized by a lawsuit-happy organization may already have taken place. As part of the ceremony, the team representing the United States entered wearing ugly uniforms. They're so ugly that even the hideous Christmas sweater in your closet, the one with the reindeer and wreaths and candy canes, actually steps out, points, and laughs, saying "Ha ha, what an ugly sweater!" If you study the picture carefully, you will observe a number of things. First of all, the incorporation of the flag into the sweater pattern (and once in the pants) v...

Feb 6, 2014
Post comments count 0
Post likes count 1

If an asynchronous I/O completes synchronously, is the hEvent in the OVERLAPPED structure signaled anyway?

Raymond Chen

Yes. When an I/O completes (whether synchronously or asynchronously), the event is signaled and completion status notifications are queued. The function can be used to wait on an I/O that has already completed; it will merely return immediately. If you ask whether the I/O has completed, and the I/O completed synchronously, it will correctly report, "Yeah, of course it completed. Heck, it completed a long time ago!" In other words, you can logically treat the case of an asynchronous I/O request completing synchronously as if it had completed asynchronously. It just completes asynchronously before you even blin...

Feb 5, 2014
Post comments count 0
Post likes count 1

How do I prevent folders like My Pictures from being recreated?

Raymond Chen

Another converse of How do I programmatically create folders like My Pictures if they were manually deleted? and Why do folders like "My Pictures" come back after I delete them? is How do I prevent folders like My Pictures from being recreated? Starting in Windows 7, there is a group policy called Disable Known Folders which lets you specify a list of known folders which should be disabled. If somebody tries to create a known folder programmatically, the call will fail with . Note that this policy only blocks creation of the folder. If the folder already exists, then the policy has no effect. (You're l...

Feb 4, 2014
Post comments count 0
Post likes count 1

Racing email against a snail

Raymond Chen

The Windows team double-dogfoods Windows Server and Exchange Server, and while this is good for both products, it can be quite frustrating when something goes wrong. I remember back in the early days of the Windows 95 project, the mail servers once got so messed up that some email messages were not delivered for several days. After a colleague told me that he had just received an email message that I had sent several days earlier, I went to the library to look up the typical speed of a garden snail. (This was back in the days when you had to use an actual library to look up facts, and cat videos were avail...

Feb 3, 2014
Post comments count 0
Post likes count 0

The new research citation format, if students got to design it

Raymond Chen

References ¹ The Internets. ² Ibid. ³ Ibid.

Feb 3, 2014
Post comments count 0
Post likes count 1

How can I make a WNDPROC or DLGPROC a member of my C++ class?

Raymond Chen

Continuing my discussion of How can I make a callback function a member of my C++ class? Common special cases for wanting to use a member function as a callback function are the window procedure and its cousin the dialog procedure. The question, then, is where to put the reference data. Let's start with window procedures. The function and its close friend let you pass your reference data as the final parameter, prototyped as . As noted in the documentation, that value is passed back to the window procedure by the and messages as part of the structure. One of the first messages passed to a window is , s...

Jan 31, 2014
Post comments count 0
Post likes count 0

Why chicken wings dominate Super Bowl snack time

Raymond Chen

This upcoming Sunday is the biggest sports day of the year in the United States: The championship game for the professional American Football league. The entire country grinds to a halt. The most famous secondary effect of the game is the commercials. So many people watch the game that television advertisement costs are the highest for the Super Bowl, which means that companies will produce spectacular ads specifically for the Super Bowl, which means that more people watch the Super Bowl just for the ads. Another secondary effect of the Super Bowl is the spike in chicken wing sales. The United States chicken ...