Showing tag results for Code

Oct 13, 2011
Post comments count0
Post likes count1

How do I set an accessible name on an unlabeled control?

Raymond Chen

A customer asked for advice on accessibility. This was great news, because it meant that somebody actually cared about accessibility! We have a property sheet page that contains an unlabeled list view. The list view is not labeled because its meaning is implied by its placement on the dialog. This works great as long as you can see the screen, bu...

Code
Oct 12, 2011
Post comments count0
Post likes count1

Is there a 2048 character limit for OFN_ALLOWMULTISELECT in MFC or isn't there?

Raymond Chen

The MFC documentation for contains the following strange warning: When the user allocates their own buffer to accommodate , the buffer can't be larger than 2048 or else everything gets corrupted (2048 is the maximum size). The sudden informality of the phrase "or else everything gets corrupted" is surprising but also sounds vaguely familiar to...

Code
Oct 10, 2011
Post comments count0
Post likes count1

How do I access a file without updating its last-access time?

Raymond Chen

The first problem with discussing file last-access time is agreeing what you mean by a file's last-access time. The file system folks have one definition of the file last-access time, namely the time the file was most recently opened and either read from or written to. This is the value retrieved by functions like , , and . The problem with th...

Code
Oct 7, 2011
Post comments count0
Post likes count1

During process termination, slim reader/writer locks are now also electrified

Raymond Chen

Some time ago I mentioned that during process termination, the gates are now electrified: If you attempt to enter a critical section that is owned by a thread that was terminated by an earlier phase of process termination, the entire process is forcibly terminated. Windows Vista introduced a new lightweight synchronization pseudo-object known as ...

Code
Oct 3, 2011
Post comments count0
Post likes count1

Do not access the disk in your IContextMenu handler, no really, don't do it

Raymond Chen

We saw some time ago that the number one cause of crashes in Explorer is malware. It so happens that the number one cause of hangs in Explorer is disk access from context menu handlers (a special case of the more general principle, you can't open the file until the user tells you to open it). That's why I was amused by Memet's claim that "w...

Code
Sep 29, 2011
Post comments count0
Post likes count1

Appearing to succeed is a valid form of undefined behavior, but it's still undefined

Raymond Chen

A customer requested a clarification on the MSDN documentation for the function. The MSDN documentation says that if the parameter is , then the behavior is undefined. Is this true? As explicitly stated in MSDN, the behavior is undefined. Observe that the annotation on the parameter is , which means that the parameter must be a non- value...

Code
Sep 26, 2011
Post comments count0
Post likes count1

Sending a window a WM_DESTROY message is like prank calling somebody pretending to be the police

Raymond Chen

A customer was trying to track down a memory leak in their program. Their leak tracking tool produced the stacks which allocated memory that was never freed, and they all seemed to come from , which is a DLL that comes with Windows. The customer naturally contacted Microsoft to report what appeared to be a memory leak in Windows. I was one of th...

Code
Sep 23, 2011
Post comments count0
Post likes count1

Why does my asynchronous I/O complete synchronously?

Raymond Chen

A customer was creating a large file and found that, even though the file was opened with and the call was being made with an structure, the I/O was nevertheless completing synchronously. Knowledge Base article 156932 covers some cases in which asynchronous I/O will be converted to synchronous I/O. And in this case, it was scenario number thre...

Code
Sep 22, 2011
Post comments count0
Post likes count1

Why does my single-byte write take forever?

Raymond Chen

A customer found that a single-byte write was taking several seconds, even though the write was to a file on the local hard drive that was fully spun-up. Here's the pseudocode: The customer experimented with using asynchronous I/O, but it didn't help. The write still took a long time. Even using (and writing full sectors, naturally) didn't he...

Code