The Old New Thing

If you have full trust, then you can do anything, so don’t be surprised that you can do bad things, too

This is another example of the dubious security vulnerability known as wrapping a simple idea inside layers of obfuscation and then thinking that somehow the obfuscation is the source of the problem. First of all, consider this: Suppose a program calls one of its own functions but gets the calling convention wrong and ends up corrupting ...

How does PostQuitMessage know which thread to post the quit message to?

Commenter bav016 asks how functions like and know which thread the messages should go to. Unlike some functions such as which have a window handle parameter that lets you say which window you want to operate on, and don't say which thread the or message should go to. How do they decide? The messages go to the current thread; that is...

Even if you have code to handle a message, you’re allowed to call DefWindowProc, because you were doing that anyway after all

Just because you write case WM_SOMETHING: doesn't mean that you have to handle all possible parameters for the WM_SOMETHING message. You're still allowed to call the DefWindowProc function. After all, that's what you did when you didn't have a case WM_SOMETHING: statement in the first place. switch (uMsg) { case WM_CHAR: OnChar...

Undecorating names to see why a function can’t be found

Here's a problem inspired by actual events. When I build my project, it compiles fine, but it fails during the link step with an unresolved external: program.obj : error LNK2001: unresolved external symbol "public: virtual wchar_t const * __thiscall UILibrary::PushButton::GetName(class UILibrary::StringHolder * *)" (?GetName@PushButton@...

What is the mysterious fourth message box button?

When you call the MessageBox function, you pass flags specifying which of a fixed set of button patterns you want (for example, Yes/No and OK/Cancel) and which button you want to be the default (MB_DEFBUTTON1 through MB_DEFBUTTON4.) Wait a second. What's with this MB_DEFBUTTON4? None of the button patterns are four-button patterns. The ...

How do I obtain the computer manufacturer’s name?

One customer wanted a way to determine the name of the computer manufacturer. For example, they wanted to make some function call and get back "IBM" or "Compaq" or "Dell". I don't know why they wanted this information, and for the moment, I don't care. And of course, when you're looking for information, you don't search MSDN; that's for ...