Showing tag results for Code

May 21, 2004
Post comments count0
Post likes count1

Do you know when your destructors run? Part 2.

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 count1

Do you know when your destructors run? Part 1.

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 count1

String sorting is not done by ASCII code any more.

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

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 count1

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

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

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 count1

When should your destructor be virtual?

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
May 3, 2004
Post comments count0
Post likes count0

Why does my hard drive light flash every few second?

Raymond Chen

Back in Windows 95, people would notice that their hard drive light would blink every few seconds. What's that all about? Actually, it wasn't the hard drive light after all. Windows 95 was polling your CD-ROM drive to see whether you had inserted a new CD. Some computers wired up the "hard drive light" not to the hard drive but r...

Code
Apr 28, 2004
Post comments count0
Post likes count1

What is __purecall?

Raymond Chen

Both C++ and C# have the concept of virtual functions. These are functions which always invoke the most heavily derived implementation, even if called from a pointer to the base class. However, the two languages differ on the semantics of virtual functions during object construction and destruction. C# objects exist as their final type before co...

Code
Apr 23, 2004
Post comments count0
Post likes count0

How to retrieve text under the cursor (mouse pointer)

Raymond Chen

Microsoft Active Accessibilty is the technology that exposes information about objects on the screen to accessibility aids such as screen readers. But that doesn't mean that only screen readers can use it. Here's a program that illustrates the use of Active Accessibility at the most rudimentary level: Reading text. There's much more to Active ...

Code