Showing tag results for Code

May 28, 2008
Post comments count0
Post likes count1

Reading a contract from the other side: SHSetInstanceExplorer and SHGetInstanceExplorer

Raymond Chen

Shell extensions that create worker threads need to call the function so that Explorer will not exit while the worker thread is still running. When your worker thread finishes, you release the that you obtained to tell the host program, "Okay, I'm done now, thanks for waiting." You can read this contract from the other side. Instead of thinkin...

Code
May 27, 2008
Post comments count0
Post likes count1

You can't give away something that isn't yours

Raymond Chen

This rule of real life applies to code as well. If something doesn't belong to you, then you can't give it away. For example, functions like and take ownership of the item that you pass it. In SetClipboardData's case, the memory block you pass as the parameter becomes the property of the clipboard. For it's the that becomes the property of ...

Code
May 23, 2008
Post comments count0
Post likes count1

What does TranslateAccelerator do?

Raymond Chen

For some reason, there appears to be some confusion over what does. It's very simple, and it's all spelled out in the documentation. You give it a message, and if the message is a keypress that matches an entry in the accelerator table, the corresponding or message is sent to the window you said you are translating messages for. One point of...

Code
May 12, 2008
Post comments count0
Post likes count1

How do I flash my window caption and taskbar button manually?

Raymond Chen

Commenter Jonathan Scheepers wonders about those programs that flash their taskbar button indefinitely, overriding the default flash count set by . The function and its simpler precursor let a program flash its window caption and taskbar button manually. The window manager flashes the caption automatically (and Explorer follows the caption by...

Code
May 8, 2008
Post comments count0
Post likes count1

Gentle reminder: On a dialog box, do not give OK and Cancel accelerators

Raymond Chen

I know most of you know this, but I'm going to say it for the record. When you have a dialog box with an OK and/or Cancel button, do not give the keys accelerators. In other words, simply write The dialog manager already has those buttons covered. The hotkey for the OK button is Enter (since it is the default pushbutton), and the hotkey for the...

Code
May 6, 2008
Post comments count0
Post likes count1

Psychic debugging: Why does ExitProcess(1) produce an exit code of zero?

Raymond Chen

Here's a question that came from a customer. By now, you should already have the necessary psychic powers to answer it. Our program calls to indicate that it exited unsuccessfully. The process that launched our program waits for the program to exit and then calls to retrieve the exit code. The function succeeds, but the exit code is zero! How c...

Code
May 5, 2008
Post comments count0
Post likes count1

If you pass invalid parameters, then all bets are off

Raymond Chen

Alun Williams pointed out that if you pass invalid parameters to , it does not destroy the . Well, yeah, because if you pass invalid parameters, then all bets are off. Different functions perform different degrees of parameter validation; the degree to which this is done is typically guided by security concerns. Information that crosses securi...

Code
May 1, 2008
Post comments count0
Post likes count1

Strange uses for window class atoms

Raymond Chen

When you register a window class (with the or function), you get an back. What use is this atom? Not much. You can use this atom in many places where a window class name can be used; just convert it to a string with the macro. Let's change our scratch program to illustrate: We save the atom returned by the function and use it (in the...

Code