Showing tag results for Code

Jun 1, 2004
Post comments count0
Post likes count0

What does SHGFI_USEFILEATTRIBUTES mean?

Raymond Chen
Raymond Chen

One of the flags you can pass to the SHGetFileInfo function is SHGFI_USEFILEATTRIBUTES. What does this flag mean? It means, "Do not access the disk. Pretend that the file/directory exists, and that its file attributes are what I passed as the dwFileAttributes parameter. Do this regardless of whether it actually exists or not." You can ...

Code
May 28, 2004
Post comments count0
Post likes count0

High-performance multithreading is very hard

Raymond Chen
Raymond Chen

Among other things, you need to understand weak memory models. Hereby incorporating by reference Brad Abrams' discussion of volatile and MemoryBarrier(). In particular, Vance Morrison's discussion of memory models is important reading. (Though I think Brad is being too pessimistic about volatile. Ensuring release semantics at the stor...

Code
May 24, 2004
Post comments count0
Post likes count0

Extending the Internet Explorer context menu

Raymond Chen
Raymond Chen

In a comment, Darrell Norton asked for a "View in Mozilla" option for Internet Explorer. You can already do this. Internet Explorer's context menu extension mechanism has been in MSDN for years. Let me show you how you can create this extension yourself. First, create the following registry key: Of course, you need to change C:\some\pa...

Code
May 21, 2004
Post comments count0
Post likes count0

Do you know when your destructors run? Part 2.

Raymond Chen
Raymond Chen

Continuing from yesterday, here's another case where you have to watch your destructors. Yesterday's theme was destructors that run at the wrong time. Today, we're going to see destructors that don't run at all! Assume there's an ObjectLock class which takes a lock in its constructor and releases it in its destructor. Pretty standard stuff. Th...

Code
May 20, 2004
Post comments count0
Post likes count0

Do you know when your destructors run? Part 1.

Raymond Chen
Raymond Chen

Larry Osterman discussed the importance of knowing when your global destructors run, but this problem is not exclusive to global objects. You need to take care even with local objects. Consider: Easy as pie. And there's a bug here. When does the destructor for that smart-pointer run? Answer: When the object goes out of scope, which is a...

Code
May 18, 2004
Post comments count0
Post likes count0

String sorting is not done by ASCII code any more.

Raymond Chen
Raymond Chen

Just because you have the ASCII table memorized doesn't mean you know how sorting works. I remember a bug filed where somebody said that the "sort" command was sorting underscores incorrectly: this was claimed to be wrong "because underscore character follow uppercase letters and precedes lowercase letters". Well perhaps it does if you thi...

Code
May 11, 2004
Post comments count0
Post likes count0

Links about COM threading models

Raymond Chen
Raymond Chen

There have been a few good articles about threading models, one from Eric Lippert and another from Larry Osterman. Go off and read them if you haven't already.

Code
May 11, 2004
Post comments count0
Post likes count0

How do the FILE_SHARE_* bits interact with the desired access bits?

Raymond Chen
Raymond Chen

It's really not that complicated. If you permit, say, , then you're saying, "I'm okay with other people reading this file while I have it open." And if you leave off the flag, then you're saying, "I do not want other people reading this file while I have it open." Now all that's left to do is work out what that means. So suppose you omit t...

Code
May 10, 2004
Post comments count0
Post likes count0

There are two types of scrollbars

Raymond Chen
Raymond Chen

Remember that there are two types of scrollbars. One is the standalone scrollbar control. This one has its own window handle, and consequently can be given focus and all those other fun things you can do with window handles. To manipulate them, pass the handle to the scrollbar control to the appropriate scrollbar function (SetScrollInfo, fo...

Code
May 7, 2004
Post comments count0
Post likes count0

When should your destructor be virtual?

Raymond Chen
Raymond Chen

When should your C++ object's destructor be virtual? First of all, what does it mean to have a virtual destructor? Well, what does it mean to have a virtual method? If a method is virtual, then calling the method on an object always invokes the method as implemented by the most heavily derived class. If the method is not virtual, then the implem...

Code