Showing tag results for 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
Feb 2, 2006
Post comments count0
Post likes count0

Be careful when interpreting security descriptors across machine boundaries

Raymond Chen
Raymond Chen

While it's true the function can be used to check whether a particular security descriptor grants access to a token, you need to be aware of where that security descriptor came from. If the security descriptor came from another machine (for example, if you got it by calling and passing the path to a file on a network share), calling the function...

Code
Feb 1, 2006
Post comments count0
Post likes count0

The per-class window styles and things really are per-class

Raymond Chen
Raymond Chen

Earlier, I discussed which window style bits belong to whom. One detail of this that I neglected to emphasize is that since the lower 16 bits of the window style are defined by the class, you can't just take styles from one class and apply them to another. For example, you can't create a button control and pass the style expecting to have the te...

Code
Jan 27, 2006
Post comments count0
Post likes count0

Waiting for all handles with MsgWaitForMultipleObjects is a bug waiting to happen

Raymond Chen
Raymond Chen

The and functions allow you to specify whether you want to want for any or all of the handles (either by passing or by passing , accordingly). But you never want to wait for all handles. Waiting for all handles means that the call does not return unless all the handles are signalled and a window message meeting your wake criteria has arrived. S...

Code
Jan 26, 2006
Post comments count0
Post likes count1

Pumping messages while waiting for a period of time

Raymond Chen
Raymond Chen

We can use the function (or its superset ) to carry out a non-polling "sleep while processing messages". This function pumps messages for up to milliseconds. The kernel of the idea is merely to use the function as a surrogate for , pumping messages until the cumulative timeout has been reached. There are a lot of small details to pay heed to...

Code
Jan 25, 2006
Post comments count0
Post likes count0

You can call MsgWaitForMultipleObjects with zero handles

Raymond Chen
Raymond Chen

There is no function, but you can create your own with the assistance of the function. To wait for a message with timeout, we use the in a vacuous sense: You pass it a list of objects you want to wait for, as well as a timeout and a set of queue states, asking that the function return when any of the objects is signalled or when a message is...

Code
Jan 24, 2006
Post comments count0
Post likes count0

Performance consequences of polling

Raymond Chen
Raymond Chen

Polling kills. A program should not poll as a matter of course. Doing so can have serious consequences on system performance. It's like checking your watch every minute to see if it's 3 o'clock yet instead of just setting an alarm. First of all, polling means that a small amount of CPU time gets eaten up at each poll even though there is nothing ...

Code
Jan 23, 2006
Post comments count0
Post likes count0

If your callback fails, it's your responsibility to set the error code

Raymond Chen
Raymond Chen

There are many cases where a callback function is allowed to halt an operation. For example, you might decide to return to the message to prevent the window from being created, or you might decide to return to one of the many enumeration callback functions such as the callback. When you do this, the enclosing operation will return failure bac...

Code