The Old New Thing

Why does OpenProcess succeed even when I add three to the process ID?

A customer noticed that if you add three to a process ID and pass it to the function, it still succeeds. Why is that? Well, first of all, I need to say up front that the behavior you're seeing is an artifact of the implementation and is not part of the contract. You're passing intentionally invalid parameters, what did you expect? The ...

Why are accelerators for hidden controls still active?

In the suggestion box, Serge Wautier asked why accelerators for hidden controls remain active. He's apparently rather insistent because he asked the question again a few months later. Asking the same question multiple times reduces the likelihood that I'll answer it. Consider yourself lucky that I wrote this answer before I noticed the ...

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

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

What does TranslateAccelerator do?

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

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

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

Data breakpoints are based on the linear address, not the physical address

When you ask the debugger to set a read or write breakpoint, the breakpoint fires only if the address is read from or written to by the address you specify. If the memory is mapped to another address and modified at that other address, then your breakpoint won't see it. For example, if you have multiple views on the same data, then ...

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

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

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

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