The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
A handful of trips through the time machine
A few trips through the time machine: In the Internet Explorer time machine video, I was struck by the remark, "Appearance-wise, very little had changed [in Internet Explorer 4] since IE3. Not much changed in terms of functionality, either." In fact, Internet Explorer 4 was probably the most significant revision of Internet Explorer in its history, because that's the version that completely replaced the old layout engine with a new one code-named Trident, the layout engine that continues to power Internet Explorer today. Another case of "When you change the insides, nobody notices."
The list of heaps returned by GetProcessHeaps is valid when it returns, but who knows what happens later
A customer had a problem involving heap corruption. In our code, we call and then for each heap, we call to enable the low fragmentation heap. However, the application crashes due to an invalid heap handle. My question is, why do we need to allocate an array of size 1025 even though we pass 1024 to ? Ha, faked you out with that question, eh? (It sure faked me out.) It's not clear why the code under-reports the buffer size to . So let's ignore the customer's stated question and move on to the more obvious question: Why does this code crash due to an invalid heap handle? Well, for one thing, the cod...
2011 mid-year link clearance
Another round of the semi-annual link clearance. And, as always, the obligatory plug for my column in TechNet Magazine:
The UseUrl attribute in the App Paths key indicates that your application can accept a URL on the command line
Setting the attribute in your key indicates that your application can accept a URL on the command line as the document to be opened. The documentation for this attribute is a confusing blend of raw documentation, guidance, history, and an example. Let's tease the parts apart so you won't confuse the example with the contract. The raw documentation is simple: Setting indicates that your application can accept URLs on the command line. The guidance is that programs like Web browsers should set this attribute because opening URLs is the primary reason for their existence. But it's not just Web browsers; any pr...
What happens to WPARAM, LPARAM, and LRESULT when they travel between 32-bit and 64-bit windows?
The integral types , , and are 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems. What happens when a 32-bit process sends a message to a 64-bit window or vice versa? There's really only one choice when converting a 64-bit value to a 32-bit value: Truncation. When a 64-bit process sends a message to a 32-bit window, the 64-bit and values are truncated to 32 bits. Similarly, when a 64-bit window returns an back to a 32-bit sender, the value is truncated. But converting a 32-bit value to a 64-bit value introduces a choice: Do you zero-extend or sign-extend? The answer is obvious if you re...
A different way to win from one of those claw game
I know two people (siblings) who are experts at those claw games. They can look at a claw game, assess the situation, decide whether there is a winnable toy, and if so, drop in their quarter and grab it. I asked the elder sibling how they arrived at this amazing skill. "As a teenager, I spent something like $20 pumping quarters into one of these machines, and I eventually figured it out." Or there is the direct approach.
How do I display the Find Printers dialog programmatically?
A customer wanted to display the Find Printers dialog programmatically to let the user pick a printer from Active Directory and wanted to know whether this was possible. Yes, it's possible, and there's more than one way to do it. There's the lazy way and the overachieving way. The overachieving way is to use the method. The sample function spells it all out for you. The lazy way takes a little bit of out-of-the-box thinking: Open the Find Printers dialog, set up the search the way you want it, and then save the search to a file (File, Save Search). In your program, when you need to open the Find Printers di...
There's more to workflow than hitting F5 in the IDE
Commenter Stu suggested that instead of having code to auto-correct dialog templates, why not have a program that corrects them at build time? That way, Windows wouldn't have to make all these accommodations for programs that didn't understand the new dialog template requirements for property sheet pages. For one thing, this model assumes that all dialog templates come from Win32 PE resources and aren't generated at runtime or loaded from other files not in resource format. For those cases, you still need the runtime fixup, so this solution would be a supplement to the existing one rather than a replacement. ...
Why doesn't my MessageBox wrap at the right location?
A customer reported that the function was wrapping text "at the wrong location." Our program displays a message with the function, and we use the '\n' character to force line breaks at positions we choose. But we've found that starting in Windows Vista, the line breaks we placed are not working. The function is inserting its own line breaks, which interferes with our custom text layout. It used to be that the width of the message box would expand to fit the longest line in the message. The function is one of those "leave the driving to us" type of functions. You give it a string to display, select whi...