The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
The tiny table sorter – or – you can write LINQ in JavaScript
I had a little side project that displayed status information in a table, and I figured, hey, let me add sorting. And it was a lot easier than I thought. I just put the header row in the and the table contents in the , then I could use this code to sort the table: Each cell can have an optional custom attribute which specifies how the item should sort. If there is no , then I just use the cell's . (My table was constructed at runtime from an , so adding the to the date fields was not difficult.) One handy thing about the functions in the prototype is that as a rule, they do not actually require that the...
If I signal an auto-reset event and there is a thread waiting on it, is it guaranteed that the event will be reset and the waiting thread released before SetEvent returns?
Let's go straight to the question: I have two programs that take turns doing something. Right now, I manage the hand-off with two auto-reset events. In Thread A, after it finishes doing some work, it signals Event B and then immediately waits on Event A. Thread B does the converse: When its wait on Event B completes, it does some work, then signals Event A and then immediately waits on Event B. This works great, but I'm wondering if I can save myself an event and use the same event to hand control back and forth. Is it guaranteed that when Thread A signals Event ...
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...