Showing tag results for Code

Jun 29, 2009
Post comments count0
Post likes count1

If you want to consume all the virtual address space, well, then go ahead and consume it, you don’t need my help

Raymond Chen

Commenter Matthew Chaboud asks if there's an easy way to consume all the virtual address space below 4GB, short of, well, actually allocating it. "It seems like there should be a cleaner way to do this." If you want to consume all the virtual address space, then call until you turn blue. Programs shouldn't care what address they get back from ...

Code
Jun 26, 2009
Post comments count0
Post likes count1

The thread that gets the DLL_PROCESS_DETACH notification is not necessarily the one that got the DLL_PROCESS_ATTACH notification

Raymond Chen

The thread that gets the notification is not necessarily the one that got the notification. This is obvious if you think about it, because the thread that got the notification might not even exist any longer when the DLL is unloaded. How can something that doesn't exist send a notification? Even so, many people fail to realize this. You can't ...

Code
Jun 19, 2009
Post comments count0
Post likes count1

You can’t leave a critical section you never entered

Raymond Chen

If you call on a critical section you never entered, the behavior is undefined. Critical sections are an extremly high-traffic code path. Intense work goes into making them as fast as possible. Customers like to ask questions like "Exactly how many cycles does it take to enter a critical section? We're not going to use them if they're too slow."...

Code
Jun 18, 2009
Post comments count0
Post likes count1

The dangers of mixing synchronous and asynchronous state

Raymond Chen

The window manager distinguishes between synchronous state (the state of the world based on what messages your program has received) and asynchronous state (the actual state of the world this very instant). We saw this earlier when discussing the difference between GetKeyState and GetAsyncKeyState. Here are some other functions and their relation...

Code
Jun 4, 2009
Post comments count0
Post likes count1

Why can’t I rotate the display with ChangeDisplaySettingsEx?

Raymond Chen

If you have one of those cool swively LCD displays (or if you decided to build your own), you naturally want to tell your video card to display rotated output, so you can take advantage of the portrait orientation. And naturally you would think that calling the and using the field of the structure would do the trick. And then you would find t...

Code
May 29, 2009
Post comments count0
Post likes count1

Alternatives to using the #error directive to check whether the compiler even sees you

Raymond Chen

In response to my description of how you can use the #error directive to check whether the compiler even sees you, some commenters proposed alternatives. I never claimed that my technique was the only one, just that it was another option available to you. Here are some other options. scott suggested merely typing asdasdasd into the header file ...

Code
May 25, 2009
Post comments count0
Post likes count1

Why can’t you change the alignment of an edit control after it has been created?

Raymond Chen

Commenter Kevin Eshbach asks why you cannot programatically change the text centering style of an edit control after the control has been created. The edit control is one of the original window manager controls, so it comes with a lot of history. First thing to note is that the message did not exist until Windows 95. The edit control preda...

Code
May 22, 2009
Post comments count0
Post likes count1

If an event is signaled more than once, are they delivered in the order in which they were signaled?

Raymond Chen

A customer asked the following question: Is it guaranteed that the events when signaled multiple times on an event object are delivered in the order in which they were signaled? For example, a thread is waiting on the event handle and performs some operation each time it is signaled. The ordering of those operations should be in the same order...

Code
May 18, 2009
Post comments count0
Post likes count1

How do I know whether a window message was processed?

Raymond Chen

Commenter Skeets Norquist asks how to tell whether the original window procedure processed a message when you use to call the original window procedure. "CallWindowProc() always seems to return an LRESULT of 0." No, actually, returns whatever the window procedure did. If the window procedure returned zero, then returns zero. If the window pro...

Code