Showing tag results for Code

Mar 4, 2011
Post comments count0
Post likes count0

The window manager needs a message pump in order to call you back unexpectedly

Raymond Chen
Raymond Chen

There are a bunch of different ways of asking the window manager to call you when something interesting happens. Some of them are are in response to things that you explicitly asked for right now. The enumeration functions are classic examples of this. If you call and pass a callback function, then that callback is called directly from the enumera...

Code
Mar 3, 2011
Post comments count0
Post likes count0

If you're waiting for I/O to complete, it helps if you actually have an I/O to begin with

Raymond Chen
Raymond Chen

We saw earlier the importance of waiting for I/O to complete before freeing the data structures associated with that I/O. On the other hand, before you start waiting, you have to make sure that you have something to wait for. A customer reported a hang in waiting for an I/O to cancel, and the I/O team was brought in to investigate. They looked...

Code
Mar 2, 2011
Post comments count0
Post likes count0

Although the x64 calling convention reserves spill space for parameters, you don't have to use them as such

Raymond Chen
Raymond Chen

Although the x64 calling convention reserves space on the stack as spill locations for the first four parameters (passed in registers), there is no requirement that the spill locations actually be used for spilling. They're just 32 bytes of memory available for scratch use by the function being called. We have a test program that works okay wh...

Code
Feb 25, 2011
Post comments count0
Post likes count0

Why does WaitForMultipleObjects return ERROR_INVALID_PARAMETER when all the parameters look valid to me?

Raymond Chen
Raymond Chen

A customer asked for assistance with the function: I am getting when calling even though all the parameters are valid as far as I can tell. I've narrowed it down to this simple program. First of all, thank you for narrowing the issue down to a minimal program that illustrates the problem. You'd be surprised how often a customer says, "I'...

Code
Feb 24, 2011
Post comments count0
Post likes count0

Shortcuts are serializable objects, which means that they can be stored in places other than just a file

Raymond Chen
Raymond Chen

It's true that the vast majority of the time, people consider the shell shortcut object as synonymous with the file it is normally saved into, shortcuts need not spend their time in a file. You can put a shortcut anywhere you can save a hunk of bytes. Here's a program that creates a shortcut to the file name passed on the command line (make sure ...

Code
Feb 21, 2011
Post comments count0
Post likes count0

If an operation results in messages being sent, then naturally the target window must be processing messages for the operation to complete

Raymond Chen
Raymond Chen

If an operation includes as part of its processing sending messages, then naturally the target window for those messages must be processing messages (or more precisely, the thread which owns the target window must be processing messages) in order for the operation to complete. Why? Because processing messages is the only way a window can receive me...

Code
Feb 18, 2011
Post comments count0
Post likes count0

WM_NCHITTEST is for hit-testing, and hit-testing can happen for reasons other than the mouse being over your window

Raymond Chen
Raymond Chen

The message is sent to your window in order determine what part of the window corresponds to a particular point. The most common reason for this is that the mouse is over your window. Although triggers most often for mouse activity, that is not the only reason why somebody might want to ask, "What part of the window does this point correspond...

Code
Feb 17, 2011
Post comments count0
Post likes count0

What is the highest numerical resource ID permitted by Win32?

Raymond Chen
Raymond Chen

A customer asked the following question: What is the maximum legal value of a resource identifier? Functions like take a as the resource ID, which suggests a full 32-bit range, but in practice, most resource IDs appear to be in the 16-bit range. Is there any particular history/precedent for avoiding large numbers as resource IDs? (I have a progr...

Code
Feb 15, 2011
Post comments count0
Post likes count0

Window message parameters do not come with metaphysical certitude

Raymond Chen
Raymond Chen

The MSDN documentation for window messages describes what each of the parameters means, but just because it means something doesn't mean that it is that something; it merely means it. But you knew this already. If you have a window handle, you can send it whatever message you like, with whatever parameters you like, even if those parameters contra...

Code
Feb 11, 2011
Post comments count0
Post likes count0

How do specify that a shortcut should not be promoted as newly-installed on the Start menu?

Raymond Chen
Raymond Chen

Windows XP employed a number of heuristics to determine which Start menu shortcuts should be promoted when an application is newly-installed. But what if those heuristics end up guessing wrong? You can set the property to to tell the Start menu, "I am not the primary entry point for the program; I'm a secondary shortcut, like a help file." ...

Code