The Old New Thing

Adventures in undefined behavior: The premature downcast

A customer encountered the following problem: The Buy­Paint function converts the cookie back to a Shape object, and then checks if the object is a Shape2D object by calling Is­2D. If so, then it does some more stuff to figure out what type of paint to buy. (Note to nitpickers: The actual scenario was not like this, but I ...
Comments are closed.0 0
Code

I'm not calling a virtual function from my constructor or destructor, but I'm still getting a __purecall error

Some time ago, I described what __purecall is for: It's to detect the cases where you call a virtual method with no implementation (a so-called pure virtual method). This can happen during object constructor or destruction, since those are times when you can validly have a partially-implemented object. Well, there's another case this can ...
Comments are closed.0 0
Code

Psychic debugging: Why Chinese characters don't work

Here's a walkthrough of an actual case of psychic debugging. I'm using the internal XYZ table-generating tool, but it appears to be useless in my case. Does this tool work? Right now, I'm just resorting to the manual method of generating my data table (Chinese and English). Hooray for vague questions! "It appears to be useless." But there ...

Command line tool to manage Windows 7 Libraries, with source code

A customer asked if there was a command-line tool for managing Windows 7 Libraries so that they could create and deploy libraries across their organization. Not only is there such a tool, it even comes with source code. The Shell Library Command Line Sample shows how to manage Windows 7 libraries programmatically via the IShell...

Well at least nobody's parking there any more

There is a field next to the Microsoft building I used to work in, and for a time, people parked their cars out on the field, presumably because finding a proper parking space in the garage became difficult due to overcrowding. To prevent people from parking in the field, Security placed a large log across the access to the field. The ...

How does the taskbar decide whether to show Recent or Frequent documents on the jump list?

Some jump lists show Recent documents, and others show Frequent documents. (Images stolen from Sasha Goldshtein.) Our friend xpclient wanted to know how the taskbar decides which one to use, because it seemed random. (Ironically, xpclient is asking a question about the Window 7 client.) The default is to show Recent documents. But an...

Dumping a hash table with external chaining from the debugger

I was doing some crash dump debugging, as I am often called upon to do, and one of the data structure I had to grovel through was something that operated basically like an atom table, so that's what I'll call it. Like an atom table, it manages a collection of strings. You can add a string to the table (getting a unique value back, which we ...

Wait, you never said that I had to initialize the object before I used it!

A customer reported that they were having trouble creating slim reader/writer locks at runtime. They simplified the issue to a short program: "What is the correct way of creating an SRWLOCK via the new operator?" It wasn't long before somebody noted that nowhere in the code is the function Initialize­SRW­Lock called. "Oh, yeah...
Comments are closed.0 0
Code

The shifting sands of "Run as different user"

A customer liaison asked the following question on behalf of his customer. When I do a shift-right-click on a shortcut to a program, I see the following: The option to run a program as another user (other than Administrator) was present in Windows XP, but it was lost in Windows Vista. It appears that we responded to those ...

Sorry we got cut off, my phone just auto-rebooted

Some time ago, I was on the phone when the connection suddenly cut out. I looked at the my phone display and it said, Auto-restart in 7 seconds. The seconds counted down, and then the phone rebooted, and after about ten more seconds, it was back in business, acting like nothing was wrong. (Except that it just terminated a phone call without ...

Feedback usabilla icon