Showing tag results for Code

Aug 8, 2014
Post comments count0
Post likes count1

The case of the orphaned LpdrLoaderLock critical section

Raymond Chen
Raymond Chen

A customer found that under heavy load, their application would occasionally hang. Debugging the hang shows that everybody was waiting for the critical section. The catch was that the critical section was reported as locked, but the owner thread did not exist. How can a critical section be owned by thread that no longer exists? There are two...

Code
Aug 7, 2014
Post comments count0
Post likes count1

Since clean-up functions can't fail, you have to soldier on

Raymond Chen
Raymond Chen

Clean-up functions can't fail, so what do you do if you encounter a failure in your clean-up function? You have to keep cleaning up. Some people like to follow this pattern for error checking: And some like to put it inside a cute flow control macro like or even Whatever floats your boat. But you have to be careful if using this p...

Code
Aug 6, 2014
Post comments count0
Post likes count1

Why does Explorer say "File too large" for my custom file system, when the problem has nothing to do with the file being too large (heck it's not even a file)

Raymond Chen
Raymond Chen

When Explorer copies files around, it doesn't really know what the maximum file size supported by any file system happens to be. (That information is not reported by .) So it guesses. If the file system name is or , then Explorer assumes that the maximum file size is 4GB − 1. Also, if a file operation fails with the error , and Explorer ca...

Code
Aug 4, 2014
Post comments count0
Post likes count1

Enumerating the ways of choosing teams in a group of players

Raymond Chen
Raymond Chen

Suppose you have a bunch of people, and you want to break them up into m teams of size n. (Therefore you have a total of nm people.) Today's Little Program will enumerate the ways this can be done. Formally, let's say that you have a collection of size nm, and you want to enumerate the ways of partitioning the collection into m subsets, each sub...

Code
Aug 1, 2014
Post comments count0
Post likes count1

Before claiming that a function doesn't work, you should check what you're passing to it and what it returns

Raymond Chen
Raymond Chen

Before claiming that a function doesn't work, you should check what you're passing to it and what it returns, because it may be that the function is behaving just fine and the problem is elsewhere. The function does not appear to support directories with Unicode characters in their names. The correct directory name is obtained if it contain...

Code
Jul 31, 2014
Post comments count0
Post likes count1

What is the strange garbage-looking string in the "command" value of a static verb?

Raymond Chen
Raymond Chen

A customer from a major software vendor asked, "What is the significance of the value that can be found under . It appears to be a copy of the default value, but with the program name replaced with apparent garbage. We've seen this both with Microsoft products as well as products by other companies. There is no mention of this value in the docume...

Code
Jul 30, 2014
Post comments count0
Post likes count1

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 count1

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 count1

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 count1

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