The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Some suggestions on improving the assembly instructions for your children's play furniture
Dec 24, 2010
Post comments count 0
Post likes count 0

Some suggestions on improving the assembly instructions for your children's play furniture

Raymond Chen
Raymond Chen

Some suggestions for those companies which produce children's play furniture:

That mysterious 01
Dec 24, 2010
Post comments count 0
Post likes count 0

That mysterious 01

Raymond Chen
Raymond Chen

Some time ago, we learned the story of that mysterious J. There is another mystery character that sometimes shows up in place of a smiley face: the \001. The character starts out as the Unicode U+263A, which looks like this: ☺. In code page 437, this character lives at position 1, and depending on what program is being used to display the character, it might appear as a box (representing the character U+0001) or as the escape sequence \001. You can think of this as a version of the mysterious J, but taking a route through code page 437, or you can think of it as how a bullet turns i...

What is the correct way of temporarily changing a thread's preferred UI language?
Dec 23, 2010
Post comments count 0
Post likes count 0

What is the correct way of temporarily changing a thread's preferred UI language?

Raymond Chen
Raymond Chen

A customer ran into a crashing bug in their shell extension. The shell extension wants to change the thread's preferred UI language temporarily, so that it can load its resources from a specific language. You'd think this would be easy: Approximately ten seconds after this code runs, Explorer crashes with the exception whose description is "A threadpool worker thread enter a callback, which left with preferred languages set. This is unexpected, indicating that the callback missed clearing them." (Just before Explorer crashes, the message "ThreadPool: callback 77180274(05B67430) returned with preferred langua...

The __fortran calling convention isn't the calling convention used by FORTRAN
Dec 22, 2010
Post comments count 0
Post likes count 1

The __fortran calling convention isn't the calling convention used by FORTRAN

Raymond Chen
Raymond Chen

Although the Microsoft C compiler supports a calling convention called , that's just what the calling convention is called; its relationship with the FORTRAN programming language is only coincidental. The keyword is now just an old-fashioned synonym for . Various FORTRAN compilers use different calling conventions; the one I describe here applies to the now-defunct Microsoft Fortran PowerStation. Fortran Powerstation pushes parameters on the stack right-to-left, with callee-cleanup. (So far, this matches aka .) Function names are converted to all-uppercase, with an underscore at the beginning and appende...

How do I simulate input without SendInput?
Dec 21, 2010
Post comments count 0
Post likes count 0

How do I simulate input without SendInput?

Raymond Chen
Raymond Chen

Michal Zygmunt wants to create a system where multiple applications can have focus, with different users generating input and directing them at their target applications. Attempting to simulate this by posting input messages didn't work. "Can you tell us maybe how SendInput is internally implemented so that we can use it to simulate only part of the actions (like without acquiring focus)?" operates at the bottom level of the input stack. It is just a backdoor into the same input mechanism that the keyboard and mouse drivers use to tell the window manager that the user has generated input. The function doesn...

Developing the method for taking advantage of the fact that the OVERLAPPED associated with asynchronous I/O is passed by address
Dec 20, 2010
Post comments count 0
Post likes count 0

Developing the method for taking advantage of the fact that the OVERLAPPED associated with asynchronous I/O is passed by address

Raymond Chen
Raymond Chen

You can take advantage of the fact that the associated with asynchronous I/O is passed by address, but there was some confusion about how this technique could "work" when kernel mode has no idea that you are playing this trick. Whether kernel mode is in on the trick is immaterial since it is not part of the trick. Let's start with a version of the code which does not take advantage of the structure address in the way described in the article. This is a technique I found in a book on advanced Windows programming: This version of the code uses the address of the structure to determine the location in th...

What happened to the return code from WinMain in 16-bit Windows?
Dec 20, 2010
Post comments count 0
Post likes count 0

What happened to the return code from WinMain in 16-bit Windows?

Raymond Chen
Raymond Chen

Commenter S asks, "What happened to the return code from WinMain in a Windows 3.1 app?" After all, there was no function in 16-bit Windows. Basically, the exit code vanished into the ether. Unless you captured it. The Toolhelp library provided a low-level hook into various parts of the kernel, allowing you to monitor, among other things, the creation and destruction of tasks. That was how you captured the return code of a Windows program in 16-bit Windows. But if you didn't catch it as it happened, it was gone forever, lost in the ether.

The OVERLAPPED associated with asynchronous I/O is passed by address, and you can take advantage of that
Dec 17, 2010
Post comments count 0
Post likes count 1

The OVERLAPPED associated with asynchronous I/O is passed by address, and you can take advantage of that

Raymond Chen
Raymond Chen

When you issue asynchronous I/O, the completion function or the I/O completion port receives, among other things, a pointer to the structure that the I/O was originally issued against. And that is your key to golden riches. If you need to associate information with the I/O operation, there's no obvious place to put it, so some people end up doing things like maintaining a master table which records all outstanding overlapped I/O as well as the additional information associated with that I/O. When each I/O completes, they look up the I/O in the master table to locate that additional information. But it's eas...

Why does SHCOLUMNINFO have unusually tight packing?
Dec 16, 2010
Post comments count 0
Post likes count 0

Why does SHCOLUMNINFO have unusually tight packing?

Raymond Chen
Raymond Chen

Alternate title: News flash: Sometimes things happen by mistake rbirkby asks why the structure has 1-byte packing. "Was the expectation that there would be so many columns in a details view that the saving would be worthwhile?" Hardly anything that clever or ingenious. It's just the consequence of a mistake. When the structure was added to the header file in the Windows 2000 timeframe, it was added with no specific packing directive. But it turns out that there was a specific packing directive; it just wasn't obvious. Near the top of the header file was the following: (There was of course a mat...