There's the interface contract, and there are the implementations of the interface contract

Raymond Chen

Ivo wants to know whether it is legal to use NULL as the icon parameters to IExtractIcon::Extract. The documentation says that the parameters are optional, but some shell folder implementations treat them as mandatory. Yes, the parameters are technically optional, but it’s also the case that many people mess up their implementation of the interface and treat them as mandatory, either by crashing on a null pointer or by returning E_INVALIDARG. Since IExtractIcon is an extension interface, you are pretty much at the mercy of all the implementations of that extension. Welcome to the land of application compatibility, where you have to incorporate workarounds for other people’s bugs. In this case, it means always passing non-null pointers for the output icons if you want to get anything meaningful back, even if that means asking for more than you really need and then throwing part of it away. Ivo’s second question was whether there is a performance benefit of asking just for the icon you want, or whether it’s almost as fast to get both. If you ask for just one of the icons, then the icon extractor doesn’t need to go extract it, which saves you a small amount of disk access (or a large amount if you’re asking for the monster 256×256 icon). But given that compatibility forces you to ask for both anyway, the answer doesn’t help you any. Given that there are drivers who run red lights, you could say that, in theory, “It is more efficient to cross the street as soon as the light turns green,” but in practice, you’d be better served to look for traffic before stepping out into the roadway.

You’d be right, but you’d be dead right.

0 comments

Discussion is closed.

Feedback usabilla icon