Showing tag results for Code

Sep 29, 2011
Post comments count0
Post likes count0

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

Raymond Chen
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 count0

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

Raymond Chen
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 count0

Why does my asynchronous I/O complete synchronously?

Raymond Chen
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 count0

Why does my single-byte write take forever?

Raymond Chen
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
Sep 19, 2011
Post comments count0
Post likes count0

The clipboard viewer linked list is no longer the responsibility of applications to maintain, unless they want to

Raymond Chen
Raymond Chen

Commenter Nice Clipboard Manager (with drop->clipboard) wonders why Windows still uses a linked list to inform programs about clipboard modifications. If any clipboard viewer fails to maintain the chain, then some windows won't get informed of the change, and if a clipboard viewer creates a loop in the chain, an infinite loop results. Well, ...

Code
Sep 16, 2011
Post comments count0
Post likes count0

Why can't I PostMessage the WM_COPYDATA message, but I can SendMessageTimeout it with a tiny timeout?

Raymond Chen
Raymond Chen

After receiving the explanation of what happens to a sent message when reaches its timeout, a customer found that the explanation raised another question: If the window manager waits until the receiving thread finishes processing the message, then why can't you post a message? "After all, with a very short timeout isn't all that different from ...

Code
Sep 15, 2011
Post comments count0
Post likes count0

What happens to a sent message when SendMessageTimeout reaches its timeout?

Raymond Chen
Raymond Chen

The function tries to send a message, but gives up if the timeout elapses. What exactly happens when the timeout elapses? It depends. The first case is if the receiving thread never received the message at all. (I.e., if during the period the sender is waiting, the receiving thread never called , , or a similar message-retrieval function which d...

Code
Sep 14, 2011
Post comments count0
Post likes count0

A common control for associating extensions is well overdue

Raymond Chen
Raymond Chen

Mark complained that a common control for associating extensions is well overdue. This is a recurring theme I see in the comments: People complaining that Windows lacks some critical feature that it in fact already has. (In the case, Windows had the feature for over two years at the time the question was asked. Maybe the SDK needs a ribbon? j/k) ...

Code
Sep 12, 2011
Post comments count0
Post likes count0

Is this a really bug with CreateWindowEx or am I just confused?

Raymond Chen
Raymond Chen

Somebody sent me email pointing out strange behavior in the function if you fail a window creation by returning −1 from the message. On the other hand, returning from seems to work just fine. "So why the difference with ?" You already know enough to solve this puzzle. You just need to connect the dots. (In fact, the person who sent ...

Code