Showing archive results for 2012

Apr 11, 2012
Post comments count0
Post likes count1

I know that an overlapped file handle requires an lpOverlapped, but why does it (sometimes) work if I omit it?

Raymond Chen

A customer observed that the formal requirements for the function specify that if the handle was opened with , then the parameter is mandatory. But the customer observed that in practice, passing results in strange behavior. Sometimes the call succeeds, and sometimes it even returns (horrors!) valid data. (Actually the more horrifying case is w...

Other
Apr 10, 2012
Post comments count0
Post likes count1

Microspeak: scoped to

Raymond Chen

The Merriam-Webster dictionary gives as the meaning of scope as a verb to look at for evaluation, as in "to scope out the competition." But that's not how we use it at Microsoft. Here are some fake citations: The Widgets pop-up shows the available widgets scoped to the current selection. The results of the search are scoped to the current fold...

OtherMicrospeak
Apr 9, 2012
Post comments count0
Post likes count1

There's the interface contract, and there are the implementations of the interface contract

Raymond Chen

Ivo wants to know whether it is legal to use as the icon parameters to . The documentation says that the parameters are optional, but some shell folder implementations treat them as mandatory. Yes, the parameters are technically optional, but it's also the case that many people mess up their implementation of the interface and treat them as mand...

Code
Apr 6, 2012
Post comments count0
Post likes count1

Registration-free COM the old-fashioned way: The car mp3 player

Raymond Chen

Windows XP introduced Registration-Free COM, permitting you to place your COM object registrations in a manifest rather than in the registry. Very handy when you want to support xcopy deployment or running directly off a thumb drive. And very much in keeping with the principle of not using a global solution for a local problem. (If you need y...

Code
Apr 5, 2012
Post comments count0
Post likes count1

You can use an OVERLAPPED structure with synchronous I/O, too

Raymond Chen

Even if you didn't open a file with , you can still use the structure when you issue reads and writes. Mind you, the I/O will still complete synchronously, but you can take advantage of the other stuff that has to offer. Specifically, you can take advantage of the and members to issue the I/O against a file location different from the curren...

Code
Apr 4, 2012
Post comments count0
Post likes count1

I totally presented to an executive the wrong way

Raymond Chen

Some time ago, Gray Knowlton wrote an article on how to present to an executive. As you might have guessed, I've done it completely the wrong way. Many years ago, I was part of a group presenting to a senior-level executive. I was the one who wrote the document establishing the background for the topic and laying out the various options with t...

Other
Apr 3, 2012
Post comments count0
Post likes count1

Introducing the unrolled-switch anti-pattern

Raymond Chen

Over the years, I've seen a bunch of coding anti-patterns. I figured maybe I'll share a few. Today, I'll introduce what I'm calling the unrolled-switch anti-pattern, also known as "Specialization is always faster, right?" As we all know, special-case code is faster than general-purpose code. Instead of writing slow general-purpose code: we ...

Code
Apr 2, 2012
Post comments count0
Post likes count1

If posting here is frequently frustrating and irritating, why do I keep doing it?

Raymond Chen

Appreciator wonders, if I find posting here frequently frustrating and irritating, why I keep doing it anyway? Imagine I announced one day, "This is too frustrating and annoying. I'm going to stop now." To the rest of the world, this would "mean something." People would discuss in hushed tones—and for the Internet, hushed tones means in a n...

Non-Computer
Mar 30, 2012
Post comments count0
Post likes count1

How do I perform shell file operations while avoiding shell copy hooks?

Raymond Chen

Okay, the subject line of the article gives away the answer to the puzzle, but here's the puzzle anyway: A customer reported a problem with the function: Consider the following program: If "a" is a file, then everything works fine, but if it's a directory, then Application Verifier raises the following error: Heap violation detected Memor...

Code
Mar 29, 2012
Post comments count0
Post likes count1

Why can't I delete a file immediately after terminating the process that has the file open?

Raymond Chen

A customer discovered a bug where terminating a process did not close the handles that the process had open, resulting in their emergency cleanup code not working: Their workaround was to insert a call to before deleting the file. The customer wanted to know whether they discovered a bug in , and they were concerned that their workaround could...

Code