Showing tag results for Code

Feb 5, 2008
Post comments count0
Post likes count0

Who decides what can be done with an object or a control?

Raymond Chen
Raymond Chen

This is one of those things that is obvious to me, but perhaps is not obvious to everyone. An object establishes what can be done with it. Any rights granted by the object go to the creator. The creator can in turn grant rights to others. But if you're a third party to the object/creator relationship, you can't just step in and start messing around...

Code
Feb 4, 2008
Post comments count0
Post likes count0

DLL forwarding is not the same as delay-loading

Raymond Chen
Raymond Chen

As I noted earlier, when you create a forwarder entry in an export table, the corresponding target DLL is not loaded until somebody links to the forwarder entry. It looks like some people misread this statement to suggest some sort of delay-loading so I'm going to state it again with an example in mind in the hopes of clearing up any confusion (...

Code
Jan 16, 2008
Post comments count0
Post likes count0

Use WM_WINDOWPOSCHANGING to intercept window state changes

Raymond Chen
Raymond Chen

The message is sent early in the window state changing process, unlike , which tells you about what already happened. A crucial difference (aside from the timing) is that you can influence the state change by handling the message and modifying the structure. Here's an example that prevents the window from being resized. Before the message...

Code
Jan 15, 2008
Post comments count0
Post likes count0

Use WM_WINDOWPOSCHANGED to react to window state changes

Raymond Chen
Raymond Chen

The documentation for the message points out that the message is not sent under certain circumstances. But what if you want to know when the window is shown, including in the cases where you don't get ? The message is sent at the end of the window state change process. It sort of combines the other state change notifications, , , and . But it ...

Code
Jan 8, 2008
Post comments count0
Post likes count0

Generating initials from a name is trickier than you think

Raymond Chen
Raymond Chen

Even though I'm signed in, the page claims that anonymous comments are not allowed, so I'm reduced to posting my comment here and generating a trackback. Some time ago, Robert McLaws wrote a function that generates initials from a name. Let's set aside completely the issue of non-U.S. names; the function doesn't even handle U.S. names correctly. ...

Code
Jan 8, 2008
Post comments count0
Post likes count0

Taxes: Files larger than 4GB

Raymond Chen
Raymond Chen

Nowadays, a hard drive less than 20 gigabytes is laughably small, but it used to be that the capacity of a hard drive was measured in megabytes, not gigabytes. Today, video files and databases can run to multiple gigabytes in size, and your programs need be prepared for them. This means that you need to use 64-bit file offsets such as those used b...

Code
Jan 7, 2008
Post comments count0
Post likes count1

Clean-up functions can't fail because, well, how do you clean up from a failed clean-up?

Raymond Chen
Raymond Chen

Commenter Matt asks how you're supposed to handle failures in functions like or . Obviously, you can't. If a clean-up function fails, there's not much you can do because, well, how do you clean up from a failed clean-up? These clean-up functions fall into the category of "Must not fail for reasons beyond the program's control." If a program trie...

Code
Jan 4, 2008
Post comments count0
Post likes count0

What does it mean when a display change is temporary?

Raymond Chen
Raymond Chen

When you call the function, you can pass the flag to indicate that the change is temporary. But if you don't also save the changes in the registry, how can they be permanent? What does temporary mean? A temporary display change is one that your program has entered because it has gone into a fullscreen mode, a change which it will undo when it re...

Code
Jan 2, 2008
Post comments count0
Post likes count0

You know the answer: Window destruction

Raymond Chen
Raymond Chen

The following request for assistance came in from a customer, and given what you know about window destruction, you should eventually be able to figure it out yourself once all the pieces are in place, though it takes some time for all the clues to be revealed. We are hitting this exception in our program. This is urgent; please give it priorit...

Code
Dec 27, 2007
Post comments count0
Post likes count0

If you need anything other than natural alignment, you have to ask for it

Raymond Chen
Raymond Chen

If you need variables to be aligned a particular way, you need to ask for it. Let's say I have the following code: What would the alignment of the starting adresses of a,b,c and d be? What would the alignment be if the memory were allocated on heap? If this alignment varies for different data types within the same translation unit, is th...

Code