The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Mar 23, 2011
Post comments count 0
Post likes count 1

Function requirements are cumulative: If you fail to meet any of them, then all bets are off

Raymond Chen

A customer was having problems with the function: We are looking for a clarification of the behavior of . We have a thread that waits on two handles (call them and ) with , . Under certain conditions, we signal and close from another thread while the wait is in progress. This results in being returned from the wait call. MSDN is not clear on what the expected behavior is here. On the one hand, it says This description implies that the wait should never fail, because the function should have noticed that is signaled before it got around to noticing that was invalid. On the other hand, the documenta...

Mar 22, 2011
Post comments count 0
Post likes count 4

Why is there the message '!Do not use this registry key' in the registry?

Raymond Chen

Under , there is a message to registry snoopers: The first value is called "!Do not use this registry key" and the associated data is the message "Use the SH­Get­Folder­Path or SH­Get­Known­Folder­Path function instead." I added that message. The long and sad story of the Shell Folders key explains that the registry key exists only to retain backward compatibility with four programs written in 1994. There's also a TechNet version of the article which is just as sad but not as long. One customer saw this message and complained, "That registry key and that TechNet article explain ho...

Mar 21, 2011
Post comments count 0
Post likes count 1

How does the C runtime know whether to use the static-linking or dynamic-linking version of the header file?

Raymond Chen

In response to a description of what happens when you get wrong, nksingh asks, "This seems like a problem for the CRT. As far as I know, VC gives you the option of statically or dynamically linking the CRT. But it seems like the headers will have to make a choice to support one thing better than the other. Conditional compilation would work, but then people would have to remember to include a #define somewhere. Is this dllimport vs. static linking thing something the compiler could figure out on its own if you're doing Link-time codegen?" Let's start from the beginning. Yes, this would be a problem for the...

Mar 18, 2011
Post comments count 0
Post likes count 1

You can extend the PROPSHEETPAGE structure with your own bonus data

Raymond Chen

... for when regular strength lParam just isn't enough. A little-known and even less-used feature of the shell property sheet is that you can hang custom data off the end of the structure, and the shell will carry it around for you. Mind you, the shell carries it around by means of and destroys it by just freeing the underlying memory, so whatever you stick on the end needs to be plain old data. (Though you do get an opportunity to "construct" and "destruct" if you register a callback, during which you are permitted to modify your bonus data and the field of the .) Here's a program that illustrates this...

Mar 17, 2011
Post comments count 0
Post likes count 1

What does the "l" in lstrcmp stand for?

Raymond Chen

If you ask Michael Kaplan, he'd probably say that it stands for lame. In his article, Michael presents a nice chart of the various L-functions and their sort-of counterparts. There are other L-functions not on his list, not because he missed them, but because they don't have anything to do with characters or encodings. On the other hand, those other functions help shed light on the history of the L-functions. Those other functions are lopen, lcreat, lread, lwrite, lclose, and llseek. There are all L-version sort-of counterparts to open, creat, and read, write, close, and lseek. Note that we've already uncovere...

Mar 16, 2011
Post comments count 0
Post likes count 1

What’s up with the mysterious inc bp in function prologues of 16-bit code?

Raymond Chen

A little while ago, we learned about the EBP chain. The EBP chain in 32-bit code is pretty straightforward because there is only one type of function call. But in 16-bit code there are two types of function calls, the near call and the far call. A near call pushes a 16-bit return address on the stack before branching to the function entry point, which must reside in the same code segment as the caller. The function then uses a instruction (a near return) when it wants to return to the caller, indicating that the CPU should resume execution at the specified address within the same code segment. By comparison, ...

Mar 15, 2011
Post comments count 0
Post likes count 0

Raymond's highly scientific predictions for the 2011 NCAA men's basketball tournament

Raymond Chen

Once again, it's time for Raymond to come up with an absurd, arbitrary criterion for filling out his NCAA bracket. This year, I look at the strength of the school's football team, on the theory that a school with a strong football team and a strong basketball team has clearly invested a lot in its athletics program. My ranking of football teams is about as scientific as my ranking of basketball teams: (As a special case, USC received its rank of 22 from two years ago, because it was forced to sit out the 2010 season as part of its punishment for "several major rules violations." Now that's what I call dedic...

Mar 15, 2011
Post comments count 0
Post likes count 1

Why can't Explorer decide what size a file is?

Raymond Chen

If you open Explorer and highlight a file whose size is a few kilobytes, you can find some file sizes where the Explorer Size column shows a size different from the value shown in the Details pane. What's the deal? Why can't Explorer decide what size a file is? The two displays use different algorithms. The values in the Size column are always given in kilobytes, regardless of the actual file size. File is 15 bytes? Show it in kilobytes. File is 2 gigabytes? Show it in kilobytes. The value shown in the Size column is rounded up to the nearest kilobyte. Your 15-byte file shows up as 1KB. This has been the behav...

Mar 14, 2011
Post comments count 0
Post likes count 1

The old DEBUG program can load COM files bigger than 64KB, but that doesn't mean they actually load as a program

Raymond Chen

Some times ago, I described why a corrupted binary sometimes results in the error "Program too big to fit in memory". Commenter Neil was under the impression that nonrelocatable programs files could be larger than 64KB and used the DEBUG command to verify this assertion. While it's true that DEBUG can load files bigger than 64KB, that doesn't mean that they will load as a program. If DEBUG decide that you didn't give it a program (the file extension is not EXE or COM),¹ then it treats the file on the command line as a data file and loads it into memory in its entirety, provided it fits in memory in its en...