Showing tag results for Code

Sep 22, 2008
Post comments count0
Post likes count1

I’ve seen why people steal the foreground window for their dialog box

Raymond Chen

Now, it may very well be true that many people who use as the owner for a dialog box because they don't know any better, but I'm not convinced that everyone who does so did it out of ignorance; I'm sure there's some malice in there, too. Here's how it may have gone down: Bug: I start the product setup, and then I go and work on something el...

Code
Sep 19, 2008
Post comments count0
Post likes count1

How can I tell that a directory is weird and should be excluded from the user interface?

Raymond Chen

Last time, we looked at a customer who wanted to know how to tell whether a given folder was a Recycle Bin folder or not. We answered the question as stated, but made the mistake of not looking at the problem the customer was trying to solve. I need to know which folders are Recycle Bin folders so I can skip over them when searching the drive f...

Code
Sep 18, 2008
Post comments count0
Post likes count1

How can I tell that a directory is really a recycle bin?

Raymond Chen

Here's a question inspired by an actual customer question: I need a function that, given a path, tells me whether it is a Recycle Bin folder. I tried using functions like SHGetSpecialFolderPath with CSIDL_BITBUCKET, but that doesn't work because the Recycle Bin is a virtual folder that is the union of the Recycle Bins of all drives. The custom...

Code
Sep 12, 2008
Post comments count0
Post likes count1

Who is responsible for destroying the font passed in the WM_SETFONT message?

Raymond Chen

The message tells a control which font you would like the control to use for its text. This message is a convention, not a rule. For example, our scratch program doesn't pay attention to the message. If somebody sends it a , nothing happens. The scratch program just ignores the caller and uses whatever font it wants. Although supporting the m...

Code
Sep 1, 2008
Post comments count0
Post likes count1

How do I convert an error code to text when FORMAT_MESSAGE_FROM_SYSTEM doesn’t work?

Raymond Chen

For the same reason that not all error codes are defined in , not all error strings are defined in the system message table. If you've ever played with the message compiler, you'd quickly have recognized the file as the header file associated with a message resource. In other words, there's a file that gets processed by the message compiler, an...

Code
Aug 29, 2008
Post comments count0
Post likes count1

What possible use are those extra bits in kernel handles? Part 3: New object types

Raymond Chen

Last time, we saw how those extra bits can be used to multiplex HANDLE with other values. That was a specific case of a more general scenario: Expanding the handle namespace to include things that aren't handles. (You can also view today's example as a generalization of the sentinel value problem, where we need to generate an arbitrary number of...

Code
Aug 28, 2008
Post comments count0
Post likes count1

What possible use are those extra bits in kernel handles? Part 2: Overcoming limited expressiveness

Raymond Chen

Last time, we saw how those extra bits can be used to develop safe sentinel values. That is a special case of a more general problem: How do you pack 33 bits of information into a 32-bit value? Whereas last time, we weren't forced into the use of a sentinel value because we could develop a (cumbersome) helper class and switch people over to ...

Code
Aug 27, 2008
Post comments count0
Post likes count1

What possible use are those extra bits in kernel handles? Part 1: Sentinels

Raymond Chen

Kernel handles are always a multiple of four; the bottom two bits are available for applications to use. But why would an application need those bits anyway? The short answer is extending the handle namespace. The long answer will take a few days to play out. (This series was written in response to Igor Levicki being unable to imagine "how thi...

Code
Aug 15, 2008
Post comments count0
Post likes count0

The implementation of iterators in C# and its consequences (part 4)

Raymond Chen

You can breathe a sigh of relief. Our long national nightmare is over: this is the end of CLR Week 2008. We wind down with a look back at iterators. Michael Entin points out that you can use C# iterators to make asynchronous code easier to write. You can use C# iterators for more than simply iterating. The automatic conversion of...

Code
Aug 14, 2008
Post comments count0
Post likes count0

The implementation of iterators in C# and its consequences (part 3)

Raymond Chen

I mentioned that there was an exception to the general statement that the conversion of an iterator into traditional C# code is something you could have done yourself. That's true, and it was also a pun, because the exception is exception handling. If you have a try ... finally block in your iterator, the language executes the finally block und...

Code