Showing results for Code - The Old New Thing

Nov 7, 2005
Post comments count0
Post likes count0

Take it easy on the automatic retries

Raymond Chen
Raymond Chen

When I saw a discussion of how to simulate retry via try/catch, using as inspiration a Ruby function that retried a network operation three times before finally giving up, I felt the need to caution against automatic retry. Your natural inclination when faced with a failure that has a good chance of being caused by a transient condition is to re...

Code
Nov 4, 2005
Post comments count0
Post likes count0

Why is there a special PostQuitMessage function?

Raymond Chen
Raymond Chen

Why is there a special PostQuitMessage function? Because it's not really a posted message. Commenter A. Skrobov asked, "What's the difference between and ?" They are not equivalent, though they may look that way at first glance. The differences are subtle but significant. Like the , , and messages, the message is not a "real" posted mess...

Code
Nov 1, 2005
Post comments count0
Post likes count0

The COM interface contract rules exist for a reason

Raymond Chen
Raymond Chen

Some people believe that the COM rules on interfaces are needlessly strict. But the rules are there for a reason. Suppose you ship some interface in version N of your product. It's an internal interface, not documented to outsiders. Therefore, you are free to change it any time you want without having to worry about breaking compatibility w...

Code
Oct 28, 2005
Post comments count0
Post likes count0

How to recognize different types of sentinel timestamps from quite a long way away

Raymond Chen
Raymond Chen

Some time ago, I discussed several timestamp formats you might run into. Today we'll take a logical step from that information and develop a list of special values you might encounter. Note that if you apply time zone adjustments, the actual timestamp may shift by up to a day. All of these special values have one thing in common: If you see them...

CodeTime
Oct 20, 2005
Post comments count0
Post likes count0

Quick and dirty buzzword bingo cards in Excel

Raymond Chen
Raymond Chen

Jensen Harris's brief example of using Excel's random number generator reminded me that I had need for the random number generator recently myself: Generating buzzword bingo cards. At the Battlestar Galactica party, our hosts needed to create some Battlestar Galactica-themed buzzword bingo cards and asked me to help out. Here's how I did it: ...

Code
Oct 14, 2005
Post comments count0
Post likes count0

Thread affinity of user interface objects, part 5: Object clean-up

Raymond Chen
Raymond Chen

The window manager and GDI objects as a general rule will automatically destroy objects created by a process when that process terminates. (The window manager also destroys windows when their owner threads exit.) Note, however, that this is a safety net and not an excuse for you to leak resources in your own program with the attitude of "Oh, it do...

Code
Oct 13, 2005
Post comments count0
Post likes count0

Thread affinity of user interface objects, part 4: GDI objects and other notes on affinity

Raymond Chen
Raymond Chen

GDI objects are much simpler. As a general rule, they all have process affinity: They can be used by any thread in the process that created them. If you use a GDI object from multiple threads, it is your responsibility to coordinate the object's use. Note that the window manager and GDI as a general rule keep their respective objects thread-safe....

Code
Oct 12, 2005
Post comments count0
Post likes count0

Thread affinity of user interface objects, part 3: Menus, icons, cursors, and accelerator tables

Raymond Chen
Raymond Chen

The remaining user interface objects in common use are menus, icons, cursors, and accelerator tables. Menus do not have thread affinity. Any thread can use a menu. However, if two threads use a menu, it is the responsibility of those threads to coordinate among themselves how that menu will be used, so that one thread doesn't modify a menu while ...

Code
Oct 11, 2005
Post comments count0
Post likes count0

Thread affinity of user interface objects, part 2: Device contexts

Raymond Chen
Raymond Chen

Last time, we discussed briefly the thread affinity rules that govern window handles. Device contexts (DCs) also have a certain degree of thread affinity. The thread that calls functions such as must also be the one that calls , but as with window handles, during the lifetime of the DC, any thread can use it. If you choose to use a DC in a mul...

Code
Oct 10, 2005
Post comments count0
Post likes count0

Thread affinity of user interface objects, part 1: Window handles

Raymond Chen
Raymond Chen

Different objects have different thread affinity rules, but the underlying principles come from 16-bit Windows. The most important user interface element is of course the window. Window objects have thread affinity. The thread that creates a window is the one with which the window has an inseparable relationship. Informally, one says that the th...

Code