Showing tag results for Code

Mar 25, 2004
Post comments count0
Post likes count0

Regular expressions and the dreaded *? operator

Raymond Chen

The regular expression *? operator means "Match as few characters as necessary to make this pattern succeed." But look at what happens when you mix it up a bit: This pattern matches a quoted string containing no embedded quotes. This works because the first quotation mark starts the string, the .*? gobbles up everything in between, and th...

Code
Mar 22, 2004
Post comments count0
Post likes count0

Why an object cannot be its own enumerator

Raymond Chen

I've seen people using the following cheat when forced to implement an enumerator: Why create a separate enumerator object when you can just be your own enumerator? It's so much easier. And it's wrong. Consider what happens if two people try to enumerate your formats at the same time: The two enumerators are really the same enumerator, so o...

Code
Mar 12, 2004
Post comments count0
Post likes count0

What is the default security descriptor?

Raymond Chen

All these functions have an optional LPSECURITY_ATTRIBUTES parameter, for which everybody just passes NULL, thereby obtaining the default security descriptor. But what is the default security descriptor? Of course, the place to start is MSDN, in the section titled Security Descriptors for New Objects. It says that the default DACL comes from ...

Code
Mar 9, 2004
Post comments count0
Post likes count0

Char.IsDigit() matches more than just "0" through "9"

Raymond Chen

Warning: .NET content ahead! Yesterday, Brad Abrams noted that Char.IsLetter() matches more than just "A" through "Z". What people might not realize is that Char.IsDigit() matches more than just "0" through "9". Valid digits are members of the following category in UnicodeCategory: DecimalDigitNumber. But what exactly is a DecimalDigitNumber? ...

Code
Feb 27, 2004
Post comments count0
Post likes count0

The correct order for disabling and enabling windows

Raymond Chen

If you want to display modal UI, you need to disable the owner and enable the modal child, and then reverse the procedure when the modal child is finished. And if you do it wrong, focus will get all messed up. If you are finished with a modal dialog, your temptation would be to clean up in the following order: But if you do that, you'll...

Code
Feb 24, 2004
Post comments count0
Post likes count0

What's so special about the desktop window?

Raymond Chen

The window returned by GetDesktopWindow() is very special, and I see people abusing it all over the place. For example, many functions in the shell accept a window handle parameter to be used in case UI is needed. IShellFolder::EnumObjects, for example. What happens if you pass GetDesktopWindow()? If UI does indeed need to be displaye...

Code
Feb 23, 2004
Post comments count0
Post likes count0

Invalid thread and process IDs

Raymond Chen

Perhaps you want a value to use as a sentinel, which you want to be guaranteed is never a valid thread ID or process ID. What values can you use? Nothing is explicitly written about this topic, but you can put on your logic cap and figure it out. If you need an invalid thread ID, you can use zero. How do you know that zero is an invalid thr...

Code
Feb 17, 2004
Post comments count0
Post likes count2

GetDialogBaseUnits is a crock

Raymond Chen

Each dialog can have different base units, so it's meaningless to have a global converter.

Code