The Old New Thing

Invalidating the null window redux

The people who work on the next generation of the window manager, known as the Desktop Window Manager (DWM), told me that their original plan was to get rid of the compatibility hack that says that invalidating the null window invalidates the entire desktop, but by an amazing coincidence, two days after I posted that article, they received a...

Why does SetWindowsHookEx take an HINSTANCE parameter?

An anonymous commenter asked why the function takes an parameter if the first thing it's going to do is convert the instance handle into a file name. Because that's not how it worked in 16-bit Windows. In 16-bit Windows there was no such thing as hook injection. All 16-bit Windows applications ran in the same address space, so there was ...

One way people abused hooks in 16-bit Windows

We saw last time how windows hooks were implemented in 16-bit Windows. Even though the was an opaque data type that should have been treated like a handle, many programs "knew enough to be dangerous" and took advantage of the fact that the was just a pointer to the previous hook procedure. The most common way of abusing this knowledge ...

How were window hooks implemented in 16-bit Windows?

The mechanism for keeping track of window hooks was very different in 16-bit Windows. The functions involved were , and . The first two functions still exist today, but the third one has been replaced with a macro: Disclaimer: All code below is "reconstructed from memory". The spirit of the code is intact, but the precise details may be ...

How were DLL functions exported in 16-bit Windows?

The whole point of dynamic link libraries (DLLs) is that the linkage is dynamic. Whereas statically-linked libraries are built into the final product, a module that uses a dynamically-linked library merely says, "I would like function X from Y.DLL, please." This technique has advantages and disadvantages. One advantage is more efficient use of...