The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts

Memory allocation functions can give you more memory than you ask for, and you are welcome to use the freebies too, but watch out for the free lunch

Memory allocation functions like , , , and all have the property that they can return more memory than you requested. For example, if you ask for 13 bytes, you may very well get a pointer to 16 bytes. The corresponding functions return the actual size of the memory block, and you are welcome to use all the memory in the block up to the actual size (even the bytes beyond the ones you requested). But watch out for the free lunch. Consider the following code: So far so good. We allocate some memory, and then fill it with zeroes. That gives us our zero-initialized memory. Or does it? When you ask the hea...

Why does the VerQueryValue function give me the wrong file version number?

A customer was writing a test to verify that their patching system was working properly, but they found that even after the patch was installed, a call to reported that the file was still the original version. Why was the function reporting the wrong version? Recall that the version resource is, well, a resource. And one of the things that happens with resources is that they can get redirected based on the language the user is running. When you ask for the resources of a language-neutral DLL, the loader redirects your request to the appropriate language-specific DLL. That way, if you're running on an English ...

How do I get mouse messages faster than WM_MOUSEMOVE?

We saw some time ago that the rate at which you receive messages is entirely up to how fast your program calls . But what if your program is calling as fast as it can, and it's still not fast enough? You can use the function to ask the window manager, "Hey, can you tell me about the mouse messages I missed?" I can think of two cases where you might want to do this: You are a program like Paint, where the user is drawing with the mouse and you want to capture every nuance of the mouse motion. You are a program that supports something like mouse gestures, so you want the full mouse curve informatio...

Microspeak: Friction

In physics, friction is a force that resists motion. In Microspeak, friction is an obstacle which prevents somebody from doing something you want them to do. (The preferred verb phrase for getting over an obstacle is overcoming friction.) There is friction in the system for X that is reduced when developing with Y. Using X reduces friction of someone being able to do Y without having to Z. Many companies have found that outsourcing activities can introduce unexpected complexity, add cost and friction into the value chain, and require more senior management attention and deeper management skills than anticip...

If you have multiple versions of Windows installed, why do they all try to adjust the clock?

Commenter Martin notes that if you have multiple copies of Windows installed on your machine, then each one will try to adjust the clock when you enter or exit daylight saving time. "I cannot believe that this feature is a bug. Please could you comment this?" This falls into a category of issue that I like to call "So what did you expect?" (This was the catch phrase of the old Call-A.P.P.L.E. magazine.) If you have multiple operating systems installed on your machine, each one thinks that it has control of your computer. It's not like there's some standard cross-operating system mechanism for negotiating cont...

To some people, time zones are just a fancy way of sounding important

Standard time sounds much more standard.

Alt text for images are important in email, too

Apparently the IT department gave up on getting everybody to read email in plain text, and other service departments at Microsoft have moved beyond simply using HTML for markup and started adding banner images to the top of each email message. Because the best way to promote your brand to other parts of the company is to stick a banner logo at the top of every message. Here's the HTML for one such banner image, with line breaks inserted for sanity. The great thing about the absurd alt text is that that's what appears in the autopreview window and in the email notification pop-up. But wait, it gets wors...

Why do program files go into the Program Files directory?

Some of Microsoft's software certification programs (such as the Windows Logo) require that applications set their default installation location to the Program Files directory. What is the reason for this? One technical reason is that this ensures that the directory receives an appropriate default security descriptor. But the Program Files directory was introduced in Windows 95, which didn't have security descriptors, so that can't be the entire reason. Rewind the clock to Windows 3.1. Microsoft didn't provide guidance on where applications should install by default. As a result, they went everywhere....

Why does Explorer ignore seconds when sorting by Date Modified?

A customer reported that Explorer appears to be ignoring the seconds when sorting by Date Modified. The customer was kind enough to include detailed steps to reproduce the problem. Start with a folder with several files, sorted by Date Modified. Right-click on the newest file, select Copy. Right-click on the blank column on the right, select Paste. This will create a file with the same name, but with "- Copy" appended. Press F5 to refresh the view and note the sort order. The copy appears at the top of the list. Highlight the newly-created file, hit F2, and give the document a different name, an...