The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Nov 26, 2009
Post comments count 0
Post likes count 0

I want to take all your chocolate milk

Raymond Chen

My older niece visited me at work one day, and I got her a carton of chocolate milk, which she very much enjoyed. Some days later, she told me, "I want to go to your work." "Why?" I asked. "I want to take all your chocolate milk." Missing from the story is that upon returning home after that first visit, she told everybody about her awesome visit with her uncle, and that he even got her a chocolate milk from the refrigerator. "And the chocolate milk is free, you can just take it!" Her uncle (not me, a different uncle) told her, "Then you should go there with a knapsack and take all the chocolate milk." That ...

Nov 26, 2009
Post comments count 0
Post likes count 1

When you want to copy a file into a folder, make sure you have a folder

Raymond Chen

This story is inspired by an actual customer problem. The program is used for TPS management, and when you want to create a new TPS report, you have to pick a cover sheet. The program shows you the cover sheets that have been defined, which it loads from the directory. The customer found that on one of the machines, the cover sheets weren't showing up, even though the standard system setup copies a sample cover sheet into the directory. The error message they got was Cannot load cover sheets. The directory name is invalid. The customer did some troubleshooting and determined that "The cover sheet direc...

Nov 25, 2009
Post comments count 0
Post likes count 0

The magic of chocolate milk

Raymond Chen

While enjoying a meal with my nieces (at the time, ages 3 and 5), I diluted my chocolate milk to cut the sweetness. The nieces then demanded that I dilute their chocolate milk as well, because as far as they could determine, it was a magical way to create more chocolate milk.

Nov 25, 2009
Post comments count 0
Post likes count 1

How do I get the command line of another process?

Raymond Chen

Win32 doesn't expose a process's command line to other processes. From Win32's point of view, the command line is just a conveniently initialized parameter to the process's startup code, some data copied from the launching process to the new process and forgotten. We'll get back to the Win32 point of view a little later. If you look around in WMI, you'll find a object, and lo and behold, it has a property. Let's check it out, using the standard WMI application: I fully anticipate that half of my readers will stop right there. "Thanks for the script. Bye!" And they won't bother reading the analysis. "Bec...

Nov 24, 2009
Post comments count 0
Post likes count 0

When computer programmers dabble in making change

Raymond Chen

My colleague who dabbled in economics when deciding how many lunch vouchers to buy had a number of other money-related quirks. One of the ones that I remember is that when paying for a purchase, my colleague would double the balance and give the cashier that much money. For example, if the total was $5.20, my colleague would hand over $10.40. Why? Just to see if the cashier reacted when pressing the Enter code appeared to have no effect. Total is $5.20. Cash tendered is $10.40. Change is $5.20. Most of the time, the cashier wouldn't pay any attention. Heck, the cashier wouldn't even question why my collea...

Nov 23, 2009
Post comments count 0
Post likes count 2

Can I talk to that William fellow? He was so helpful

Raymond Chen

His friends call him Bill.

Nov 20, 2009
Post comments count 0
Post likes count 1

The difference between assignment and attachment with ATL smart pointers

Raymond Chen

Last time, I presented a puzzle regarding a memory leak. Here's the relevant code fragment: The problem here is assigning the return value of to a smart pointer instead of attaching it. The function creates a memory stream and returns a pointer to it. That pointer has a reference count of one, in accordance with COM rules that a function which produces a reference calls , and the responsibility is placed upon the recipient to call . The assignment operator for is a copy operation: It s the pointer and saves it. You're still on the hook for the reference count of the original pointer. Observe that as...

Nov 19, 2009
Post comments count 0
Post likes count 1

We're using a smart pointer, so we can't possibly be the source of the leak

Raymond Chen

A customer reported that there was a leak in the shell, and they included the output from Application Verifier as proof. And yup, the memory that was leaked was in fact allocated by the shell: On the other hand, is an object creation function, so it's natural that the function allocate some memory. The responsibility for freeing the memory belongs to the caller. We suggested that the customer appears to have leaked the interface pointer. Perhaps there's a hole where they called and managed to avoid the matching . "Oh no," the customer replied, "that's not possible. We call this function in only one pla...

Nov 18, 2009
Post comments count 0
Post likes count 0

News flash: Healthy people live longer

Raymond Chen

Researchers have determined that people in good physical condition live longer. Who'd'a thunk it?