Showing tag results for Code

Jun 6, 2008
Post comments count0
Post likes count1

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

Raymond Chen
Raymond Chen

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

Code
Jun 2, 2008
Post comments count0
Post likes count1

Why are accelerators for hidden controls still active?

Raymond Chen
Raymond Chen

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

Code
May 28, 2008
Post comments count0
Post likes count1

Reading a contract from the other side: SHSetInstanceExplorer and SHGetInstanceExplorer

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