The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Jan 13, 2014
Post comments count 0
Post likes count 1

Creating a listview with checkboxes on some items but not others

Raymond Chen

Today's Little Program creates a listview with checkboxes on some items but not other. The extended style is really just a convenience style. Everything it does you could have done yourself, with a bit more typing. It creates a state image list consisting of an unchecked box (state 1) and a checked box (state 2). You could have done this yourself with followed by a few calls to . When you hit the space bar or click on the check box, the state image toggles between 1 and 2. You could have done this yourself by responding to (for the space bar), and the mouse notific...

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

How do I manually recalculate ACLs on a file based on the containing directory?

Raymond Chen

A customer wanted to move a file and have it forget all its old ACLs and instead inherit its ACLs from its new location. They found an old article of mine that said If you use to move a file and pass the flag, then it will not preserve the original ACLs on the moved files but will rather recalculate them from the destination's inheritable properties. (If you want to do the same thing in your own code, you can call the function, specifying that you want an empty, unprotected DACL.) They were having trouble implementing the recommendation in parentheses. We set the file to have an SDDL of in order to give ...

Jan 9, 2014
Post comments count 0
Post likes count 3

Can you dllexport/dllimport an inline function?

Raymond Chen

Yes, but it won't actually do much.

Jan 8, 2014
Post comments count 0
Post likes count 1

The case of the missing context menu verbs

Raymond Chen

A customer reported that when they right-clicked a batch file, a bunch of commands were missing. For example, Open was gone! Okay, there really isn't much of a story here, because some direct debugging quickly identified the culprit. The customer had installed a third party shell extension which returned a huge value from its method. Explorer told the shell extension, "Hey, like I've got room for 30,000 menu items. How many do you need?" The shell extension replied, "I'll take 29,995 of them." And so the shell extension sucked up nearly all the menu IDs, and by the time the Open command handler came along, ...

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

The case of the mysterious Alternate Data Stream query

Raymond Chen

A customer was running Windows Server 2003 ("Still in support until 2015!") and they have some custom application that monitors all disk accesses. They noticed that there were a lot of failed Alternate Data Stream queries coming from Explorer, and that was causing the custom application's logs to fill with largely useless information. These Alternate Data Stream queries are being made in order to extract file metadata for the pop-up infotip. (Windows later abandoned the use of Alternate Data Streams for file metadata since Alternate Data Streams were so fragile and were easily damaged or lost.) The customer fou...

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

Excuses college students use for missing assignments

Raymond Chen

My father recently retired after over 40 years as a college professor. During that time, he has seen all sorts of lame excuses students offer for missing homework assignments. Eventually, he got tired of dealing with them, so he instituted the following homework policy: There are nine homework assignments in this class, broken into three groups of three. I will take the best score from each group and drop the other two. Therefore, you can turn in as few as three homework assignments and still get full credit for homework. Late homework will be graded so you can learn from your mistakes, but the score will not c...

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

How do I obtain the computer manufacturer's name via C++?

Raymond Chen

The way to get the computer manufacturer and other information is to ask WMI. WMI is much easier to use via scripting, but maybe you want to do it from C++. Fortunately, MSDN takes you through it step by step and even puts it together into a sample program. But I'm going to write the code myself anyway. Today's Little Program extracts the computer name, manufacturer, and model from WMI. Remember that Little Programs do little or no error checking. And the smart pointer library we'll use is (rolls dice) ! Those include files and macros set things up so we can use to access WBEM interfaces. The fir...

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

What happened in real-mode Windows when somebody did a longjmp into a discardable segment?

Raymond Chen

During the discussion of how real-mode Windows handled return addresses into discarded segments, Gabe wondered, "What happens when somebody does a into a discardable segment?" I'm going to assume that everybody knows how traditionally works so I can go straight to the analysis. The reason is tricky is that it has to jump to a return address that isn't on the stack. (The return address was captured in the .) If that segment got relocated or discarded, then the jump target is no longer valid. It would have gotten patched to a return thunk if it were on the stack, but since it's in a , the stack walker didn'...

Jan 2, 2014
Post comments count 0
Post likes count 1

If the cursor clip rectangle is a global resource, how come I can't change it with ClipCursor?

Raymond Chen

A customer reported that the function was not working. "The cursor clip rectangle is a shared global resource, so I should be able to change it any time I like. My app installs a global mouse hook and sets the clip cursor inside the hook function, but the change doesn't have any effect. Why can't I change the clip cursor inside a mouse hook?" Sure, you can change the clip cursor inside a mouse hook. But remember, a shared global resource cuts both ways. Since anybody can change it, your app can change it any time it likes. But since anybody can change it, another app can also change it any time they like. In t...