Showing results for Code - The Old New Thing

Jan 27, 2014
Post comments count0
Post likes count0

How can I make a callback function a member of my C++ class?

Raymond Chen
Raymond Chen

Instead of a Little Program today, I'm going to answer a Little Question. This is a common beginner question, but I figure I'll just spell it out right here for posterity. First of all, you probably noticed that you can't do this: That's because the is declared as a so-called free function, but member functions are not free. Neither are func...

Code
Jan 24, 2014
Post comments count0
Post likes count0

Non-psychic debugging: Looking for leaked objects by their vtable

Raymond Chen
Raymond Chen

A programmer on the GHI team reported that they were hitting an assertion failure using an internal library and asked for help debugging it. I didn't work on this internal library, but on the other hand I'm also not afraid to look inside and around. The assertion failure said, "Assertion failed: All widgets from a factory must be destroyed be...

Code
Jan 22, 2014
Post comments count0
Post likes count0

What clock do MSG.time and GetMessageTime use?

Raymond Chen
Raymond Chen

The structure has a field called which is a . There is also a function which returns a . Both are documented as returning the time the message was generated, but the types are different. Are these time units comparable? Yes, they are the same thing. They all use the 32-bit timer provided by the function. Sorry about the inconsistency in sign...

Code
Jan 17, 2014
Post comments count0
Post likes count0

Psychic debugging: Why messages aren't getting processed by your message pump

Raymond Chen
Raymond Chen

The second parameter to the is an optional window handle that is used to tell the function to retrieve only messages that belong to the specified window. A filtered is nearly always a bad idea, because your program will not respond to messages that don't meet the filter. Unlike a filtered (which simply returns "no messages satisfy the filter...

Code
Jan 13, 2014
Post comments count0
Post likes count0

Creating a listview with checkboxes on some items but not others

Raymond Chen
Raymond Chen

Today's Little Program creates a listview with checkboxes on some items but not other. The extended style is really just a convenience style. Everything it does you could have done yourself, with a bit more typing. It creates a state image list consisting of an unchecked box (state 1) and a checked box (state 2). You could have done t...

Code
Jan 10, 2014
Post comments count0
Post likes count0

How do I manually recalculate ACLs on a file based on the containing directory?

Raymond Chen
Raymond Chen

A customer wanted to move a file and have it forget all its old ACLs and instead inherit its ACLs from its new location. They found an old article of mine that said If you use to move a file and pass the flag, then it will not preserve the original ACLs on the moved files but will rather recalculate them from the destination's inheritable prop...

Code
Jan 8, 2014
Post comments count0
Post likes count0

The case of the missing context menu verbs

Raymond Chen
Raymond Chen

A customer reported that when they right-clicked a batch file, a bunch of commands were missing. For example, Open was gone! Okay, there really isn't much of a story here, because some direct debugging quickly identified the culprit. The customer had installed a third party shell extension which returned a huge value from its method. Explorer t...

Code