Showing tag results for Code

Feb 27, 2006
Post comments count0
Post likes count0

Changing a window class affects all windows which belong to that class

Raymond Chen
Raymond Chen

Sometimes you need to state the obvious, and that's fine. You can learn a lot from the obvious. For example, the first topic in my PDC talk consisted of simply stating the obvious. Occasionally, when you state the obvious, you have to follow up by stating the obvious. When I pointed out that the effect of lasts only until the next , one comment...

Code
Feb 23, 2006
Post comments count0
Post likes count1

Enumerating threads in a process

Raymond Chen
Raymond Chen

The tool helper library is sort of the black sheep of Win32. It grew out of the 16-bit TOOLHELP library, which provided services for system debugging tools to do things like take stack traces and enumerate all the memory in the system. The original incarnation of Win32 didn't incorporate it; it wasn't until Windows 95 that a 32-bit version o...

Code
Feb 22, 2006
Post comments count0
Post likes count1

The performance cost of reading a registry key

Raymond Chen
Raymond Chen

The registry is a convenient place to record persistent cross-process data in a uniform and multi-thread-safe manner. It roams with the user if you store it in , and individual keys can be secured (even on systems that use FAT, which doesn't otherwise support security). But that doesn't mean that it's free. The cost of opening a key, reading a v...

Code
Feb 21, 2006
Post comments count0
Post likes count0

In pursuit of the message queue

Raymond Chen
Raymond Chen

In 16-bit Windows, every thread (or "task" as it was called then) had a message queue, end of story. In the transition to 32-bit Windows, this model broke down because Win32 introduced the concepts of "worker threads" and "console applications", neither of which had much need for messaging. Creating a queue for every thread in the system would have...

Code
Feb 20, 2006
Post comments count0
Post likes count1

Why does my program run faster if I click and hold the caption bar?

Raymond Chen
Raymond Chen

Sometimes, people discover that a long-running task runs faster if you hold down the mouse. How can that be? This strange state of affairs typically results when a program is spending too much time updating its progress status and not enough time actually doing work. (In other words, the programmer messed up badly.) When you click and hold the m...

Code
Feb 16, 2006
Post comments count0
Post likes count0

Because programmers were trusted to do the right thing, part 2

Raymond Chen
Raymond Chen

Some time ago, I discussed briefly the philosophy of API design that prevailed in the early days. One of the places this manifested itself was in the area of power management. As originally designed, power management was a cooperative affair (as was nearly everything in Windows in the early days). When the user attempted to put the computer into a...

Code
Feb 10, 2006
Post comments count0
Post likes count1

The dangers of sleeping on a UI thread

Raymond Chen
Raymond Chen

If you have a thread that owns a window, you should not be using the function, because that causes your thread to stop responding to messages for the duration of the sleep. This is true even for sleeps of short duration, such as sleeping for a few seconds and waking up in order to poll the state of something in the system. As we noted earlier, p...

Code
Feb 7, 2006
Post comments count0
Post likes count0

Viewing function composition as transformation of the domain

Raymond Chen
Raymond Chen

A lot of formulas you encounter in computer science can be viewed as function composition. Let's start with the simple problem of rounding integers down to the nearest multiple of some positive constant. The formula for this should be relatively easy for you to produce: round_down(n, m) = floor_div(n, m) * m where returns the largest integer ...

Code
Feb 6, 2006
Post comments count0
Post likes count0

Beware of redirected folders, too

Raymond Chen
Raymond Chen

Earlier, we learned about roaming user profiles, wherein the master copy of the user's profile is kept on a central server (which for the purpose of discussion I will call the "profile server") and is copied around to follow the user as she logs onto computers throughout an organization. In the comments, many people said that what they really want...

Code
Feb 3, 2006
Post comments count0
Post likes count0

You can't even trust the identity of the calling executable

Raymond Chen
Raymond Chen

A while back, I demonstrated that you can't trust the return address. What's more, you can't even trust the identity of the calling executable. I've seen requests from people who say, "I want to check whether I'm being called from MYAPP.EXE. I'm going to make a security decision based on the result." Although you can do this, all it does is give ...

Code