The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
How do I control the order of the pages in property sheets from my shell extension?
A customer wanted to know whether a shell extension can control the order of the property sheet pages in a property sheet. The interface lets you add pages and replace pages, but nothing about rearranging them. Naturally a shell extension can control the relative order of its own pages (by changing in the order in which it calls ) but how can it affect the order of pages from other shell extensions? Imagine if that were possible. Every shell extension would set itself to be first! The customer was kind enough to explain what they were doing. "We were more concerned about consistency, because our tab appears ...
What's the point of letting you change the GCL_CBCLSEXTRA if it has no effect?
The documentation for the function mentions GCL_CBCLSEXTRA: Sets the size, in bytes, of the extra memory associated with the class. Setting this value does not change the number of extra bytes already allocated. What's the point of letting the application change a value if it has no effect? The class long grants access to the value that was originally passed in the structure when you called , or the Ex-versions mutatus mutandis. The intent is for it to be used with so you can read the value back, in case you forgot, or if you are inspecting somebody else's class (for example, because you wa...
Generally speaking, yanking the power plug unexpectedly should not be part of your business process
A customer had a complex process for setting up their computers, and the process recorded information in the registry so that applications could record their state across reboots. They then noticed that if they yanked the power cord instead of going through the normal Shutdown process, that the registry keys were not reliably updated. They were wondering if there was a function they can call to force the registry to be flushed to disk even if the system doesn't go through a normal shutdown. Patient: "Doctor, it hurts when I do this." Doctor: "Don't do that." You could call the function each time you update th...
Please don't wade across the Strait of Juan de Fuca
I dreamed that I was visiting a scenic location near the Canadian border. A central large body of water had the mainland to the south and east. A river ran southeast, spanned by a footbridge. To the northwest was another land mass, which had gained the nickname "Alaska" even though we were nowhere near Alaska. There was a gift shop on "Alaska", and from there you could either travel further northwest to hike the snowy terrain, or you could take a shuttle train east over the water to the mainland. I had finished a hike on pretend-Alaska and was planning my return. The ringleader of my group was a friend of mine k...
How do I convert a synchronous file handle into an asynchronous one?
Say you opened a file in synchronous mode, and then you realize that you want to issue asynchronous I/O on it, too. One way to do this is to call a second time with the , but this requires you to know the file name, and the file name may not be readily available to the function that wants to do the conversion, or it may not even be valid any longer if the file has been renamed in the meantime. Enter . This basically lets you do a based on another handle rather than a file name. It differs from because it actually goes and opens the file again (as opposed to merely creating another reference to the same file...
Each time I move, my mailbox moves further away
When I was growing up, the mailman letter carrier came right to our front door. The mailbox was mounted on the front of the house right next to the front door. You could check the mail without even getting dressed; just open the door a crack and stick out your hand. Approximate distance from front door to mailbox: less than 1 foot. In the next house I lived in, the mailbox was no longer mounted on the house. Instead, it stood at the end of the driveway. Approximate distance from front door to mailbox: 55 feet. My next house was in a neighborhood which grouped its mailboxes in clusters. The cluster of ...
Why does the CLR report a NullReferenceException even if the referenced access is not exactly the null pointer?
We saw some time ago that before invoking a method on an object, the CLR will generate a instruction to force a null reference exception to be raised if you are trying to invoke a method on a null reference. But why does the CLR raise a if the faulting address is almost but not quite zero? When run, this program raises a rather than an . On the other hand, if you change the address to , then you get the expected . With a little bit of preparation, the CLR optimizes out null pointer checks if it knows that it's going to access the object anyway. For example, if you write then the CLR doesn't need to...
On partially-constructed objects, additional remarks, not as interesting
Don't worry. Our long national nightmare of CLR week is almost over. I had originally planned to write an article about partially-constructed objects, but in the time since I queued up the topic (back in November 2005) to the time I got around to writing it up, I found that Joe Duffy had already written it for me! On partially-constructed objects Read it. Okay, here are some follow-up remarks. One place where people get caught out by partially-constructed objects is when they try to maintain a cache of objects (perhaps with a little bit of action) and stash the objects into the cache before they a...
The mathematical card game Krypto and reaching a level of proficiency where the rules break down
Solving it faster than the rules considered possible.