The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Jan 30, 2013
Post comments count 0
Post likes count 1

Why doesn’t HeapValidate detect corruption in the managed heap?

Raymond Chen

A customer had a program that was corrupting the managed heap by p/invoking incorrectly. The problem didn't show up until the next garbage collection pass, at which point the CLR got all freaked-out-like. "According to Knowledge Base article 286470, the tool is supposed to catch heap corruption, but it doesn't catch squat." Depending on your point of view, this is either a case of the customer not understanding what things mean in context or of the KB article author looking at the world through kernel-colored glasses. The tool, pageheap, full pageheap, and the function all operate on heaps, but the sen...

Jan 29, 2013
Post comments count 0
Post likes count 1

Poisoning your own DNS for fun and profit

Raymond Chen

When you type a phrase into the Windows Vista Start menu's search box and click Search the Internet, then the Start menu hands the query off to your default Internet search provider. Or at least that's what the Illuminati would have you believe. A customer reported that when they typed a phrase into the Search box and clicked Search the Internet, they got a screenful of advertisements disguised to look like search results. What kind of evil Microsoft shenanigans is this? If you looked carefully at the URL for the bogus search "results", the results were not coming from Windows Live Search. They were c...

Jan 28, 2013
Post comments count 0
Post likes count 1

Please hold your head perfectly still while you write up that memo

Raymond Chen

I dreamed that the original Volkswagen Beetle factory was so cramped that the office workers had to move their desks to the factory floor, with heavy equipment swinging around just inches from their faces. To prevent serious injuries, a template passed through every so often to make sure nothing was out of place.

Jan 28, 2013
Post comments count 0
Post likes count 1

Finding a printer, and then creating a shortcut to that printer

Raymond Chen

Today's "Little Program" does two things: It looks for a printer in the Printers folder, and then once it finds it, it creates a shortcut to that printer. As is common with "Little Programs", I don't bother with error checking. I'll leave you to do that. Second part first, since it is handy on its own: Creating a shortcut to an arbitrary item in the shell namespace, provided either in the form of an ID list or a shell item. (The ID list is the thing that identifies an item in the shell namespace.) void CreateShortcutToIDList(PCWSTR pszName, PCUIDLIST_ABSOLUTE pidl) { CComPtr<IShellLink> spsl; spsl....

Jan 25, 2013
Post comments count 0
Post likes count 1

When you have a SAFEARRAY, you need to know what it is a SAFEARRAY *of*

Raymond Chen

A customer had a problem with SAFEARRAY, or more specifically, with CComSafeArray. CComSafeArray<VARIANT> sa; GetAwesomeArray(&sa); LONG lb = sa.GetLowerBound(); LONG ub = sa.GetUpperBound(); for (LONG i = lb; i <= ub; i++) { CComVariant item = sa.GetAt(i); ... use the item ... } The GetAt method returns a VARIANT&, and when it is copy-constructed into item, the DISP_E_BAD­VAR­TYPE exception is raised. On the other hand, if the offending line is changed to CComQIPtr<IAwesome> pAwesome = sa.GetAt(i).punkVal; then the problem goes away. Your initial reaction to this c...

Jan 24, 2013
Post comments count 0
Post likes count 1

STRICT_TYPED_ITEMIDS is the shell namespace version of the STRICT macro used by USER and GDI

Raymond Chen

Starting with the Windows Vista PlatformSDK, defining the symbol before including shell header files changes declarations that previously had simply used now use one of various types which are more clear about what type of ID list is being used. Think of it as the macro for the shell. The more precise names emphasize the form of the ID list: These new types were introduced to help catch common programming errors when using the shell namespace. For example, if you try to pass an array of absolute pidls to , you will get a type mismatch compiler error because that method takes an , and the thing you ...

Jan 23, 2013
Post comments count 0
Post likes count 0

Eliot Chang’s list of things Asians hate

Raymond Chen

Where are you really from?

Jan 23, 2013
Post comments count 0
Post likes count 1

Why was WHEEL_DELTA chosen to be 120 instead of a much more convenient value like 100 or even 10?

Raymond Chen

We saw some time ago that the nominal mouse wheel amount for one click (known as a "detent") is specified by the constant , which has the value 120. Why 120? Why not a much more convenient number like 100, or even 10? Because the value 120 made it easier to create higher-resolution mouse wheels. As noted in the documentation: The delta was set to 120 to allow Microsoft or other vendors to build finer-resolution wheels (a freely-rotating wheel with no notches) to send more messages per rotation, but with a smaller value in each message. Suppose the original wheel mouse had nine clicks around its ci...

Jan 22, 2013
Post comments count 0
Post likes count 1

Heads-up: Phone scammers pretending to be JPMorgan Chase MasterCard security

Raymond Chen

Recently, a round of phone scammers have been dialing through our area with a caller-ID of (000) 000-0000, which should already raise suspicions. When you answer, a synthesized voice says that they are calling from JPMorgan Chase MasterCard security. They claim that your credit card has been disabled due to suspicious activity, and in order to reactivate it, you need to enter your 16-digit credit card number. I decided to see how far I could take the robot voice for a ride, so I entered 16 random digits. No luck, the robot voice knew about the checksum and asked me to enter it again. I did a quick search for...