Showing tag results for Code

Dec 9, 2013
Post comments count0
Post likes count0

Destroying all child processes (and grandchildren) when the parent exits

Raymond Chen
Raymond Chen

Today's Little Program launches a child process and then just hangs around. If you terminate the parent process, then all the children (and grandchildren and great-grandchildren, you get the idea) are also terminated. The tool for this is the Job Object. Specifically, we mark the job as "kill on job close" which causes all processes in the job ...

Code
Dec 6, 2013
Post comments count0
Post likes count0

Is it wrong to call SHFileOperation from a service?

Raymond Chen
Raymond Chen

A customer had a simple question: "Is it wrong to call from a service?" I don't know if I'd call it wrong, but I'd call it highly inadvisable. Update: See Is it wrong to call SHFileOperation from a service? Revised.

Code
Dec 4, 2013
Post comments count0
Post likes count0

What's the difference between the wParam of the WM_NOTIFY message and the idFrom in the NMHDR structure?

Raymond Chen
Raymond Chen

The message takes the following parameters: Notice that the identifier of the control sending the message appears in two places, once in the and again in the . What's the difference? There is no difference. It's just a convenience. The same value is passed in both places, and you can check whichever one is easier for you. You might use the ...

Code
Dec 2, 2013
Post comments count0
Post likes count0

Logging the foreground process as it changes

Raymond Chen
Raymond Chen

Today's Little Program simply logs all changes to the foreground window by recording the path to the application the user switched to. You might use this as part of a usability study to monitor what applications users spend most of their time in. Most of this code is just taking things we already know and snapping them together. Usin...

Code
Nov 29, 2013
Post comments count0
Post likes count0

Why can't I create my dialog with DialogBox, DialogBoxParam, CreateDialog, CreateDialogParam, or the indirect versions of same?

Raymond Chen
Raymond Chen

One of the purposes of my dialog manager series was to help people diagnose problems with their dialog boxes. But since I embedded the tips inside the series body, it's hard for people to find them, and I still end up answering the same questions over and over. So here it is in a separate article that hopefully people can find. Why your call ...

Code
Nov 28, 2013
Post comments count0
Post likes count0

If you try to declare a variadic function with an incompatible calling convention, the compiler secretly converts it to cdecl

Raymond Chen
Raymond Chen

Consider the following function on an x86 system: The function declares itself as , which is a callee-clean convention. But a variadic function cannot be callee-clean since the callee does not know how many parameters were passed, so it doesn't know how many it should clean. The Microsoft Visual Studio C/C++ compiler resolves this conflict by...

Code
Nov 27, 2013
Post comments count0
Post likes count0

The case of the DLL that refuses to load

Raymond Chen
Raymond Chen

A customer reported that they had a problem that occurred only on some machines but not others. Their application called and the call succeeded on some machines, but failed on others with error ("The specified module could not be found"). The path was a fully-qualified path to a file that was confirmed to exist and be readable. If the comm...

Code
Nov 25, 2013
Post comments count0
Post likes count0

Extracting GPS coordinates from a photo and plotting it on a map

Raymond Chen
Raymond Chen

Today's Little Program extracts GPS coordinates from a photo and plots it on a map. Remember, Little Programs do little to no error checking, because that's how they roll. We start with a simple function that takes a latitude and longitude and opens a Web page that highlights that coordinate. In a real program, you probably would do something m...

Code
Nov 22, 2013
Post comments count0
Post likes count0

How do I get the effect of CW_USEDEFAULT positioning on a window I've already created?

Raymond Chen
Raymond Chen

A customer wanted to know how to get the effect of positioning on a window that already exists. In particular, they wanted to be able to reposition a dialog box to get the cascade effect, but since you can't actually pass in a dialog template, the repositioning has to be done after the fact. (Presumably in the handler, which runs before the d...

Code