Showing results for Code - The Old New Thing

Sep 15, 2005
Post comments count0
Post likes count0

Fiddling with the fonts, part 1: Making the Chinese characters larger

Raymond Chen
Raymond Chen

Let's pay a quick visit to our continuing dictionary project. One of the things you may have noticed is that the Chinese characters are unreadably small. Let's fix that by making them larger. class RootWindow : public Window { public: virtual LPCTSTR ClassName() { return TEXT("Scratch"); } static RootWindow *Create(); RootWindow(); ~RootWind...

Code
Sep 12, 2005
Post comments count0
Post likes count0

Understanding the consequences of WAIT_ABANDONED

Raymond Chen
Raymond Chen

One of the important distinctions between mutexes and the other synchronization objects is that mutexes have owners. If the thread that owns a mutex exits without releasing the mutex, the mutex is automatically released on the thread's behalf. But if this happens, you're in big trouble. One thing many people gloss over is the WAIT_ABANDONED re...

Code
Sep 9, 2005
Post comments count0
Post likes count0

Reading the output of a command from batch

Raymond Chen
Raymond Chen

The FOR command has become the batch language's looping construct. If you ask for help via FOR /? you can see all the ways it has become overloaded. For example, you can read the output of a command by using the for command. FOR /F "tokens=*" %i IN ('ver') DO echo %i The /F switch in conjunction with the single quotation marks indicates that t...

Code
Sep 7, 2005
Post comments count0
Post likes count0

Why aren’t low-level hooks injected?

Raymond Chen
Raymond Chen

When I described what the HINSTANCE parameter to the function is for, I neglected to mention why the low-level hooks are not injected. But then again, it should be obvious. The low-level hooks let you see input as it arrives at the window manager. At this low level of processing, the window manager hasn't yet decided what window will receive...

Code
Sep 1, 2005
Post comments count0
Post likes count0

More undocumented behavior and the people who rely on it: Output buffers

Raymond Chen
Raymond Chen

For functions that return data, the contents of the output buffer if the function fails are typically left unspecified. If the function fails, callers should assume nothing about the contents. But that doesn't stop them from assuming it anyway. I was reminded of this topic after reading Michael Kaplan's story of one customer who wanted the ou...

Code
Aug 31, 2005
Post comments count0
Post likes count0

Understanding hash codes

Raymond Chen
Raymond Chen

On more than one occasion, I've seen someone ask a question like this: I have some procedure that generates strings dynamically, and I want a formula that takes a string and produces a small unique identifer for that string (a hash code), such that two identical strings have the same identifier, and that if two strings are different, then they wi...

Code
Aug 30, 2005
Post comments count0
Post likes count0

Program names in file type handlers need to be fully-qualified

Raymond Chen
Raymond Chen

Most people probably haven't noticed this, but there was a change to the requirements for file type handlers that arrived with Windows XP SP 2: Paths to programs now must be fully-qualified if they reside in a directory outside of the Windows directory and the System directory. The reason for this is security with a touch of predictabil...

Code
Aug 17, 2005
Post comments count0
Post likes count0

Why is processor affinity inherited by child processes?

Raymond Chen
Raymond Chen

Consider why a typical program launches child processes. (Shell programs like Explorer aren't typical.) It's because the task at hand is being broken down into sub-tasks which for whatever reason has been placed into a child process. An Example of this would be, say, a multi-pass compiler/linker, where each pass is implemented as a separate proces...

Code
Aug 15, 2005
Post comments count0
Post likes count0

The poor man’s way of identifying memory leaks

Raymond Chen
Raymond Chen

There is a variety of tools available for identifying resource leaks, but there's one method that requires no tools or special compiler switches or support libraries: Just let the leak continue until the source becomes blatantly obvious. Nightly automated stress testing is a regular part of any project. Some teams use screen savers as the trigger...

Code
Aug 12, 2005
Post comments count0
Post likes count0

Adding a lookup control to the dictionary: Searching Pinyin

Raymond Chen
Raymond Chen

Finally we start searching. For now, the search algorithm is going to be very simple: The string you type into the edit control will be treated as the start of a Pinyin word or phrase. We'll make it fancier later. Here is where a lot of the groundwork (some of which I called out explicitly and some of which I slipped in without calling attention...

Code