Showing tag results for Code

Nov 12, 2014
Post comments count0
Post likes count1

How can I wait until all startup applications have finished launching?

Raymond Chen

A customer wanted to know how to detect that all startup applications have finished launching. They wanted to wait until everything settled down before proceeding with some task. What if two programs did this? Suppose two programs both wanted to detect that all startup applications have finished launching. Each one would sit there waiting for the...

Code
Nov 10, 2014
Post comments count0
Post likes count1

Kicking around a function that formats stuff

Raymond Chen

Today's "Little Program" is really a "Little Puzzle" that got out of hand. This started out as a practical question: This code fragment screams out for some sort of simplification. (I've changed the names of the classes.) Clearly, the pattern is Everything here is pretty straightforward, except for the part. Can we write a function that t...

Code
Nov 7, 2014
Post comments count0
Post likes count1

Why does an attempt to create a SysLink control in my plug-in sometimes fail?

Raymond Chen

A customer had written a plug-in for some application, and they found that their plug-in was unable to create a SysLink control via the function. The same code in a standalone application works fine, but when the code is placed in their plug-in, the code fails. Debugging showed that the call to succeeded, but the call failed with "Cannot find w...

Code
Nov 6, 2014
Post comments count0
Post likes count2

How do I get a handle to the primary monitor?

Raymond Chen

There are various ways of getting a monitor. You can get the monitor from a point, from a rectangle, or from a window. But how do you get the primary monitor? The primary monitor is defined to be the one which has (0, 0) as its origin. Therefore, one solution is The desktop window by convention is deemed to reside primarily on the primary mo...

Code
Nov 5, 2014
Post comments count0
Post likes count1

Passing the incorrect object type for a handle, how bad is it?

Raymond Chen

A customer asked a somewhat strange question: "We are calling but passing the handle to a waitable timer. Application Verifier reports, "Incorrect object type for handle." But the code works well. We want to know the risks of passing the wrong object type to . Is the recommendation only to pass handles of type "Event" to ? Let's answer those ques...

Code
Nov 3, 2014
Post comments count0
Post likes count2

Applying a filter to the contents of an Explorer Browser

Raymond Chen

Today's Little Program hosts an Explorer Browser but filters the contents to remove DLL files. You can, of course, substitute your own filter. (For example, maybe you want to show only files that changed since the last time the user ran your program, or you might want a view of My Computer but filtered to show only removable drives.) Remember th...

Code
Oct 31, 2014
Post comments count0
Post likes count1

The case of the file that won't copy because of an Invalid Handle error message

Raymond Chen

A customer reported that they had a file that was "haunted" on their machine: Explorer was unable to copy the file. If you did a copy/paste, the copy dialog displayed an error. Okay, time to roll up your sleeves and get to work. This investigation took several hours, but you'll be able to read it in ten minutes because I'm deleting all t...

Code
Oct 29, 2014
Post comments count0
Post likes count1

The contents of the Start page are not programmatically accessible

Raymond Chen

A customer wanted to know if is possible for an application to edit the user's Start page. No, there is no interface for editing the user's Start page or even knowing what is on it. The Start page is the user's personal space and applications should not be messing with it. Imagine if it were possible. Every application would edit the Start page t...

Code
Oct 28, 2014
Post comments count0
Post likes count1

A question about preventing the system from going to the idle state turns out to be misguided

Raymond Chen

A customer asked how they could have their program prevent the system from going to the idle state. Specifically, when the system goes idle, the application gets into a weird state where it starts leaking memory like crazy. The program normally uses around 100MB of memory, but when the system goes idle, something funky happens and the program's mem...

Code
Oct 27, 2014
Post comments count0
Post likes count1

Enumerating the ways of distributing n balls into k boxes

Raymond Chen

Suppose you had n indistinguishable balls and k distinguishable boxes. Enumerate the ways of distributing the balls into boxes. Some boxes may be empty. We can represent each distribution in the form of n stars and k − 1 vertical lines. The stars represent balls, and the vertical lines divide the balls into boxes. For example, here are the...

Code