Showing results for Code - The Old New Thing

Oct 9, 2008
Post comments count0
Post likes count0

How can I increase the number of files I can open at a time?

Raymond Chen
Raymond Chen

People who ask this question invariably under-specify the question. They just say, "How can I increase the number of files I can open at a time?" without saying how they're opening them. From the operating system's point of view, the number of files you can open at a time is limited only by available resources. Call until you drop. (This remark ap...

Code
Oct 3, 2008
Post comments count0
Post likes count0

Acquire and release sound like bass fishing terms, but they also apply to memory models

Raymond Chen
Raymond Chen

Many of the normal interlocked operations come with variants called InterlockedXxxAcquire and InterlockedXxxRelease. What do the terms Acquire and Release mean here? They have to do with the memory model and how aggressively the CPU can reorder operations around it. An operation with acquire semantics is one which does not permit subsequent me...

Code
Sep 29, 2008
Post comments count0
Post likes count0

Anybody can make up a generic mapping

Raymond Chen
Raymond Chen

Each component that uses ACLs to control access has its own idea of what GENERIC_READ, GENERIC_WRITE, and GENERIC_EXECUTE mean. It's not like there's a master list that somebody can make that lists them all, because I can make up a new one right here. Watch me: #define GIZMO_QUERY_STATUS 0x0001 #define GIZMO_QUERY_MEMBERS 0x0002 #define GIZM...

Code
Sep 26, 2008
Post comments count0
Post likes count1

ERRORLEVEL is not %ERRORLEVEL%

Raymond Chen
Raymond Chen

The command interpreter cmd.exe has a concept known as the error level, which is the exit code of the program most recently run. You can test the error level with the IF ERRORLEVEL command: IF ERRORLEVEL 1 ECHO error level is 1 or more <sidebar> The IF ERRORLEVEL n test succeeds if the error level is n or more. This was presumably becaus...

Code
Sep 22, 2008
Post comments count0
Post likes count0

I’ve seen why people steal the foreground window for their dialog box

Raymond Chen
Raymond Chen

Now, it may very well be true that many people who use as the owner for a dialog box because they don't know any better, but I'm not convinced that everyone who does so did it out of ignorance; I'm sure there's some malice in there, too. Here's how it may have gone down: Bug: I start the product setup, and then I go and work on something el...

Code
Sep 19, 2008
Post comments count0
Post likes count0

How can I tell that a directory is weird and should be excluded from the user interface?

Raymond Chen
Raymond Chen

Last time, we looked at a customer who wanted to know how to tell whether a given folder was a Recycle Bin folder or not. We answered the question as stated, but made the mistake of not looking at the problem the customer was trying to solve. I need to know which folders are Recycle Bin folders so I can skip over them when searching the drive f...

Code
Sep 18, 2008
Post comments count0
Post likes count0

How can I tell that a directory is really a recycle bin?

Raymond Chen
Raymond Chen

Here's a question inspired by an actual customer question: I need a function that, given a path, tells me whether it is a Recycle Bin folder. I tried using functions like SHGetSpecialFolderPath with CSIDL_BITBUCKET, but that doesn't work because the Recycle Bin is a virtual folder that is the union of the Recycle Bins of all drives. The custom...

Code
Sep 12, 2008
Post comments count0
Post likes count0

Who is responsible for destroying the font passed in the WM_SETFONT message?

Raymond Chen
Raymond Chen

The message tells a control which font you would like the control to use for its text. This message is a convention, not a rule. For example, our scratch program doesn't pay attention to the message. If somebody sends it a , nothing happens. The scratch program just ignores the caller and uses whatever font it wants. Although supporting the m...

Code
Sep 1, 2008
Post comments count0
Post likes count0

How do I convert an error code to text when FORMAT_MESSAGE_FROM_SYSTEM doesn’t work?

Raymond Chen
Raymond Chen

For the same reason that not all error codes are defined in , not all error strings are defined in the system message table. If you've ever played with the message compiler, you'd quickly have recognized the file as the header file associated with a message resource. In other words, there's a file that gets processed by the message compiler, an...

Code
Aug 29, 2008
Post comments count0
Post likes count0

What possible use are those extra bits in kernel handles? Part 3: New object types

Raymond Chen
Raymond Chen

Last time, we saw how those extra bits can be used to multiplex HANDLE with other values. That was a specific case of a more general scenario: Expanding the handle namespace to include things that aren't handles. (You can also view today's example as a generalization of the sentinel value problem, where we need to generate an arbitrary number of...

Code