Showing tag results for Code

May 6, 2008
Post comments count0
Post likes count0

Psychic debugging: Why does ExitProcess(1) produce an exit code of zero?

Raymond Chen
Raymond Chen

Here's a question that came from a customer. By now, you should already have the necessary psychic powers to answer it. Our program calls to indicate that it exited unsuccessfully. The process that launched our program waits for the program to exit and then calls to retrieve the exit code. The function succeeds, but the exit code is zero! How c...

Code
May 5, 2008
Post comments count0
Post likes count0

If you pass invalid parameters, then all bets are off

Raymond Chen
Raymond Chen

Alun Williams pointed out that if you pass invalid parameters to , it does not destroy the . Well, yeah, because if you pass invalid parameters, then all bets are off. Different functions perform different degrees of parameter validation; the degree to which this is done is typically guided by security concerns. Information that crosses securi...

Code
May 1, 2008
Post comments count0
Post likes count0

Strange uses for window class atoms

Raymond Chen
Raymond Chen

When you register a window class (with the or function), you get an back. What use is this atom? Not much. You can use this atom in many places where a window class name can be used; just convert it to a string with the macro. Let's change our scratch program to illustrate: We save the atom returned by the function and use it (in the...

Code
Apr 30, 2008
Post comments count0
Post likes count0

Some other places atoms (and the magical 0xC000) arise

Raymond Chen
Raymond Chen

The moment the Windows developers got a system for converting strings into numbers, they could use it anywhere they need to, well, convert a string into a number. Somtimes these integers are officially declared as atoms, but most of the time they are just integers that happen to be atoms under the covers. I'll start with registered window messages...

Code
Apr 21, 2008
Post comments count0
Post likes count0

Windows doesn't close windows when a user logs off; that's your call

Raymond Chen
Raymond Chen

Commenter Peter Kankowski asks why Windows doesn't send and messages when the user logs off. That's what is for. To tell the program that the Windows session is ending, and that you should get done whatever last things you want to get done before the world comes to an end. Windows doesn't send the message because sending becomes complicated...

Code
Apr 9, 2008
Post comments count0
Post likes count0

Use the #error directive to check whether the compiler even sees you

Raymond Chen
Raymond Chen

You may find yourself in a twisty maze of s. Or you may be wondering why your macros aren't working. I have these lines in my header file: but when I try to use them, I get errors. Any idea why this is happening? First, make sure the compiler even sees you. Notice that for macros, generating a preprocessed file doesn't accomplish anyth...

Code
Mar 31, 2008
Post comments count0
Post likes count0

You can drag multiple virtual objects, you know

Raymond Chen
Raymond Chen

A customer wanted to know how they could find out the directory that the user dropped a file onto. As we already noted, users can drop files onto things other than directories, so the question itself comes with incorrect hidden assumptions. This is another one of those cases where you have to ask the customer, "What are you really trying to do?" ...

CodeWhat a drag