Showing results for Code - The Old New Thing

Jul 17, 2014
Post comments count0
Post likes count0

What does it mean when GetQueuedCompletionStatus return ERROR_SEM_TIMEOUT?

Raymond Chen
Raymond Chen

A customer asked for assistance interpreting a failure of the function. We are observing that is intermittently behaving as follows: That's all the information we have in our log files. We don't know the value of or , sorry. We realize that this is a rather vague question, but when this problem hits our machines, it causes our internal l...

Code
Jul 16, 2014
Post comments count0
Post likes count0

How do I configure Windows Update programmatically?

Raymond Chen
Raymond Chen

First of all, normal programs shouldn't be messing with Windows Update configuration. That's something the user (or the user's administrator) decides. If you're an IT administrator, then you can use Group Policy to configure Windows Update on your network. But maybe you're a special case where the above remarks don't apply. Say you're a data ce...

Code
Jul 14, 2014
Post comments count0
Post likes count0

Enumerating integer compositions (the return of the binomial coefficients)

Raymond Chen
Raymond Chen

In number theory, a composition of an integer is an ordered sequence of positive integers which sum to the target value. For example, the value 3 can be written as 3, 1+2, 2+1, or 1+1+1. You can think about the target number as a string of stars, and a composition is a way of breaking the stars into groups. For example, here are the compositions...

Code
Jul 11, 2014
Post comments count0
Post likes count0

If I duplicate a handle, can I keep using the duplicate after closing the original?

Raymond Chen
Raymond Chen

A customer asked whether it was okay to use a duplicated handle even after the original handle was closed. Yes. That's sort of why you would duplicate it. Duplicating a handle creates a second handle which refers to the same underlying object as the original. Once that's done, the two handles are completely equivalent. There's no way to know whic...

Code
Jul 10, 2014
Post comments count0
Post likes count0

Using the REFIID/void** pattern for returning COM objects for future-proofing and to avoid problems with dependencies

Raymond Chen
Raymond Chen

Suppose you have a function that creates a reference to a COM object: There are a few issues with this design. First of all, it requires that whoever uses your header file must have included first, since that's where is defined. You could solve that problem by putting at the top of , but that creates its own problems. For example, many hea...

Code
Jun 30, 2014
Post comments count0
Post likes count0

Getting the location of the Close button in the title bar, from Windows 2000 or Windows XP

Raymond Chen
Raymond Chen

Today's Little Program locates the × button in the corner of the window and displays a balloon tip pointing at it. We did this some time ago with the help of the message, which is new for Windows Vista. But what if you don't have that message available, say, because you're running on Windows 2000 or Windows XP or (gasp) Windows 9...

Code
Jun 23, 2014
Post comments count0
Post likes count0

Adding a sound to the Alt+Tab window

Raymond Chen
Raymond Chen

Today's Little Program plays a sound when the Alt+Tab window appears and disappears. The program registers an accessibility event hook for the and events. The Start event fires when an Alt+Tab operation begins, and the End event fires when an Alt+Tab operation completes. As noted in the documentation, you can get spurious End events, so we k...

Code
Jun 20, 2014
Post comments count0
Post likes count0

Once you go input-idle, your application is deemed ready to receive DDE messages

Raymond Chen
Raymond Chen

Feel free to stop using DDE. There was one customer who confessed that they were still using DDE, and they asked for help debugging a DDE problem. They found that sometimes, when their application was launched for DDE, it never received the message. Instead, the function returned . If launched from Explorer, the error message shown to the user ...

Code