Showing results for Code - The Old New Thing

Jul 30, 2014
Post comments count0
Post likes count0

If you want to be notified when your app is uninstalled, you can do that from your uninstaller

Raymond Chen
Raymond Chen

A customer had a rather strange request. "Is there a way to be notified when the user uninstalls any program from Programs and Features (formerly known as Add and Remove Programs)?" They didn't explain what they wanted to do this for, and we immediately got suspicious. It sounds like the customer is trying to do something user-hostile, like seeing...

Code
Jul 28, 2014
Post comments count0
Post likes count0

Finding the shortest path to the ground while avoiding obstacles

Raymond Chen
Raymond Chen

Today's Little Program solves the following problem: Consider a two-dimensional board, tall and narrow. Into the board are nailed a number of horizontal obstacles. Place a water faucet at the top of the board and turn it on. The water will dribble down, and when it hits an obstacle, some of the water will go left and some will go right. The goal...

Code
Jul 25, 2014
Post comments count0
Post likes count0

How do I obtain the computer manufacturer's name from C++?

Raymond Chen
Raymond Chen

Some time ago, I gave a scripting solution to the problem of obtaining the computer manufacturer and model. But what if you want to do this from C++? I could translate the script into C++, or I could just point you to Creating a WMI Application Using C++ in MSDN. In particular, one of the WMI C++ Sample Applications does exactly what you want:...

Code
Jul 24, 2014
Post comments count0
Post likes count0

When I send a WM_GETFONT message to a window, why don't I get a font?

Raymond Chen
Raymond Chen

A customer reported that the message was not working. Specifically, they sent the message to a window, and they can plainly see that the window is rendering with a particular font, yet the message returns 0. Why isn't the window returning the correct font handle? The and messages are not mandatory. A window may choose to support them, or it ma...

Code
Jul 23, 2014
Post comments count0
Post likes count0

When will GetSystemWindowsDirectory return something different from GetWindowsDirectory?

Raymond Chen
Raymond Chen

Most of the time, the returns the Windows directory. However, as noted in the documentation for : With Terminal Services, the Get­System­Windows­Directory function retrieves the path of the system Windows directory, while the Get­Windows­Directory function retrieves the path of a Windows directory that is private for each user...

Code
Jul 21, 2014
Post comments count0
Post likes count0

How can I get the URL to the Web page the clipboard was copied from?

Raymond Chen
Raymond Chen

When you copy content from a Web page to the clipboard and then paste it into OneNote, OneNote pastes the content but also annotates it "Pasted from ...". How does OneNote know where the content was copied from? As noted in the documentation for the HTML clipboard format, Web browsers can provide an optional property to specify the Web page th...

Code
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