Showing tag results for Code

Mar 28, 2011
Post comments count0
Post likes count1

Why did Win32 define BOOL as a signed int instead of an unsigned int?

Raymond Chen
Raymond Chen

Igor Levicki wants somebody from Microsoft to explain why was defined as a instead of an . You don't need to work for Microsoft to figure this out. All the information you need is publically available. Quoting from K&R Classic, which was the operative C standards document at the time Windows was being developed: 7.6 Relational Operators ...

Code
Mar 25, 2011
Post comments count0
Post likes count1

How do I monitor, or even control, the lifetime of an Explorer window?

Raymond Chen
Raymond Chen

A customer wanted help with monitoring the lifetime of an Explorer window. We want to launch a copy of Explorer to open a specific folder, then wait until the user closes the folder before continuing. We tried launching a copy of Explorer with the folder on the command line, then doing a on the process handle, but the wait sometimes completes i...

Code
Mar 23, 2011
Post comments count0
Post likes count1

Function requirements are cumulative: If you fail to meet any of them, then all bets are off

Raymond Chen
Raymond Chen

A customer was having problems with the function: We are looking for a clarification of the behavior of . We have a thread that waits on two handles (call them and ) with , . Under certain conditions, we signal and close from another thread while the wait is in progress. This results in being returned from the wait call. MSDN is not clear o...

Code
Mar 18, 2011
Post comments count0
Post likes count1

You can extend the PROPSHEETPAGE structure with your own bonus data

Raymond Chen
Raymond Chen

... for when regular strength lParam just isn't enough. A little-known and even less-used feature of the shell property sheet is that you can hang custom data off the end of the structure, and the shell will carry it around for you. Mind you, the shell carries it around by means of and destroys it by just freeing the underlying memory, so what...

Code
Mar 11, 2011
Post comments count0
Post likes count1

Why does my TIME_ZONE_INFORMATION have the wrong DST cutover date?

Raymond Chen
Raymond Chen

Public Service Announcement: Daylight Saving Time begins in most parts of the United States this weekend. Other parts of the world may change on a different day from the United States. A customer reported that they were getting incorrect values from the function. I have a program that calls , and it looks like it's returning incorrect DST trans...

CodeTime
Mar 10, 2011
Post comments count0
Post likes count1

How do I create a topmost window that is never covered by other topmost windows?

Raymond Chen
Raymond Chen

We already know that you can't create a window that is always on top, even in the presence of other windows marked always-on-top. An application of the What if two programs did this? rule demonstrates that it's not possible, because whatever trick you use to be on-top-of-always-on-top, another program can use the same trick, and now you have two o...

Code
Mar 7, 2011
Post comments count0
Post likes count1

What's the difference between FreeResource and, say, DestroyAcceleratorTable

Raymond Chen
Raymond Chen

MaxMax asks a number of resource-related questions, starting with "How do you Unlock a Lock­Resource?" and culminating in "What are the differences between and , , etc.? It would be much easier to use a single function instead of a collection of five." It helps if you understand the history of resources, because the functions were designed b...

Code
Mar 4, 2011
Post comments count0
Post likes count1

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 count1

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 count1

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