Showing tag results for Code

Jan 7, 2009
Post comments count0
Post likes count1

When debugging a stack overflow, you want to focus on the repeating recursive part

Raymond Chen

When your program breaks into the debugger with a stack overflow, you will get a ridiculously huge stack trace because your program has gone into some sort of recursive death. (This is not a statement of metaphysical certitude, but it is true with very high probability.) But the place where the program crashed is usually not interesting at all. He...

Code
Jan 5, 2009
Post comments count0
Post likes count1

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

Raymond Chen

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(...); ret...

Code
Jan 1, 2009
Post comments count0
Post likes count1

How do I write a program that can be run either as a console or a GUI application?

Raymond Chen

You can't, but you can try to fake it. Each PE application contains a field in its header that specifies which subsystem it was designed to run under. You can say to mark yourself as a Windows GUI application, or you can say to say that you are a console application. If you are GUI application, then the program will run without a console. The s...

Code
Dec 29, 2008
Post comments count0
Post likes count1

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

Raymond Chen

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@UILibr...

Code
Dec 19, 2008
Post comments count0
Post likes count1

What is the mysterious fourth message box button?

Raymond Chen

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 highest n...

Code
Dec 18, 2008
Post comments count0
Post likes count1

How do I obtain the computer manufacturer’s name?

Raymond Chen

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 crazy pe...

Code
Dec 11, 2008
Post comments count0
Post likes count1

Don’t use global state to manage a local problem

Raymond Chen

We've seen a few instances where people have used a global setting to solve a local problem. For example, people who use the function to prevent a window from redrawing, toggle a global setting to see what its value is, or who change the system time zone as part of an internal calculation. To this, I'll add as an example a program which figures...

Code
Nov 28, 2008
Post comments count0
Post likes count1

Just because a method is called Refresh doesn’t mean that it refreshes what you want

Raymond Chen

Here's a question from a customer: I made some changes related to my shell extension [details omitted], but the changes don't show up in the Explorer window when I refresh it. Any suggestions on how to solve this problem? When we asked how they were refreshing the Explorer window, we were expecting something like pressing F5 or calling with ,...

Code
Nov 24, 2008
Post comments count0
Post likes count1

Consequences of the Explorer view model: If you create a view, then you succeeded, even if you’d rather fail

Raymond Chen

Commenter Anonymous asked why navigating to a drive with no media displays a dialog instead of showing the error message in the view. This is an unfortunate consequence of Explorer's browser/view model. The shell browser binds to the and asks for the view by calling . The view window calls to figure out what to show in the view—and here ...

Code