Showing tag results for Code

Feb 6, 2009
Post comments count0
Post likes count1

A process shutdown puzzle: Answers

Raymond Chen
Raymond Chen

Last week, I posed a process shutdown puzzle in honor of National Puzzle Day. Let's see how we did. Part One asked us to explain why the thread no longer exists. That's easy. One of the things that happen inside is that all threads (other than the one calling ) are forcibly terminated in the nastiest way possible. This happens before the noti...

Code
Feb 2, 2009
Post comments count0
Post likes count1

How do I programmatically show and hide the Quick Launch bar?

Raymond Chen
Raymond Chen

Commenter Mihai wants to know how to show or hide the Quick Launch bar programmatically. That's not something a program should be doing. Whether the Quick Launch bar is shown or hidden is an end user setting, and programs should not be overriding the user's preferences. Explorer consciously does not expose an interface for showing and hiding tas...

Code
Jan 29, 2009
Post comments count0
Post likes count1

A process shutdown puzzle

Raymond Chen
Raymond Chen

In honor of National Puzzle Day, I leave you today with a puzzle based on an actual customer problem. Part One: The customer explains the problem. We have this DLL, and during its startup, it creates a thread with the following thread procedure: DWORD CALLBACK ThreadFunction(void *) { HANDLE HandleArray[2]; HandleArray[0] = SetUpStuff()...

Code
Jan 26, 2009
Post comments count0
Post likes count1

But then we ran into problems when we started posting 10,000 messages per second

Raymond Chen
Raymond Chen

Once upon a time, a long, long time ago, there was a research team inside Microsoft who was working on alternate models for handling input. I don't know what eventually came of that project, and I don't even remember the details of the meeting, but I do remember the punch line, so I'm just going to make up the rest. The research project broke up ...

Code
Jan 22, 2009
Post comments count0
Post likes count1

Why do I get the error REGDB_E_IIDNOTREG when I call a method that returns an interface?

Raymond Chen
Raymond Chen

This is another manifestation of the missing marshaller problem. IContextMenu *pcm; HRESULT hr = psf->GetUIObjectOf(hwnd, 1, &pidl, IID_IContextMenu, NULL, &pcm); // fails with REGDB_E_IIDNOTREG The IContextMenu interface does not have a proxy/stub factory (as of this writing). Recall that shell objects, as a rule, a...

Code
Jan 21, 2009
Post comments count0
Post likes count1

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

Raymond Chen
Raymond Chen

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 its sta...

Code
Jan 12, 2009
Post comments count0
Post likes count1

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

Raymond Chen
Raymond Chen

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, they...

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
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
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
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